Merge pull request #470 from fdupoux/fix-lvol-lvcreate-prompt
Suppress prompts from lvcreate using --yes when LVM supports this option
This commit is contained in:
commit
3185f84505
1 changed files with 24 additions and 1 deletions
|
@ -85,6 +85,8 @@ import re
|
|||
|
||||
decimal_point = re.compile(r"(\.|,)")
|
||||
|
||||
def mkversion(major, minor, patch):
|
||||
return (1000 * 1000 * int(major)) + (1000 * int(minor)) + int(patch)
|
||||
|
||||
def parse_lvs(data):
|
||||
lvs = []
|
||||
|
@ -97,6 +99,17 @@ def parse_lvs(data):
|
|||
return lvs
|
||||
|
||||
|
||||
def get_lvm_version(module):
|
||||
ver_cmd = module.get_bin_path("lvm", required=True)
|
||||
rc, out, err = module.run_command("%s version" % (ver_cmd))
|
||||
if rc != 0:
|
||||
return None
|
||||
m = re.search("LVM version:\s+(\d+)\.(\d+)\.(\d+).*(\d{4}-\d{2}-\d{2})", out)
|
||||
if not m:
|
||||
return None
|
||||
return mkversion(m.group(1), m.group(2), m.group(3))
|
||||
|
||||
|
||||
def main():
|
||||
module = AnsibleModule(
|
||||
argument_spec=dict(
|
||||
|
@ -109,6 +122,16 @@ def main():
|
|||
supports_check_mode=True,
|
||||
)
|
||||
|
||||
# Determine if the "--yes" option should be used
|
||||
version_found = get_lvm_version(module)
|
||||
if version_found == None:
|
||||
module.fail_json(msg="Failed to get LVM version number")
|
||||
version_yesopt = mkversion(2, 2, 99) # First LVM with the "--yes" option
|
||||
if version_found >= version_yesopt:
|
||||
yesopt = "--yes"
|
||||
else:
|
||||
yesopt = ""
|
||||
|
||||
vg = module.params['vg']
|
||||
lv = module.params['lv']
|
||||
size = module.params['size']
|
||||
|
@ -189,7 +212,7 @@ def main():
|
|||
changed = True
|
||||
else:
|
||||
lvcreate_cmd = module.get_bin_path("lvcreate", required=True)
|
||||
rc, _, err = module.run_command("%s -n %s -%s %s%s %s" % (lvcreate_cmd, lv, size_opt, size, size_unit, vg))
|
||||
rc, _, err = module.run_command("%s %s -n %s -%s %s%s %s" % (lvcreate_cmd, yesopt, lv, size_opt, size, size_unit, vg))
|
||||
if rc == 0:
|
||||
changed = True
|
||||
else:
|
||||
|
|
Loading…
Reference in a new issue