Repository: ansible-collections/community.general

Issue:
parted: add filesystem type parameter
<!--- Verify first that your feature was not already discussed on GitHub -->
<!--- Complete *all* sections as described, this form is processed automatically -->

##### SUMMARY
GNU parted allows specifying optional filesystem type, which has effect on some partition labels:
**mkpart** `part-type [fs-type] start end`
Ansible parted module should allow to specify it to override parted defaults

##### ISSUE TYPE
- Feature Idea

##### COMPONENT NAME
parted

##### ADDITIONAL INFORMATION
<!--- Describe how the feature would be used, why it is needed and what it would solve -->

<!--- Paste example playbooks or commands between quotes below -->
```yaml
  parted:
    device: /dev/sdb
    number: 1
    part_end: 100%
    state: present
    filesystem: fat
```

<!--- HINT: You can also paste gist.github.com links for larger files -->



Discussion:
cc @ColOfAbRiX
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: notify --->
cc @MorrisA @bcoca @d-little @flynn1973 @gforster @kairoaraujo @marvin-sinister @mator @molekuul @ramooncamacho @wtcross
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: notify --->

Resolving patch:
diff --git a/plugins/modules/system/parted.py b/plugins/modules/system/parted.py
--- a/plugins/modules/system/parted.py
+++ b/plugins/modules/system/parted.py
@@ -95,6 +95,11 @@
     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 @@
 '''
 
 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 <partition> <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
             )


Test patch:
diff --git a/tests/unit/plugins/modules/system/test_parted.py b/tests/unit/plugins/modules/system/test_parted.py
--- a/tests/unit/plugins/modules/system/test_parted.py
+++ b/tests/unit/plugins/modules/system/test_parted.py
@@ -218,10 +218,11 @@ def test_create_new_primary_lvm_partition(self):
             '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