mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Merge pull request #1080 from dagwieers/prompt-only_if
Add an only_if option to vars_prompt to make prompts conditional
This commit is contained in:
commit
734db4ffe9
3 changed files with 11 additions and 6 deletions
|
@ -172,8 +172,10 @@ class Play(object):
|
||||||
encrypt = var.get("encrypt", None)
|
encrypt = var.get("encrypt", None)
|
||||||
salt_size = var.get("salt_size", None)
|
salt_size = var.get("salt_size", None)
|
||||||
salt = var.get("salt", None)
|
salt = var.get("salt", None)
|
||||||
|
conditional = var.get("only_if", 'True')
|
||||||
|
|
||||||
vars[vname] = self.playbook.callbacks.on_vars_prompt(vname, private, prompt,encrypt, confirm, salt_size, salt)
|
if utils.check_conditional(conditional):
|
||||||
|
vars[vname] = self.playbook.callbacks.on_vars_prompt(vname, private, prompt,encrypt, confirm, salt_size, salt)
|
||||||
|
|
||||||
elif type(self.vars_prompt) == dict:
|
elif type(self.vars_prompt) == dict:
|
||||||
for (vname, prompt) in self.vars_prompt.iteritems():
|
for (vname, prompt) in self.vars_prompt.iteritems():
|
||||||
|
|
|
@ -317,12 +317,8 @@ class Runner(object):
|
||||||
new_args = new_args + "%s='%s' " % (k,v)
|
new_args = new_args + "%s='%s' " % (k,v)
|
||||||
module_args = new_args
|
module_args = new_args
|
||||||
|
|
||||||
def _check_conditional(conditional):
|
|
||||||
def is_set(var):
|
|
||||||
return not var.startswith("$")
|
|
||||||
return eval(conditional)
|
|
||||||
conditional = utils.template(self.basedir, self.conditional, inject)
|
conditional = utils.template(self.basedir, self.conditional, inject)
|
||||||
if not _check_conditional(conditional):
|
if not utils.check_conditional(conditional):
|
||||||
result = utils.jsonify(dict(skipped=True))
|
result = utils.jsonify(dict(skipped=True))
|
||||||
self.callbacks.on_skipped(host, inject.get('item',None))
|
self.callbacks.on_skipped(host, inject.get('item',None))
|
||||||
return ReturnData(host=host, result=result)
|
return ReturnData(host=host, result=result)
|
||||||
|
|
|
@ -93,6 +93,13 @@ def is_failed(result):
|
||||||
|
|
||||||
return ((result.get('rc', 0) != 0) or (result.get('failed', False) in [ True, 'True', 'true']))
|
return ((result.get('rc', 0) != 0) or (result.get('failed', False) in [ True, 'True', 'true']))
|
||||||
|
|
||||||
|
def check_conditional(conditional):
|
||||||
|
def is_set(var):
|
||||||
|
return not var.startswith("$")
|
||||||
|
def is_unset(var):
|
||||||
|
return var.startswith("$")
|
||||||
|
return eval(conditional)
|
||||||
|
|
||||||
def prepare_writeable_dir(tree):
|
def prepare_writeable_dir(tree):
|
||||||
''' make sure a directory exists and is writeable '''
|
''' make sure a directory exists and is writeable '''
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue