diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-14 20:03:01 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-14 20:03:01 +0000 |
commit | a453ac31f3428614cceb99027f8efbdb9258a40b (patch) | |
tree | f61f87408f32a8511cbd91799f9cececb53e0374 /test/integration/targets/var_templating | |
parent | Initial commit. (diff) | |
download | ansible-upstream.tar.xz ansible-upstream.zip |
Adding upstream version 2.10.7+merged+base+2.10.8+dfsg.upstream/2.10.7+merged+base+2.10.8+dfsgupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'test/integration/targets/var_templating')
8 files changed, 131 insertions, 0 deletions
diff --git a/test/integration/targets/var_templating/aliases b/test/integration/targets/var_templating/aliases new file mode 100644 index 00000000..b5983214 --- /dev/null +++ b/test/integration/targets/var_templating/aliases @@ -0,0 +1 @@ +shippable/posix/group3 diff --git a/test/integration/targets/var_templating/group_vars/all.yml b/test/integration/targets/var_templating/group_vars/all.yml new file mode 100644 index 00000000..4eae7c1b --- /dev/null +++ b/test/integration/targets/var_templating/group_vars/all.yml @@ -0,0 +1,7 @@ +--- +x: 100 +y: "{{ x }}" +nested_x: + value: + x: 100 +nested_y: "{{ nested_x }}" diff --git a/test/integration/targets/var_templating/runme.sh b/test/integration/targets/var_templating/runme.sh new file mode 100755 index 00000000..0d3ac6bb --- /dev/null +++ b/test/integration/targets/var_templating/runme.sh @@ -0,0 +1,17 @@ +#!/usr/bin/env bash + +set -eux + +# this should succeed since we override the undefined variable +ansible-playbook undefined.yml -i inventory -v "$@" -e '{"mytest": False}' + +# this should still work, just show that var is undefined in debug +ansible-playbook undefined.yml -i inventory -v "$@" + +# this should work since we dont use the variable +ansible-playbook undall.yml -i inventory -v "$@" + +# test hostvars templating +ansible-playbook task_vars_templating.yml -v "$@" + +ansible-playbook test_connection_vars.yml -v "$@" 2>&1 | grep 'sudo' diff --git a/test/integration/targets/var_templating/task_vars_templating.yml b/test/integration/targets/var_templating/task_vars_templating.yml new file mode 100644 index 00000000..88e1e604 --- /dev/null +++ b/test/integration/targets/var_templating/task_vars_templating.yml @@ -0,0 +1,58 @@ +--- +- hosts: localhost + connection: local + gather_facts: no + tasks: + - add_host: + name: host1 + ansible_connection: local + ansible_host: 127.0.0.1 + +- hosts: all + gather_facts: no + tasks: + - debug: + msg: "{{ hostvars['host1']['x'] }}" + register: x_1 + - debug: + msg: "{{ hostvars['host1']['y'] }}" + register: y_1 + - debug: + msg: "{{ hostvars_['x'] }}" + vars: + hostvars_: "{{ hostvars['host1'] }}" + register: x_2 + - debug: + msg: "{{ hostvars_['y'] }}" + vars: + hostvars_: "{{ hostvars['host1'] }}" + register: y_2 + + - assert: + that: + - x_1 == x_2 + - y_1 == y_2 + - x_1 == y_1 + + - debug: + msg: "{{ hostvars['host1']['nested_x']['value'] }}" + register: x_1 + - debug: + msg: "{{ hostvars['host1']['nested_y']['value'] }}" + register: y_1 + - debug: + msg: "{{ hostvars_['nested_x']['value'] }}" + vars: + hostvars_: "{{ hostvars['host1'] }}" + register: x_2 + - debug: + msg: "{{ hostvars_['nested_y']['value'] }}" + vars: + hostvars_: "{{ hostvars['host1'] }}" + register: y_2 + + - assert: + that: + - x_1 == x_2 + - y_1 == y_2 + - x_1 == y_1 diff --git a/test/integration/targets/var_templating/test_connection_vars.yml b/test/integration/targets/var_templating/test_connection_vars.yml new file mode 100644 index 00000000..2b22eea6 --- /dev/null +++ b/test/integration/targets/var_templating/test_connection_vars.yml @@ -0,0 +1,26 @@ +--- +- hosts: localhost + gather_facts: no + vars: + my_var: + become_method: sudo + connection: local + become: 1 + tasks: + + - include_vars: "./vars/connection.yml" + + - command: whoami + ignore_errors: yes + register: result + failed_when: result is not success and (result.module_stderr is defined or result.module_stderr is defined) + + - assert: + that: + - "'sudo' in result.module_stderr" + when: result is not success and result.module_stderr is defined + + - assert: + that: + - "'Invalid become method specified' not in result.msg" + when: result is not success and result.msg is defined diff --git a/test/integration/targets/var_templating/undall.yml b/test/integration/targets/var_templating/undall.yml new file mode 100644 index 00000000..9ea9f1d1 --- /dev/null +++ b/test/integration/targets/var_templating/undall.yml @@ -0,0 +1,6 @@ +- hosts: localhost + gather_facts: false + tasks: + - debug: + vars: + mytest: '{{ und }}' diff --git a/test/integration/targets/var_templating/undefined.yml b/test/integration/targets/var_templating/undefined.yml new file mode 100644 index 00000000..cf083d5f --- /dev/null +++ b/test/integration/targets/var_templating/undefined.yml @@ -0,0 +1,13 @@ +- hosts: localhost + gather_facts: false + tasks: + - name: show defined/undefined var + debug: var=mytest + vars: + mytest: '{{ und }}' + register: var_undefined + + - name: ensure either mytest is defined or debug finds it to be undefined + assert: + that: + - mytest is defined or 'VARIABLE IS NOT DEFINED!' in var_undefined['mytest'] diff --git a/test/integration/targets/var_templating/vars/connection.yml b/test/integration/targets/var_templating/vars/connection.yml new file mode 100644 index 00000000..263929a8 --- /dev/null +++ b/test/integration/targets/var_templating/vars/connection.yml @@ -0,0 +1,3 @@ +ansible_become: "{{ my_var.become }}" +ansible_become_method: "{{ my_var.become_method }}" +ansible_connection: "{{ my_var.connection }}" |