mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-08 06:12:51 +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:
@@ -172,8 +172,10 @@ class Play(object):
|
||||
encrypt = var.get("encrypt", None)
|
||||
salt_size = var.get("salt_size", 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:
|
||||
for (vname, prompt) in self.vars_prompt.iteritems():
|
||||
|
||||
Reference in New Issue
Block a user