diff --git a/changelogs/fragments/76610-empty-template-none.yml b/changelogs/fragments/76610-empty-template-none.yml new file mode 100644 index 00000000000..a69d5114881 --- /dev/null +++ b/changelogs/fragments/76610-empty-template-none.yml @@ -0,0 +1,2 @@ +bugfixes: + - "Fix for when templating empty template file resulted in file with string 'None' (https://github.com/ansible/ansible/issues/76610)" diff --git a/lib/ansible/template/native_helpers.py b/lib/ansible/template/native_helpers.py index c75d356b38a..79091d0c9a9 100644 --- a/lib/ansible/template/native_helpers.py +++ b/lib/ansible/template/native_helpers.py @@ -60,7 +60,7 @@ def ansible_concat(nodes, convert_data, variable_start_string): head = list(islice(nodes, 2)) if not head: - return None + return '' if len(head) == 1: out = _fail_on_undefined(head[0]) diff --git a/test/integration/targets/template/tasks/main.yml b/test/integration/targets/template/tasks/main.yml index d97aa4d550d..d07a605f771 100644 --- a/test/integration/targets/template/tasks/main.yml +++ b/test/integration/targets/template/tasks/main.yml @@ -756,3 +756,13 @@ - assert: that: - out.rc == 0 + +- template: + src: empty_template.j2 + dest: "{{ output_dir }}/empty_template.templated" + +- assert: + that: + - test + vars: + test: "{{ lookup('file', '{{ output_dir }}/empty_template.templated')|length == 0 }}" diff --git a/test/integration/targets/template/templates/empty_template.j2 b/test/integration/targets/template/templates/empty_template.j2 new file mode 100644 index 00000000000..e69de29bb2d