From 4ac0c23db642614654cc18388db434c1ab5685b4 Mon Sep 17 00:00:00 2001 From: Brian Coca Date: Wed, 30 Jan 2019 15:01:13 -0500 Subject: [PATCH] added unsafe toggle to vars_prompt (#49219) * added unsafe toggle to vars_prompt fixes #47534 --- changelogs/fragments/unsafe_prompt.yml | 2 ++ .../rst/user_guide/playbooks_prompts.rst | 13 +++++++++--- lib/ansible/executor/playbook_executor.py | 7 +++++-- lib/ansible/plugins/callback/__init__.py | 6 +++--- lib/ansible/utils/display.py | 7 +++++-- .../targets/vars_prompt/test-vars_prompt.py | 6 ++++++ .../targets/vars_prompt/unsafe.yml | 20 +++++++++++++++++++ 7 files changed, 51 insertions(+), 10 deletions(-) create mode 100644 changelogs/fragments/unsafe_prompt.yml create mode 100644 test/integration/targets/vars_prompt/unsafe.yml diff --git a/changelogs/fragments/unsafe_prompt.yml b/changelogs/fragments/unsafe_prompt.yml new file mode 100644 index 00000000000..de45bd22c1d --- /dev/null +++ b/changelogs/fragments/unsafe_prompt.yml @@ -0,0 +1,2 @@ +minor_changes: + - added 'unsafe' keyword to vars_prompt so users can signal 'template unsafe' content diff --git a/docs/docsite/rst/user_guide/playbooks_prompts.rst b/docs/docsite/rst/user_guide/playbooks_prompts.rst index 540c15a4cb2..b057f3be6ff 100644 --- a/docs/docsite/rst/user_guide/playbooks_prompts.rst +++ b/docs/docsite/rst/user_guide/playbooks_prompts.rst @@ -89,6 +89,16 @@ Depending on your platform at most the following crypt schemes are supported: - *sha256_crypt* - SHA-256 Crypt - *sha512_crypt* - SHA-512 Crypt +.. versionadded:: 2.8 + +If you need to put in special characters (i.e `{%`) that might create templating errors, use the ``unsafe`` option:: + + vars_prompt: + - name: "my_password_with_wierd_chars" + prompt: "Enter password" + unsafe: yes + private: yes + .. seealso:: :doc:`playbooks` @@ -101,6 +111,3 @@ Depending on your platform at most the following crypt schemes are supported: Have a question? Stop by the google group! `irc.freenode.net `_ #ansible IRC chat channel - - - diff --git a/lib/ansible/executor/playbook_executor.py b/lib/ansible/executor/playbook_executor.py index c2ac125bd31..5adecdd7f21 100644 --- a/lib/ansible/executor/playbook_executor.py +++ b/lib/ansible/executor/playbook_executor.py @@ -111,6 +111,7 @@ class PlaybookExecutor: templar = Templar(loader=self._loader, variables=all_vars) setattr(play, 'vars_prompt', templar.template(play.vars_prompt)) + # FIXME: this should be a play 'sub object' like loop_control if play.vars_prompt: for var in play.vars_prompt: vname = var['name'] @@ -121,11 +122,13 @@ class PlaybookExecutor: encrypt = var.get("encrypt", None) salt_size = var.get("salt_size", None) salt = var.get("salt", None) + unsafe = var.get("unsafe", None) 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) - play.vars[vname] = display.do_var_prompt(vname, private, prompt, encrypt, confirm, salt_size, salt, default) + 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-