1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

parted: support fs_type (#221)

* parted: support fs_type

Closes #135

* Update plugins/modules/system/parted.py

Co-Authored-By: Andrew Klychkov <aaklychkov@mail.ru>

* Update plugins/modules/system/parted.py

Co-Authored-By: Andrew Klychkov <aaklychkov@mail.ru>

Co-authored-by: Andrew Klychkov <aaklychkov@mail.ru>
This commit is contained in:
Andrea Scarpino 2020-04-27 15:30:48 +00:00 committed by GitHub
parent 61ecc1fee4
commit c2e37d202a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 3 deletions

View file

@ -0,0 +1,2 @@
minor_changes:
- parted - add the ``fs_type`` parameter (https://github.com/ansible-collections/community.general/issues/135).

View file

@ -95,6 +95,11 @@ options:
type: str type: str
choices: [ absent, present, info ] choices: [ absent, present, info ]
default: 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: notes:
- When fetching information about a new disk and when the version of parted - 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 installed on the system is before version 3.1, the module queries the kernel
@ -145,11 +150,12 @@ partition_info:
''' '''
EXAMPLES = r''' EXAMPLES = r'''
- name: Create a new primary partition - name: Create a new ext4 primary partition
parted: parted:
device: /dev/sdb device: /dev/sdb
number: 1 number: 1
state: present state: present
fs_type: ext4
- name: Remove partition number 1 - name: Remove partition number 1
parted: parted:
@ -548,6 +554,7 @@ def main():
part_type=dict(type='str', default='primary', choices=['extended', 'logical', 'primary']), part_type=dict(type='str', default='primary', choices=['extended', 'logical', 'primary']),
part_start=dict(type='str', default='0%'), part_start=dict(type='str', default='0%'),
part_end=dict(type='str', default='100%'), part_end=dict(type='str', default='100%'),
fs_type=dict(type='str'),
# name <partition> <name> command # name <partition> <name> command
name=dict(type='str'), name=dict(type='str'),
@ -578,6 +585,7 @@ def main():
name = module.params['name'] name = module.params['name']
state = module.params['state'] state = module.params['state']
flags = module.params['flags'] flags = module.params['flags']
fs_type = module.params['fs_type']
# Parted executable # Parted executable
parted_exec = module.get_bin_path('parted', True) parted_exec = module.get_bin_path('parted', True)
@ -610,8 +618,9 @@ def main():
# Create partition if required # Create partition if required
if part_type and not part_exists(current_parts, 'num', number): if part_type and not part_exists(current_parts, 'num', number):
script += "mkpart %s %s %s " % ( script += "mkpart %s %s%s %s " % (
part_type, part_type,
'%s ' % fs_type if fs_type is not None else '',
part_start, part_start,
part_end part_end
) )

View file

@ -218,10 +218,11 @@ class TestParted(ModuleTestCase):
'flags': ["boot"], 'flags': ["boot"],
'state': 'present', 'state': 'present',
'part_start': '257GiB', 'part_start': '257GiB',
'fs_type': 'ext3',
'_ansible_check_mode': True, '_ansible_check_mode': True,
}) })
with patch('ansible_collections.community.general.plugins.modules.system.parted.get_device_info', return_value=parted_dict1): 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): def test_create_label_gpt(self):
# Like previous test, current implementation use parted to create the partition and # Like previous test, current implementation use parted to create the partition and