diff --git a/changelogs/fragments/vars_prompt-allow-prompting-for-play-vars.yaml b/changelogs/fragments/vars_prompt-allow-prompting-for-play-vars.yaml new file mode 100644 index 00000000000..d95857ae707 --- /dev/null +++ b/changelogs/fragments/vars_prompt-allow-prompting-for-play-vars.yaml @@ -0,0 +1,2 @@ +bugfixes: + - vars_prompt - properly template play level variables in vars_prompt (https://github.com/ansible/ansible/issues/37984) diff --git a/lib/ansible/executor/playbook_executor.py b/lib/ansible/executor/playbook_executor.py index 6c300977e2a..25020c4a1c0 100644 --- a/lib/ansible/executor/playbook_executor.py +++ b/lib/ansible/executor/playbook_executor.py @@ -102,16 +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 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. + # 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() - new_play.post_validate(templar) + setattr(play, 'vars_prompt', templar.template(play.vars_prompt)) if play.vars_prompt: - for var in new_play.vars_prompt: + for var in play.vars_prompt: vname = var['name'] prompt = var.get("prompt", vname) default = var.get("default", None) @@ -128,17 +125,17 @@ class PlaybookExecutor: else: # we are either in --list-