Merge pull request #6158 from risaacson/issues_5165

If you try to resize a lvol to the current size return a changed=False and don't fail.
This commit is contained in:
Michael DeHaan 2014-02-24 19:17:43 -05:00
commit 14df804545

View file

@ -72,8 +72,10 @@ EXAMPLES = '''
'''
import re
decimal_point = re.compile(r"(\.|,)")
def parse_lvs(data):
lvs = []
for line in data.splitlines():
@ -84,6 +86,7 @@ def parse_lvs(data):
})
return lvs
def main():
module = AnsibleModule(
argument_spec=dict(
@ -102,9 +105,6 @@ def main():
size_opt = 'L'
size_unit = 'm'
if state=='present' and not size:
module.fail_json(msg="No size given.")
if size:
# LVCREATE(8) -l --extents option with percentage
if '%' in size:
@ -141,7 +141,9 @@ def main():
unit = 'm'
else:
unit = size_unit
rc,current_lvs,err = module.run_command("lvs --noheadings -o lv_name,size --units %s --separator ';' %s" % (unit, vg))
rc, current_lvs, err = module.run_command(
"lvs --noheadings -o lv_name,size --units %s --separator ';' %s" % (unit, vg))
if rc != 0:
if state == 'absent':
@ -160,6 +162,12 @@ def main():
else:
this_lv = None
if state == 'present' and not size:
if this_lv is None:
module.fail_json(msg="No size given.")
else:
module.exit_json(changed=False, vg=vg, lv=this_lv['name'], size=this_lv['size'])
msg = ''
if this_lv is None:
if state == 'present':
@ -200,6 +208,8 @@ def main():
rc, _, err = module.run_command("%s -%s %s%s %s/%s" % (tool, size_opt, size, size_unit, vg, this_lv['name']))
if rc == 0:
changed = True
elif "matches existing size" in err:
module.exit_json(changed=False, vg=vg, lv=this_lv['name'], size=this_lv['size'])
else:
module.fail_json(msg="Unable to resize %s to %s%s" % (lv, size, size_unit), rc=rc, err=err)
@ -207,4 +217,5 @@ def main():
# import module snippets
from ansible.module_utils.basic import *
main()