Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions changelogs/fragments/405-parted_align_undefined.yml
Original file line number Diff line number Diff line change
@@ -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)."
15 changes: 10 additions & 5 deletions plugins/modules/system/parted.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
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:
Expand All @@ -28,9 +29,9 @@
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:
Expand Down Expand Up @@ -483,8 +484,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:
Expand Down Expand Up @@ -536,7 +541,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 <unit> command
Expand Down