diff --git a/changelogs/fragments/vars_prompt_choices_support.yml b/changelogs/fragments/vars_prompt_choices_support.yml new file mode 100644 index 00000000000..48c173ce277 --- /dev/null +++ b/changelogs/fragments/vars_prompt_choices_support.yml @@ -0,0 +1,3 @@ +--- +minor_changes: + - vars_prompt now supports a `choices` key for input validation. If choices are defined, users must pick one of the provided options. Values supplied via `--extra-vars` are also validated against the choices list. diff --git a/lib/ansible/executor/playbook_executor.py b/lib/ansible/executor/playbook_executor.py index 9bd7317615c..9c50dcc8f77 100644 --- a/lib/ansible/executor/playbook_executor.py +++ b/lib/ansible/executor/playbook_executor.py @@ -139,13 +139,48 @@ class PlaybookExecutor: salt = var.get("salt", None) unsafe = boolean(var.get("unsafe", False)) - if vname not in self._variable_manager.extra_vars: - if self._tqm: - self._tqm.send_callback('v2_playbook_on_vars_prompt', vname, private, prompt, encrypt, confirm, salt_size, salt, - default, unsafe) - play.vars[vname] = display.do_var_prompt(vname, private, prompt, encrypt, confirm, salt_size, salt, default, unsafe) - else: # we are either in --list-