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

Require force for LVM shrink and remove operations in lvol. Fixes #5774

Conflicts:
	library/system/lvol
This commit is contained in:
Stefan J. Betz 2014-01-26 18:07:48 +01:00 committed by Richard C Isaacson
parent 05bf80751b
commit 789ae4697c

View file

@ -47,6 +47,14 @@ options:
description: description:
- Control if the logical volume exists. - Control if the logical volume exists.
required: false required: false
force:
version_added: "1.5"
choices: [ "yes", "no" ]
default: "no"
description:
- Shrink or remove operations of volumes requires this switch. Ensures that
that filesystems get never corrupted/destroyed by mistake.
required: false
notes: notes:
- Filesystems on top of the volume are not resized. - Filesystems on top of the volume are not resized.
''' '''
@ -65,10 +73,10 @@ EXAMPLES = '''
- lvol: vg=firefly lv=test size=1024 - lvol: vg=firefly lv=test size=1024
# Reduce the logical volume to 512m # Reduce the logical volume to 512m
- lvol: vg=firefly lv=test size=512 - lvol: vg=firefly lv=test size=512 force=yes
# Remove the logical volume. # Remove the logical volume.
- lvol: vg=firefly lv=test state=absent - lvol: vg=firefly lv=test state=absent force=yes
''' '''
import re import re
@ -94,6 +102,7 @@ def main():
lv=dict(required=True), lv=dict(required=True),
size=dict(), size=dict(),
state=dict(choices=["absent", "present"], default='present'), state=dict(choices=["absent", "present"], default='present'),
force=dict(type='bool', default='no'),
), ),
supports_check_mode=True, supports_check_mode=True,
) )
@ -102,6 +111,7 @@ def main():
lv = module.params['lv'] lv = module.params['lv']
size = module.params['size'] size = module.params['size']
state = module.params['state'] state = module.params['state']
force = module.boolean(module.params['force'])
size_opt = 'L' size_opt = 'L'
size_unit = 'm' size_unit = 'm'
@ -179,12 +189,14 @@ def main():
if rc == 0: if rc == 0:
changed = True changed = True
else: else:
module.fail_json(msg="Creating logical volume '%s' failed" % (lv), rc=rc, err=err) module.fail_json(msg="Creating logical volume '%s' failed" % lv, rc=rc, err=err)
else: else:
if state == 'absent': if state == 'absent':
### remove LV ### remove LV
if module.check_mode: if module.check_mode:
module.exit_json(changed=True) module.exit_json(changed=True)
if not force:
module.fail_json(msg="Sorry, no removal of logical volume %s without force=yes." % (this_lv['name']))
rc, _, err = module.run_command("lvremove --force %s/%s" % (vg, this_lv['name'])) rc, _, err = module.run_command("lvremove --force %s/%s" % (vg, this_lv['name']))
if rc == 0: if rc == 0:
module.exit_json(changed=True) module.exit_json(changed=True)
@ -199,6 +211,8 @@ def main():
if size > this_lv['size']: if size > this_lv['size']:
tool = 'lvextend' tool = 'lvextend'
elif size < this_lv['size']: elif size < this_lv['size']:
if not force:
module.fail_json(msg="Sorry, no shrinking of %s without force=yes." % (this_lv['name']))
tool = 'lvreduce --force' tool = 'lvreduce --force'
if tool: if tool: