diff --git a/changelogs/fragments/221-parted-fs_type-parameter.yml b/changelogs/fragments/221-parted-fs_type-parameter.yml new file mode 100644 index 0000000000..df75b04b83 --- /dev/null +++ b/changelogs/fragments/221-parted-fs_type-parameter.yml @@ -0,0 +1,2 @@ +minor_changes: +- parted - add the ``fs_type`` parameter (https://github.com/ansible-collections/community.general/issues/135). diff --git a/plugins/modules/system/parted.py b/plugins/modules/system/parted.py index fcc1b8aaac..fd19d65d59 100644 --- a/plugins/modules/system/parted.py +++ b/plugins/modules/system/parted.py @@ -95,6 +95,11 @@ options: type: str choices: [ absent, present, info ] default: info + fs_type: + description: + - If specified and the partition does not exist, will set filesystem type to given partition. + type: str + version_added: '2.10' notes: - When fetching information about a new disk and when the version of parted installed on the system is before version 3.1, the module queries the kernel @@ -145,11 +150,12 @@ partition_info: ''' EXAMPLES = r''' -- name: Create a new primary partition +- name: Create a new ext4 primary partition parted: device: /dev/sdb number: 1 state: present + fs_type: ext4 - name: Remove partition number 1 parted: @@ -548,6 +554,7 @@ def main(): part_type=dict(type='str', default='primary', choices=['extended', 'logical', 'primary']), part_start=dict(type='str', default='0%'), part_end=dict(type='str', default='100%'), + fs_type=dict(type='str'), # name command name=dict(type='str'), @@ -578,6 +585,7 @@ def main(): name = module.params['name'] state = module.params['state'] flags = module.params['flags'] + fs_type = module.params['fs_type'] # Parted executable parted_exec = module.get_bin_path('parted', True) @@ -610,8 +618,9 @@ def main(): # Create partition if required if part_type and not part_exists(current_parts, 'num', number): - script += "mkpart %s %s %s " % ( + script += "mkpart %s %s%s %s " % ( part_type, + '%s ' % fs_type if fs_type is not None else '', part_start, part_end ) diff --git a/tests/unit/plugins/modules/system/test_parted.py b/tests/unit/plugins/modules/system/test_parted.py index 75a8ddc2d8..85345c071e 100644 --- a/tests/unit/plugins/modules/system/test_parted.py +++ b/tests/unit/plugins/modules/system/test_parted.py @@ -218,10 +218,11 @@ class TestParted(ModuleTestCase): 'flags': ["boot"], 'state': 'present', 'part_start': '257GiB', + 'fs_type': 'ext3', '_ansible_check_mode': True, }) with patch('ansible_collections.community.general.plugins.modules.system.parted.get_device_info', return_value=parted_dict1): - self.execute_module(changed=True, script='unit KiB mkpart primary 257GiB 100% unit KiB set 4 boot on') + self.execute_module(changed=True, script='unit KiB mkpart primary ext3 257GiB 100% unit KiB set 4 boot on') def test_create_label_gpt(self): # Like previous test, current implementation use parted to create the partition and