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

Prevent parted warnings in script mode #7304

Merged
2 changes: 2 additions & 0 deletions changelogs/fragments/7304-prevent-parted-warnings.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
minor_changes:
- parted - On resize, use --fix option if available (https://github.com/ansible-collections/community.general/pull/7304)
oldmanhere marked this conversation as resolved.
Show resolved Hide resolved
24 changes: 23 additions & 1 deletion plugins/modules/parted.py
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,23 @@ def parted_version():
return major, minor, rev


def check_parted_fix():
"""
Determines if parted have option --fix (-f). Versions prior
to 3.4.64 don't have it. For more information see:
http://savannah.gnu.org/news/?id=10114
"""
global parted_exec # pylint: disable=global-variable-not-assigned

parted_major, parted_minor, revision = parted_version()
if (parted_major == 3 and parted_minor == 4 and revision >= 64):
return True
if (parted_major == 3 and parted_minor >= 5) or parted_major > 3:
return True
oldmanhere marked this conversation as resolved.
Show resolved Hide resolved

return False


def parted(script, device, align):
"""
Runs a parted script.
Expand All @@ -569,8 +586,13 @@ def parted(script, device, align):
if align == 'undefined':
align_option = ''

if check_parted_fix():
script_option = '-s -f'
else:
script_option = '-s'

if script and not module.check_mode:
command = "%s -s -m %s %s -- %s" % (parted_exec, align_option, device, script)
command = "%s %s -m %s %s -- %s" % (parted_exec, script_option, align_option, device, script)
rc, out, err = module.run_command(command)

if rc != 0:
Expand Down