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:
Dag Wieers 2012-09-24 21:06:34 +02:00
parent 3939f7a812
commit 4e9a970616
3 changed files with 11 additions and 6 deletions

View file

@ -93,6 +93,13 @@ def is_failed(result):
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):
''' make sure a directory exists and is writeable '''