Debian Codegraph @

test/integration/targets/lookup_env/vars_not_set.yml

raw
1 - hosts: testhost
2 gather_facts: no
3 tasks:
4 - name: look up an environment variable which is not set with various default behaviors
5 ansible._protomatter.debug:
6 expression:
7 - lookup('env', 'USR') == '' # expect '' (the default fallback value)
8 - lookup('env', 'USR', default='nobody') == 'nobody' # expect 'nobody'
9 - lookup('env', 'USR', default=undef()) # expect a hint-ed undefined from the env lookup
10 - lookup('env', 'USR', default=undef('custom')) # expect an undefined whose hint is 'custom'
11 - lookup('env', 'USR', default=bogus_var) # expect an undefined hinting at bogus_var
12 register: result
13
14 - name: verify the lookups returned the expected results
15 assert:
16 that:
17 - result.expression_result[0:2] == [true, true]
18 - result.expression_result[2] is search("environment variable 'USR' is not set")
19 - result.expression_result[3] is search("custom")
20 - result.expression_result[4] is search("'bogus_var' is undefined")
21 - result.warnings | select("search", "'USR' is not set") | length == 1
22 - result.warnings | select("search", "custom") | length == 1
23 - result.warnings | select("search", "'bogus_var' is undefined") | length == 1