Skip to content

Instantly share code, notes, and snippets.

@samdoran
Last active August 3, 2018 18:00
Show Gist options
  • Select an option

  • Save samdoran/629f60bec7bb3bda97625e0041487938 to your computer and use it in GitHub Desktop.

Select an option

Save samdoran/629f60bec7bb3bda97625e0041487938 to your computer and use it in GitHub Desktop.
diff --git a/lib/ansible/executor/playbook_executor.py b/lib/ansible/executor/playbook_executor.py
index 46575ae79f..b72970a64a 100644
--- a/lib/ansible/executor/playbook_executor.py
+++ b/lib/ansible/executor/playbook_executor.py
@@ -102,17 +102,13 @@ class PlaybookExecutor:
# 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 template varibales
- # in vars_prompt fields without the templating changes affecting the original object.
- #
- # The next four lines allow variables to be used in vars_prompt fields.
+ # Allow variables to be used in vars_prompt fields.
all_vars = self._variable_manager.get_vars(play=play)
templar = Templar(loader=self._loader, variables=all_vars)
- new_play = play.copy()
- setattr(new_play, 'vars_prompt', templar.template(new_play.vars_prompt))
+ setattr(play, 'vars_prompt', templar.template(play.vars_prompt))
- if new_play.vars_prompt:
- for var in new_play.vars_prompt:
+ if play.vars_prompt:
+ for var in play.vars_prompt:
vname = var['name']
prompt = var.get("prompt", vname)
default = var.get("default", None)
@@ -129,10 +125,12 @@ class PlaybookExecutor:
else: # we are either in --list-<option> or syntax check
play.vars[vname] = default
- # Post validate the play in order to template any variables used at the play level
+ # 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)
- play.post_validate(templar)
+ new_play = play.copy()
+ new_play.post_validate(templar)
if self._options.syntax:
continue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment