Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix traceback in template action with ANSIBLE_DEBUG=1 #79764

Merged
merged 3 commits into from Jan 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions changelogs/fragments/79763-ansible_debug_template_tb_fix.yml
@@ -0,0 +1,2 @@
bugfixes:
- Fix traceback when using the ``template`` module and running with ``ANSIBLE_DEBUG=1`` (https://github.com/ansible/ansible/issues/79763)
6 changes: 5 additions & 1 deletion lib/ansible/plugins/action/template.py
Expand Up @@ -118,7 +118,11 @@ def run(self, tmp=None, task_vars=None):
searchpath = newsearchpath

# add ansible 'template' vars
temp_vars = task_vars | generate_ansible_template_vars(self._task.args.get('src', None), source, dest)
temp_vars = task_vars.copy()
# NOTE in the case of ANSIBLE_DEBUG=1 task_vars is VarsWithSources(MutableMapping)
# so | operator cannot be used as it can be used only on dicts
# https://peps.python.org/pep-0584/#what-about-mapping-and-mutablemapping
temp_vars.update(generate_ansible_template_vars(self._task.args.get('src', None), source, dest))

# force templar to use AnsibleEnvironment to prevent issues with native types
# https://github.com/ansible/ansible/issues/46169
Expand Down
@@ -0,0 +1 @@
{{ hello }}
3 changes: 3 additions & 0 deletions test/integration/targets/var_templating/runme.sh
Expand Up @@ -16,3 +16,6 @@ ansible-playbook task_vars_templating.yml -v "$@"

# there should be an attempt to use 'sudo' in the connection debug output
ANSIBLE_BECOME_ALLOW_SAME_USER=true ansible-playbook test_connection_vars.yml -vvvv "$@" | tee /dev/stderr | grep 'sudo \-H \-S'

# smoke test usage of VarsWithSources that is used when ANSIBLE_DEBUG=1
ANSIBLE_DEBUG=1 ansible-playbook test_vars_with_sources.yml -v "$@"
@@ -0,0 +1,9 @@
- hosts: localhost
gather_facts: false
tasks:
- template:
src: ansible_debug_template.j2
dest: "{{ output_dir }}/ansible_debug_templated.txt"
vars:
output_dir: "{{ lookup('env', 'OUTPUT_DIR') }}"
hello: hello