Skip to content

Commit

Permalink
Allow variables to be used in vars_prompt (ansible#32802)
Browse files Browse the repository at this point in the history
  • Loading branch information
samdoran authored and maxamillion committed Jan 5, 2018
1 parent 7bf75f2 commit 6d4ab66
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions lib/ansible/executor/playbook_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ def __init__(self, playbooks, inventory, variable_manager, loader, options, pass
check_for_controlpersist(C.ANSIBLE_SSH_EXECUTABLE)

def run(self):

'''
Run the given playbook, based on the settings in the play which
may limit the runs to serialized groups, etc.
Expand Down Expand Up @@ -103,8 +102,16 @@ def run(self):
# clear any filters which may have been applied to the inventory
self._inventory.remove_restriction()

# Create a temporary copy of the play here, so we can run post_validate
# on it without the templating changes affecting the original object.
# Doing this before vars_prompt to allow for using variables in prompt.
all_vars = self._variable_manager.get_vars(play=play)
templar = Templar(loader=self._loader, variables=all_vars)
new_play = play.copy()
new_play.post_validate(templar)

if play.vars_prompt:
for var in play.vars_prompt:
for var in new_play.vars_prompt:
vname = var['name']
prompt = var.get("prompt", vname)
default = var.get("default", None)
Expand All @@ -121,12 +128,10 @@ def run(self):
else: # we are either in --list-<option> or syntax check
play.vars[vname] = default

# Create a temporary copy of the play here, so we can run post_validate
# on it without the templating changes affecting the original object.
all_vars = self._variable_manager.get_vars(play=play)
templar = Templar(loader=self._loader, variables=all_vars)
new_play = play.copy()
new_play.post_validate(templar)
# Post validating again in case variables were entered in the prompt.
all_vars = self._variable_manager.get_vars(play=play)
templar = Templar(loader=self._loader, variables=all_vars)
new_play.post_validate(templar)

if self._options.syntax:
continue
Expand Down

0 comments on commit 6d4ab66

Please sign in to comment.