parted option align: undefined to maintain parted 1.8.3 compatibility (#405)

* option align: undefined to maintain parted 1.8.3 compatibility

* modified argument_spec

* changelog fragment for #405

* Update changelogs/fragments/405-parted_align_undefined.yml

Co-authored-by: Felix Fontein <felix@fontein.de>

Co-authored-by: Felix Fontein <felix@fontein.de>
This commit is contained in:
Robert Osowiecki 2020-06-19 08:41:59 +02:00 committed by GitHub
parent ab5533022e
commit 9e28f3cceb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 5 deletions

View file

@ -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)."

View file

@ -19,7 +19,8 @@ description:
command line tool. For a full description of the fields and the options command line tool. For a full description of the fields and the options
check the GNU parted manual. check the GNU parted manual.
requirements: 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 - If the version of parted is below 3.1, it requires a Linux version running
the sysfs file system C(/sys/). the sysfs file system C(/sys/).
options: options:
@ -28,9 +29,9 @@ options:
type: str type: str
required: True required: True
align: align:
description: Set alignment for newly created partitions. description: Set alignment for newly created partitions. Use 'undefined' for parted default aligment.
type: str type: str
choices: [ cylinder, minimal, none, optimal ] choices: [ cylinder, minimal, none, optimal, undefined ]
default: optimal default: optimal
number: number:
description: description:
@ -489,8 +490,12 @@ def parted(script, device, align):
""" """
global module, parted_exec global module, parted_exec
align_option = '-a %s' % align
if align == 'undefined':
align_option = ''
if script and not module.check_mode: 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) rc, out, err = module.run_command(command)
if rc != 0: if rc != 0:
@ -542,7 +547,7 @@ def main():
module = AnsibleModule( module = AnsibleModule(
argument_spec=dict( argument_spec=dict(
device=dict(type='str', required=True), 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'), number=dict(type='int'),
# unit <unit> command # unit <unit> command