mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-07 05:42:50 +00:00
Add an only_if option to vars_prompt to make prompts conditional
Sometimes you may want to allow variables through host_vars or inventory, but prompt for a value if it is not set or if the value does not conform to something specific. This option allows you to specify when you want to offer a prompt.
This patch also moves check_conditional to utils, and adds an is_unset() function which is nicer to read:
only_if: "not is_set('${var}')"
vs
only_if: "is_unset('${var}')"
This commit is contained in:
@@ -329,12 +329,8 @@ class Runner(object):
|
||||
self.module_args = new_args
|
||||
self.module_args = utils.template(self.basedir, self.module_args, inject)
|
||||
|
||||
def _check_conditional(conditional):
|
||||
def is_set(var):
|
||||
return not var.startswith("$")
|
||||
return eval(conditional)
|
||||
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))
|
||||
self.callbacks.on_skipped(host, inject.get('item',None))
|
||||
return ReturnData(host=host, result=result)
|
||||
|
||||
Reference in New Issue
Block a user