community.general
community.general copied to clipboard
returned unit from parted is not compatble with the expected unit from parted
SUMMARY
The unit returned by the parted module is not compatible with the unit expected from the parted module. The unit returned from the module is in all lowercase (e.g. 'kib', 'kb') whereas the unit expected from the module must be in mixed case (e.g. 'KiB', 'KB')
ISSUE TYPE
- Bug Report
COMPONENT NAME
parted
ANSIBLE VERSION
ansible 2.10.4
config file = /home/hashlog/git/ansible-play-piriodic/ansible.cfg
configured module search path = ['/home/hashlog/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/hashlog/.local/lib/python3.9/site-packages/ansible
executable location = /home/hashlog/.local/bin/ansible
python version = 3.9.1 (default, Jan 20 2021, 00:00:00) [GCC 10.2.1 20201125 (Red Hat 10.2.1-9)]
CONFIGURATION
no output
OS / ENVIRONMENT
Host OS:
- Fedora 33
- Linux Kernel 5.10.15-200.fc33.x86_64
- Architecture amd64
STEPS TO REPRODUCE
# playbook.yml
- hosts: all
gather_facts: no
tasks:
- name: get partition information
community.general.parted:
device: /dev/mmcblk0
number: 3
state: info
unit: "KiB"
register: _mmcblk0
- name: resize partition
community.general.parted:
device: /dev/mmcblk0
number: 3
state: present
unit: "{{ _mmcblk0.disk.unit }}"
part_start: "{{ _mmcblk0.partitions[2].begin }}"
part_end: "100%"
$ ansible -i localhost, -c local -C ./playbook.yml
TASK [get partition information] *************************************************
ok: [localhost]
TASK [resize partition] *************************************************
fatal: [localhost]: FAILED! => {"changed": false, "msg": "value of unit must be one of: B, KB, MB, GB, TB, KiB, MiB, GiB, TiB, s, %, cyl, chs, compact, got: kib"}
EXPECTED RESULTS
The unit returned by the parted module should be able to be used as value for the parameters unit
, part_start
or part_end
.
ACTUAL RESULTS
The value returned by the parted module is in all lowercase, whereas the unit specified in the unit
, part_start
and part_end
parameter must be one of B, KB, MB, GB, TB, KiB, MiB, GiB or TiB (case sensitive).
ansible-playbook -i localhost, -c local -C -vvvv ./parted.yml
ansible-playbook 2.10.4
config file = /home/fgierlinger/git/ansible-play-piriodic/ansible.cfg
configured module search path = ['/home/fgierlinger/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/fgierlinger/.local/lib/python3.9/site-packages/ansible
executable location = /home/fgierlinger/.local/bin/ansible-playbook
python version = 3.9.1 (default, Jan 20 2021, 00:00:00) [GCC 10.2.1 20201125 (Red Hat 10.2.1-9)]
Using /home/fgierlinger/git/ansible-play-piriodic/ansible.cfg as config file
setting up inventory plugins
Set default localhost to localhost
Parsed localhost, inventory source with host_list plugin
Loading collection community.general from /home/fgierlinger/.ansible/collections/ansible_collections/community/general
Loading callback plugin default of type stdout, v2.0 from /home/fgierlinger/.local/lib/python3.9/site-packages/ansible/plugins/callback/default.py
Skipping callback 'default', as we already have a stdout callback.
Skipping callback 'minimal', as we already have a stdout callback.
Skipping callback 'oneline', as we already have a stdout callback.
PLAYBOOK: parted.yml ***********************************************************
Positional arguments: ./parted.yml
verbosity: 4
connection: local
timeout: 10
become_method: sudo
tags: ('all',)
check: True
inventory: ('localhost,',)
forks: 5
1 plays in ./parted.yml
PLAY [all] *********************************************************************
META: ran handlers
TASK [get partition information] ***********************************************
task path: /home/fgierlinger/git/ansible-play-piriodic/parted.yml:4
<localhost> ESTABLISH LOCAL CONNECTION FOR USER: fgierlinger
<localhost> EXEC /bin/sh -c 'echo ~fgierlinger && sleep 0'
<localhost> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /home/fgierlinger/.ansible/tmp `"&& mkdir "` echo /home/hashlog/.ansible/tmp/ansible-tmp-1613770178.5947487-49213-128725810757893 `" && echo ansible-tmp-1613770178.5947487-49213-128725810757893="` echo /home/hashlog/.ansible/tmp/ansible-tmp-1613770178.5947487-49213-128725810757893 `" ) && sleep 0'
<localhost> Attempting python interpreter discovery
<localhost> EXEC /bin/sh -c 'echo PLATFORM; uname; echo FOUND; command -v '"'"'/usr/bin/python'"'"'; command -v '"'"'python3.7'"'"'; command -v '"'"'python3.6'"'"'; command -v '"'"'python3.5'"'"'; command -v '"'"'python2.7'"'"'; command -v '"'"'python2.6'"'"'; command -v '"'"'/usr/libexec/platform-python'"'"'; command -v '"'"'/usr/bin/python3'"'"'; command -v '"'"'python'"'"'; echo ENDFOUND && sleep 0'
<localhost> EXEC /bin/sh -c '/usr/bin/python && sleep 0'
Using module file /home/fgierlinger/.ansible/collections/ansible_collections/community/general/plugins/modules/parted.py
<localhost> PUT /home/fgierlinger/.ansible/tmp/ansible-local-49203rka5mps0/tmpu8qga4la TO /home/hashlog/.ansible/tmp/ansible-tmp-1613770178.5947487-49213-128725810757893/AnsiballZ_parted.py
<localhost> EXEC /bin/sh -c 'chmod u+x /home/fgierlinger/.ansible/tmp/ansible-tmp-1613770178.5947487-49213-128725810757893/ /home/hashlog/.ansible/tmp/ansible-tmp-1613770178.5947487-49213-128725810757893/AnsiballZ_parted.py && sleep 0'
<localhost> EXEC /bin/sh -c '/usr/bin/python /home/fgierlinger/.ansible/tmp/ansible-tmp-1613770178.5947487-49213-128725810757893/AnsiballZ_parted.py && sleep 0'
<localhost> EXEC /bin/sh -c 'rm -f -r /home/fgierlinger/.ansible/tmp/ansible-tmp-1613770178.5947487-49213-128725810757893/ > /dev/null 2>&1 && sleep 0'
[DEPRECATION WARNING]: Distribution fedora 33 on host localhost should use
/usr/bin/python3, but is using /usr/bin/python for backward compatibility with
prior Ansible releases. A future Ansible release will default to using the
discovered platform python for this host. See https://docs.ansible.com/ansible/
2.10/reference_appendices/interpreter_discovery.html for more information. This
feature will be removed in version 2.12. Deprecation warnings can be disabled
by setting deprecation_warnings=False in ansible.cfg.
ok: [localhost] => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
},
"changed": false,
"disk": {
"dev": "/dev/sda",
"logical_block": 512,
"model": "ATA Samsung SSD 850",
"physical_block": 512,
"size": 244198584.0,
"table": "gpt",
"unit": "kib"
},
"invocation": {
"module_args": {
"align": "optimal",
"device": "/dev/sda",
"flags": null,
"fs_type": null,
"label": "msdos",
"name": null,
"number": 3,
"part_end": "100%",
"part_start": "0%",
"part_type": "primary",
"resize": false,
"state": "info",
"unit": "KiB"
}
},
"partitions": [
{
"begin": 1024.0,
"end": 615424.0,
"flags": [
"boot",
"esp"
],
"fstype": "fat32",
"name": "",
"num": 1,
"size": 614400.0,
"unit": "kib"
},
{
"begin": 615424.0,
"end": 1229824.0,
"flags": [],
"fstype": "hfs+",
"name": "Linux HFS+ ESP",
"num": 2,
"size": 614400.0,
"unit": "kib"
},
{
"begin": 1229824.0,
"end": 2278400.0,
"flags": [],
"fstype": "ext4",
"name": "",
"num": 3,
"size": 1048576.0,
"unit": "kib"
},
{
"begin": 2278400.0,
"end": 244198400.0,
"flags": [
"lvm"
],
"fstype": "",
"name": "",
"num": 4,
"size": 241920000.0,
"unit": "kib"
}
],
"script": "unit 'KiB' print"
}
TASK [resize partition] ********************************************************
task path: /home/fgierlinger/git/ansible-play-piriodic/parted.yml:12
<localhost> ESTABLISH LOCAL CONNECTION FOR USER: fgierlinger
<localhost> EXEC /bin/sh -c 'echo ~fgierlinger && sleep 0'
<localhost> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /home/fgierlinger/.ansible/tmp `"&& mkdir "` echo /home/hashlog/.ansible/tmp/ansible-tmp-1613770179.450308-49244-54515161842921 `" && echo ansible-tmp-1613770179.450308-49244-54515161842921="` echo /home/hashlog/.ansible/tmp/ansible-tmp-1613770179.450308-49244-54515161842921 `" ) && sleep 0'
Using module file /home/fgierlinger/.ansible/collections/ansible_collections/community/general/plugins/modules/parted.py
<localhost> PUT /home/fgierlinger/.ansible/tmp/ansible-local-49203rka5mps0/tmpd6klgtma TO /home/hashlog/.ansible/tmp/ansible-tmp-1613770179.450308-49244-54515161842921/AnsiballZ_parted.py
<localhost> EXEC /bin/sh -c 'chmod u+x /home/fgierlinger/.ansible/tmp/ansible-tmp-1613770179.450308-49244-54515161842921/ /home/hashlog/.ansible/tmp/ansible-tmp-1613770179.450308-49244-54515161842921/AnsiballZ_parted.py && sleep 0'
<localhost> EXEC /bin/sh -c '/usr/bin/python /home/fgierlinger/.ansible/tmp/ansible-tmp-1613770179.450308-49244-54515161842921/AnsiballZ_parted.py && sleep 0'
<localhost> EXEC /bin/sh -c 'rm -f -r /home/fgierlinger/.ansible/tmp/ansible-tmp-1613770179.450308-49244-54515161842921/ > /dev/null 2>&1 && sleep 0'
fatal: [localhost]: FAILED! => {
"changed": false,
"invocation": {
"module_args": {
"align": "optimal",
"device": "/dev/sda",
"label": "msdos",
"number": 3,
"part_end": "100%",
"part_start": "1229824.0",
"part_type": "primary",
"resize": false,
"state": "present",
"unit": "kib"
}
},
"msg": "value of unit must be one of: B, KB, MB, GB, TB, KiB, MiB, GiB, TiB, s, %, cyl, chs, compact, got: kib"
}
PLAY RECAP *********************************************************************
localhost : ok=1 changed=0 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0
Files identified in the description:
If these files are inaccurate, please update the component name
section of the description or use the !component
bot command.
cc @ColOfAbRiX @jake2184 @rosowiecki click here for bot help
The parted
command line program actually does not care in which case (lower, upper, mixed) the unit is passed
$ parted -s -m /dev/sda -- unit KIB print
BYT;
/dev/sda:244198584kiB:scsi:512:512:gpt:ATA Samsung SSD 850:;
$ parted -s -m /dev/sda -- unit kib print
BYT;
/dev/sda:244198584kiB:scsi:512:512:gpt:ATA Samsung SSD 850:;
$ parted -s -m /dev/sda -- unit KiB print
BYT;
/dev/sda:244198584kiB:scsi:512:512:gpt:ATA Samsung SSD 850:;
@fgierlinger in that case, shouldn't we make the module also case-insensitive?
I‘m not sure which is the proper way of solving this. IMO there are two ways to solve this problem. Either transforming the output received from parted
to match the input.
https://github.com/ansible-collections/community.general/blob/305748b3331c099981396460e90cff7ada3e45b3/plugins/modules/system/parted.py#L262-L263
Or changing the accepted values, to also allow the all-lowercase value. Probably this is the easiest accomplished by converting the input parameter to all lowercase.
https://github.com/ansible-collections/community.general/blob/305748b3331c099981396460e90cff7ada3e45b3/plugins/modules/system/parted.py#L235-L236
https://github.com/ansible-collections/community.general/blob/305748b3331c099981396460e90cff7ada3e45b3/plugins/modules/system/parted.py#L651
IMHO, I prefer to change the returned value to mixed-/upper-case which complies to ISO/IEC-80000.
@fgierlinger while I think adjusting the returned values is probably the better solution, it is also the most annoying one to implement, as it breaks backwards compatibility.
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.