Debian Codegraph @

test/integration/targets/lookup_vars/tasks/main.yml

raw
1 - name: Test that we can give it a single value and receive a single value
2 set_fact:
3 var_host: '{{ lookup("vars", "ansible_host") }}'
4
5 - assert:
6 that:
7 - 'var_host == ansible_host'
8
9 - name: Test that we can give a list of values to var and receive a list of values back
10 set_fact:
11 var_host_info: '{{ query("vars", "ansible_host", "ansible_connection") }}'
12
13 - assert:
14 that:
15 - 'var_host_info[0] == ansible_host'
16 - 'var_host_info[1] == ansible_connection'
17
18 - block:
19 - name: EXPECTED FAILURE - test invalid var
20 raw: '{{ lookup("vars", "doesnotexist") }}'
21
22 - fail:
23 msg: "should not get here"
24
25 rescue:
26 - assert:
27 that:
28 - ansible_failed_task.name == "EXPECTED FAILURE - test invalid var"
29 - expected in ansible_failed_result.msg
30 vars:
31 expected: "No variable named 'doesnotexist' was found"
32
33 - block:
34 - name: EXPECTED FAILURE - test invalid var type
35 debug:
36 var: '{{ lookup("vars", 42) }}'
37
38 - fail:
39 msg: "should not get here"
40
41 rescue:
42 - assert:
43 that:
44 - ansible_failed_task.name == "EXPECTED FAILURE - test invalid var type"
45 - expected in ansible_failed_result.msg
46 vars:
47 expected: "Variable name must be 'str' not 'int'"
48
49 - name: test default
50 set_fact:
51 expected_default_var: '{{ lookup("vars", "doesnotexist", default="some text") }}'
52
53 - assert:
54 that:
55 - expected_default_var == "some text"