diff --git a/lib/ansible/modules/system/parted.py b/lib/ansible/modules/system/parted.py index 46ecdcafdc..5b43742718 100644 --- a/lib/ansible/modules/system/parted.py +++ b/lib/ansible/modules/system/parted.py @@ -658,10 +658,18 @@ def main(): # Assign name to the partition if name is not None and partition.get('name', None) != name: - script += "name %s %s " % (number, name) + # Wrap double quotes in single quotes so the shell doesn't strip + # the double quotes as those need to be included in the arg + # passed to parted + script += 'name %s \'"%s"\' ' % (number, name) # Manage flags if flags: + # Parted infers boot with esp, if you assign esp, boot is set + # and if boot is unset, esp is also unset. + if 'esp' in flags and 'boot' not in flags: + flags.append('boot') + # Compute only the changes in flags status flags_off = list(set(partition['flags']) - set(flags)) flags_on = list(set(flags) - set(partition['flags'])) diff --git a/test/units/modules/system/test_parted.py b/test/units/modules/system/test_parted.py index 95735aabd1..df141af797 100644 --- a/test/units/modules/system/test_parted.py +++ b/test/units/modules/system/test_parted.py @@ -237,4 +237,4 @@ class TestParted(ModuleTestCase): '_ansible_check_mode': True, }) with patch('ansible.modules.system.parted.get_device_info', return_value=parted_dict2): - self.execute_module(changed=True, script='unit KiB mklabel gpt mkpart primary 0% 100% unit KiB name 1 lvmpartition set 1 lvm on') + self.execute_module(changed=True, script='unit KiB mklabel gpt mkpart primary 0% 100% unit KiB name 1 \'"lvmpartition"\' set 1 lvm on')