Debian Codegraph @

test/integration/targets/lookup_ini/test_lookup_properties.yml

raw
1 - name: Lookup test
2 hosts: testhost
3
4 tasks:
5 - name: "read properties value"
6 set_fact:
7 test1: "{{lookup('ini', 'value1 type=properties file=lookup.properties')}}"
8 test2: "{{lookup('ini', 'value2', type='properties', file='lookup.properties')}}"
9 test_dot: "{{lookup('ini', 'value.dot', type='properties', file='lookup.properties')}}"
10 field_with_space: "{{lookup('ini', 'field.with.space type=properties file=lookup.properties')}}"
11
12 - assert:
13 that: "item is defined"
14 with_items: [ 'test1', 'test2', 'test_dot', 'field_with_space' ]
15
16 - name: "read ini value"
17 set_fact:
18 value1_global: "{{lookup('ini', 'value1', section='global', file='lookup.ini')}}"
19 value2_global: "{{lookup('ini', 'value2', section='global', file='lookup.ini')}}"
20 value1_section1: "{{lookup('ini', 'value1', section='section1', file='lookup.ini')}}"
21 field_with_unicode: "{{lookup('ini', 'unicode', section='global', file='lookup.ini')}}"
22
23 - debug: var={{item}}
24 with_items: [ 'value1_global', 'value2_global', 'value1_section1', 'field_with_unicode' ]
25
26 - assert:
27 that:
28 - "field_with_unicode == 'été indien où à château français ïîôû'"
29
30 - name: "read ini value from iso8859-15 file"
31 set_fact:
32 field_with_unicode: "{{lookup('ini', 'field_with_unicode section=global encoding=iso8859-1 file=lookup-8859-15.ini')}}"
33
34 - assert:
35 that:
36 - "field_with_unicode == 'été indien où à château français ïîôû'"
37
38 - name: "read ini value with section and regexp"
39 set_fact:
40 value_section: "{{lookup('ini', 'value[1-2] section=value_section file=lookup.ini re=true')}}"
41 other_section: "{{lookup('ini', 'other[1-2] section=other_section file=lookup.ini re=true')}}"
42
43 - debug: var={{item}}
44 with_items: [ 'value_section', 'other_section' ]
45
46 - assert:
47 that:
48 - "value_section == '1,2'"
49 - "other_section == '4,5'"
50
51 - name: "Reading unknown value"
52 set_fact:
53 unknown: "{{lookup('ini', 'unknown default=unknown section=section1 file=lookup.ini')}}"
54
55 - debug: var=unknown
56
57 - assert:
58 that:
59 - 'unknown == "unknown"'
60
61 - name: "Looping over section section1"
62 debug: msg="{{item}}"
63 with_ini: value[1-2] section=section1 file=lookup.ini re=true
64 register: _
65
66 - assert:
67 that:
68 - '_.results.0.item == "section1/value1"'
69 - '_.results.1.item == "section1/value2"'
70
71 - name: "Looping over section value_section"
72 debug: msg="{{item}}"
73 with_ini: value[1-2] section=value_section file=lookup.ini re=true
74 register: _
75
76 - assert:
77 that:
78 - '_.results.0.item == "1"'
79 - '_.results.1.item == "2"'
80
81 - debug: msg="{{item}}"
82 with_ini: value[1-2] section=section1 file=lookup.ini re=true
83 register: _
84
85 - assert:
86 that:
87 - '_.results.0.item == "section1/value1"'
88 - '_.results.1.item == "section1/value2"'