Fix traceback in template action with ANSIBLE_DEBUG=1 (#79764)

Fixes #79763
pull/79783/head
Martin Krizek 1 year ago committed by GitHub
parent 868d721d8c
commit 4f5ed24972
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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)

@ -118,7 +118,11 @@ class ActionModule(ActionBase):
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

@ -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
Loading…
Cancel
Save