Skip to content

Commit

Permalink
parted: support fs_type (#221)
Browse files Browse the repository at this point in the history
* parted: support fs_type

Closes #135

* Update plugins/modules/system/parted.py

Co-Authored-By: Andrew Klychkov <[email protected]>

* Update plugins/modules/system/parted.py

Co-Authored-By: Andrew Klychkov <[email protected]>

Co-authored-by: Andrew Klychkov <[email protected]>
  • Loading branch information
ilpianista and Andersson007 authored Apr 27, 2020
1 parent 61ecc1f commit c2e37d2
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/221-parted-fs_type-parameter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
minor_changes:
- parted - add the ``fs_type`` parameter (https://github.com/ansible-collections/community.general/issues/135).
13 changes: 11 additions & 2 deletions plugins/modules/system/parted.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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'),
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
)
Expand Down
3 changes: 2 additions & 1 deletion tests/unit/plugins/modules/system/test_parted.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c2e37d2

Please sign in to comment.