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

Add support for LVM to filesystem module (#21620)

And since LVM2_member is not a very userfiendly name, add
a mechanism for more user friendly names.
This commit is contained in:
Michael Scherer 2017-10-03 21:26:25 +02:00 committed by ansibot
parent ba0b91b51b
commit 6caac2743a

View file

@ -23,9 +23,11 @@ description:
version_added: "1.2" version_added: "1.2"
options: options:
fstype: fstype:
choices: [ "ext4", "ext4dev", "ext3", "ext2", "xfs", "btrfs", "reiserfs", "lvm"]
description: description:
- File System type to be created. - File System type to be created.
- reiserfs support was added in 2.2. - reiserfs support was added in 2.2.
- lvm support was added in 2.4.
required: true required: true
dev: dev:
description: description:
@ -111,22 +113,21 @@ def _get_fs_size(fssize_cmd, dev, module):
# There is no way to get the blocksize and blockcount for btrfs filesystems # There is no way to get the blocksize and blockcount for btrfs filesystems
block_size = 1 block_size = 1
block_count = 1 block_count = 1
elif 'pvs' == fssize_cmd:
rc, size, err = module.run_command([cmd, '--noheadings', '-o', 'pv_size', '--units', 'b', dev])
if rc == 0:
block_count = int(size[:-1])
block_size = 1
else:
module.fail_json(msg="Failed to get block count and block size of %s with %s" % (dev, cmd), rc=rc, err=err )
return block_size*block_count return block_size*block_count
def main(): def main():
module = AnsibleModule( friendly_names = {
argument_spec = dict( 'lvm': 'LVM2_member',
fstype=dict(required=True, aliases=['type']), }
dev=dict(required=True, aliases=['device']),
opts=dict(),
force=dict(type='bool', default='no'),
resizefs=dict(type='bool', default='no'),
),
supports_check_mode=True,
)
# There is no "single command" to manipulate filesystems, so we map them all out and their options # There is no "single command" to manipulate filesystems, so we map them all out and their options
fs_cmd_map = { fs_cmd_map = {
@ -178,15 +179,38 @@ def main():
'grow_flag' : 'filesystem resize', 'grow_flag' : 'filesystem resize',
'force_flag' : '-f', 'force_flag' : '-f',
'fsinfo': 'btrfs', 'fsinfo': 'btrfs',
},
'LVM2_member' : {
'mkfs' : 'pvcreate',
'grow' : 'pvresize',
'grow_flag' : None,
'force_flag' : '-f' ,
'fsinfo': 'pvs',
} }
} }
module = AnsibleModule(
argument_spec = dict(
fstype=dict(required=True, aliases=['type'],
choices=fs_cmd_map.keys() + friendly_names.keys()),
dev=dict(required=True, aliases=['device']),
opts=dict(),
force=dict(type='bool', default='no'),
resizefs=dict(type='bool', default='no'),
),
supports_check_mode=True,
)
dev = module.params['dev'] dev = module.params['dev']
fstype = module.params['fstype'] fstype = module.params['fstype']
opts = module.params['opts'] opts = module.params['opts']
force = module.boolean(module.params['force']) force = module.boolean(module.params['force'])
resizefs = module.boolean(module.params['resizefs']) resizefs = module.boolean(module.params['resizefs'])
if fstype in friendly_names:
fstype = friendly_names[fstype]
changed = False changed = False
try: try: