diff --git a/lib/ansible/executor/playbook_executor.py b/lib/ansible/executor/playbook_executor.py index c0b0c22187..6c300977e2 100644 --- a/lib/ansible/executor/playbook_executor.py +++ b/lib/ansible/executor/playbook_executor.py @@ -68,7 +68,6 @@ class PlaybookExecutor: 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. @@ -103,8 +102,16 @@ 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 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) @@ -121,12 +128,10 @@ class PlaybookExecutor: else: # we are either in --list-