summaryrefslogtreecommitdiffstats
path: root/test/integration/targets/lookup_vars/tasks/main.yml
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 16:04:21 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 16:04:21 +0000
commit8a754e0858d922e955e71b253c139e071ecec432 (patch)
tree527d16e74bfd1840c85efd675fdecad056c54107 /test/integration/targets/lookup_vars/tasks/main.yml
parentInitial commit. (diff)
downloadansible-core-8a754e0858d922e955e71b253c139e071ecec432.tar.xz
ansible-core-8a754e0858d922e955e71b253c139e071ecec432.zip
Adding upstream version 2.14.3.upstream/2.14.3upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'test/integration/targets/lookup_vars/tasks/main.yml')
-rw-r--r--test/integration/targets/lookup_vars/tasks/main.yml56
1 files changed, 56 insertions, 0 deletions
diff --git a/test/integration/targets/lookup_vars/tasks/main.yml b/test/integration/targets/lookup_vars/tasks/main.yml
new file mode 100644
index 0000000..57b05b8
--- /dev/null
+++ b/test/integration/targets/lookup_vars/tasks/main.yml
@@ -0,0 +1,56 @@
+- name: Test that we can give it a single value and receive a single value
+ set_fact:
+ var_host: '{{ lookup("vars", "ansible_host") }}'
+
+- assert:
+ that:
+ - 'var_host == ansible_host'
+
+- name: Test that we can give a list of values to var and receive a list of values back
+ set_fact:
+ var_host_info: '{{ query("vars", "ansible_host", "ansible_connection") }}'
+
+- assert:
+ that:
+ - 'var_host_info[0] == ansible_host'
+ - 'var_host_info[1] == ansible_connection'
+
+- block:
+ - name: EXPECTED FAILURE - test invalid var
+ debug:
+ var: '{{ lookup("vars", "doesnotexist") }}'
+
+ - fail:
+ msg: "should not get here"
+
+ rescue:
+ - assert:
+ that:
+ - ansible_failed_task.name == "EXPECTED FAILURE - test invalid var"
+ - expected in ansible_failed_result.msg
+ vars:
+ expected: "No variable found with this name: doesnotexist"
+
+- block:
+ - name: EXPECTED FAILURE - test invalid var type
+ debug:
+ var: '{{ lookup("vars", 42) }}'
+
+ - fail:
+ msg: "should not get here"
+
+ rescue:
+ - assert:
+ that:
+ - ansible_failed_task.name == "EXPECTED FAILURE - test invalid var type"
+ - expected in ansible_failed_result.msg
+ vars:
+ expected: "Invalid setting identifier, \"42\" is not a string"
+
+- name: test default
+ set_fact:
+ expected_default_var: '{{ lookup("vars", "doesnotexist", default="some text") }}'
+
+- assert:
+ that:
+ - expected_default_var == "some text"