From 333ee8d01086057de7a7b9c2b17aa8aaf4f05af3 Mon Sep 17 00:00:00 2001 From: Sloane Hertel <19572925+s-hertel@users.noreply.github.com> Date: Fri, 7 Feb 2025 16:15:59 -0500 Subject: [PATCH] Test include_vars reserved variable matching (#84678) * Add test case for include_vars * Revise test to catch erroneous warnings --- .../var_reserved/tasks/include_vars.yml | 5 ++++ .../targets/var_reserved/tasks/main.yml | 26 +++++++++++++------ .../var_reserved/vars/set_host_variable.yml | 1 + 3 files changed, 24 insertions(+), 8 deletions(-) create mode 100644 test/integration/targets/var_reserved/tasks/include_vars.yml create mode 100644 test/integration/targets/var_reserved/vars/set_host_variable.yml diff --git a/test/integration/targets/var_reserved/tasks/include_vars.yml b/test/integration/targets/var_reserved/tasks/include_vars.yml new file mode 100644 index 00000000000..af05f3f71e6 --- /dev/null +++ b/test/integration/targets/var_reserved/tasks/include_vars.yml @@ -0,0 +1,5 @@ +- hosts: localhost + gather_facts: no + tasks: + - include_vars: + file: ../vars/set_host_variable.yml diff --git a/test/integration/targets/var_reserved/tasks/main.yml b/test/integration/targets/var_reserved/tasks/main.yml index c4c9600f6d8..efd5f9fcb2a 100644 --- a/test/integration/targets/var_reserved/tasks/main.yml +++ b/test/integration/targets/var_reserved/tasks/main.yml @@ -2,22 +2,32 @@ vars: canary: Found variable using reserved name block: - - shell: ansible-playbook '{{[ role_path, "tasks", item ~ ".yml"] | path_join }}' + - shell: ansible-playbook '{{[ role_path, "tasks", item.file ~ ".yml"] | path_join }}' environment: ANSIBLE_LOCALHOST_WARNING: 0 + ANSIBLE_FORCE_COLOR: 0 failed_when: false loop: - - play_vars - - block_vars - - task_vars - - task_vars_used - - set_fact + - file: play_vars + name: lipsum + - file: block_vars + name: query + - file: task_vars + name: query + - file: task_vars_used + name: q + - file: set_fact + name: lookup + - file: include_vars + name: query register: play_out - name: check they all complain about bad defined var assert: that: - - canary in item['stderr'] + - item.stderr == warning_message loop: '{{play_out.results}}' loop_control: - label: '{{item.item}}' + label: '{{item.item.file}}' + vars: + warning_message: "[WARNING]: {{ canary }}: {{ item.item.name }}" diff --git a/test/integration/targets/var_reserved/vars/set_host_variable.yml b/test/integration/targets/var_reserved/vars/set_host_variable.yml new file mode 100644 index 00000000000..a6b4dead74d --- /dev/null +++ b/test/integration/targets/var_reserved/vars/set_host_variable.yml @@ -0,0 +1 @@ +query: overwrite global Jinja2 function