diff --git a/changelogs/fragments/405-parted_align_undefined.yml b/changelogs/fragments/405-parted_align_undefined.yml new file mode 100644 index 0000000000..28398cc97f --- /dev/null +++ b/changelogs/fragments/405-parted_align_undefined.yml @@ -0,0 +1,2 @@ +bugfixes: + - "parted - added 'undefined' align option to support parted versions < 2.1 (https://github.com/ansible-collections/community.general/pull/405)." diff --git a/plugins/modules/system/parted.py b/plugins/modules/system/parted.py index aaeaa7f1fc..c2f1005d7c 100644 --- a/plugins/modules/system/parted.py +++ b/plugins/modules/system/parted.py @@ -19,7 +19,8 @@ description: command line tool. For a full description of the fields and the options check the GNU parted manual. requirements: - - This module requires parted version 1.8.3 and above. + - This module requires parted version 1.8.3 and above + - align option (except 'undefined') requires parted 2.1 and above - If the version of parted is below 3.1, it requires a Linux version running the sysfs file system C(/sys/). options: @@ -28,9 +29,9 @@ options: type: str required: True align: - description: Set alignment for newly created partitions. + description: Set alignment for newly created partitions. Use 'undefined' for parted default aligment. type: str - choices: [ cylinder, minimal, none, optimal ] + choices: [ cylinder, minimal, none, optimal, undefined ] default: optimal number: description: @@ -489,8 +490,12 @@ def parted(script, device, align): """ global module, parted_exec + align_option = '-a %s' % align + if align == 'undefined': + align_option = '' + if script and not module.check_mode: - command = "%s -s -m -a %s %s -- %s" % (parted_exec, align, device, script) + command = "%s -s -m %s %s -- %s" % (parted_exec, align_option, device, script) rc, out, err = module.run_command(command) if rc != 0: @@ -542,7 +547,7 @@ def main(): module = AnsibleModule( argument_spec=dict( device=dict(type='str', required=True), - align=dict(type='str', default='optimal', choices=['cylinder', 'minimal', 'none', 'optimal']), + align=dict(type='str', default='optimal', choices=['cylinder', 'minimal', 'none', 'optimal', 'undefined']), number=dict(type='int'), # unit command