community.general
community.general copied to clipboard
parted does not respect "number" when creating partition
Summary
I try to create a partition with a custom number and it does not assign it, but also shows no errors.
Issue Type
Bug Report
Component Name
parted module
Ansible Version
$ ansible --version
ansible [core 2.12.7]
Community.general Version
$ ansible-galaxy collection list community.general
community.general 5.4.0
Configuration
$ ansible-config dump --only-changed
nothing
OS / Environment
Running on Fedora 34, target OS Ubuntu 20.04 on KVM.
Steps to Reproduce
- name: create new part
parted:
device: "/dev/vda"
label: gpt
fs_type: ext4
number: 6
state: present
part_start: '{{ (root_part_devinfo["start"] | int) + (root_part_devinfo["sectors"] | int) + 2 }}s' # that's just copied from my code. should be probably reproducable with other hardcoded values, too.
part_end: '60%'
Expected Results
I expected the new partition to have the number 6.
Actual Results
The new partition had the number 3.
Number Start End Size File system Name Flags
14 1049kB 5243kB 4194kB bios_grub
15 5243kB 116MB 111MB fat32 boot, esp
1 116MB 2361MB 2245MB ext4
3 2361MB 6442MB 4081MB primary <--- THIS ONE WAS CREATED
2 9664MB 10.7GB 1073MB primary
I tested many times and I don't get the module to set the number I specified. It just seems to always choose the next one available (e.g., 1, 2 already taken, it picks 3).
Code of Conduct
- [X] I agree to follow the Ansible Code of Conduct
Files identified in the description:
If these files are incorrect, please update the component name
section of the description or use the !component
bot command.
cc @ColOfAbRiX @jake2184 @rosowiecki click here for bot help
I dont think manual numbering of the partition is supported - this module simply wraps around the parted binary, and the parted mkpart
command doesn't take a numeric identifier as an argument.
number
is a mandatory argument so the module/parted can identify which partition you're referring to to ensure idempotency.
The documentation does claim otherwise, though. For number
, it says The number of the partition to work with or the number of the partition that will be created.
. The option has been there since the beginning (https://github.com/ansible/ansible/pull/20399), and it didn't do what promised already back then: https://github.com/ansible/ansible/pull/20399/files#diff-6d376841d12b8d77d4917a4a1b7b762569c740ad95b452973d3c1c53014306fdR631-R637
@jake2184 @felixfontein Thanks for the quick responses! I actually didn't know parted was not able to set a custom number since it's possible to do that with fdisk, but now looking at it it seems like there is indeed no easy way with parted. I guess this issue is then about clarifying the documentation. As long as the partition numbers are predictable (like always the next free number starting at 1) that's fine for my use case.
number is a mandatory argument so the module/parted can identify which partition you're referring to to ensure idempotency.
How it works now, it could be a bit confusing in some cases, though. Let's say you want to you have a partition 1 and want to create two more, but you have the definition for partition 3 before 2 in your playbook. It'll first create a partition 2 (but was defined as 3) and probably make some resizing or fail for the second one, because partition 2 does already exist...
Files identified in the description:
If these files are incorrect, please update the component name
section of the description or use the !component
bot command.