blob: 43f9c74eb67f36a392a8d7e1e1c55bb5dde63315 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
|
- hosts: testhost
gather_facts: no
tasks:
- name: get PATH from target
command: echo $PATH
register: target_path
- hosts: testhost
vars:
- test1:
key1: val1
environment:
PATH: '{{ansible_env.PATH + ":/lola"}}'
lola: 'ido'
tasks:
- name: ensure special case with ansible_env is skipped but others still work
assert:
that:
- target_path.stdout == ansible_env.PATH
- "'/lola' not in ansible_env.PATH"
- ansible_env.lola == 'ido'
- name: check that envvar does not exist
shell: echo $key1
register: test_env
- name: assert no val in stdout
assert:
that:
- '"val1" not in test_env.stdout_lines'
- name: check that envvar does exist
shell: echo $key1
environment: "{{test1}}"
register: test_env2
- name: assert val1 in stdout
assert:
that:
- '"val1" in test_env2.stdout_lines'
- hosts: testhost
vars:
- test1:
key1: val1
- test2:
key1: not1
other1: val2
environment: "{{test1}}"
tasks:
- name: check that play envvar does exist
shell: echo $key1
register: test_env3
- name: assert val1 in stdout
assert:
that:
- '"val1" in test_env3.stdout_lines'
- name: check that task envvar does exist
shell: echo $key1; echo $other1
register: test_env4
environment: "{{test2}}"
- name: assert all vars appear as expected
assert:
that:
- '"val1" not in test_env4.stdout_lines'
- '"not1" in test_env4.stdout_lines'
- '"val2" in test_env4.stdout_lines'
- block:
- name: check that task envvar does exist in block
shell: echo $key1; echo $other1
register: test_env5
- name: assert all vars appear as expected in block
assert:
that:
- '"val1" not in test_env5.stdout_lines'
- '"not1" in test_env5.stdout_lines'
- '"val2" in test_env5.stdout_lines'
environment: "{{test2}}"
- name: test setting environment while using loops
hosts: testhost
environment:
foo: outer
tasks:
- name: verify foo==outer
command: /bin/echo $foo
loop:
- 1
register: test_foo
- name: assert foo==outer
assert:
that:
- "{{ test_foo.results[0].stdout == 'outer' }}"
- name: set environment on a task
environment:
foo: in_task
command: /bin/echo $foo
loop:
- 1
register: test_foo
- name: assert foo==in_task
assert:
that:
- "test_foo.results[0].stdout == 'in_task'"
- name: test that the outer env var is set appropriately still
command: /bin/echo $foo
loop:
- 1
register: test_foo
- name: assert foo==outer
assert:
that:
- "{{ test_foo.results[0].stdout == 'outer' }}"
- name: set environment on a block
environment:
foo: in_block
block:
- name: test the environment is set in the block
command: /bin/echo $foo
loop:
- 1
register: test_foo
- name: assert foo==in_block
assert:
that:
- "test_foo.results[0].stdout == 'in_block'"
- name: test setting environment in a task inside a block
environment:
foo: in_block_in_task
command: /bin/echo $foo
loop:
- 1
register: test_foo
- name: assert foo==in_block_in_task
assert:
that:
- "test_foo.results[0].stdout == 'in_block_in_task'"
- name: test the environment var is set to the parent value
command: /bin/echo $foo
loop:
- 1
register: test_foo
- name: assert foo==in_block
assert:
that:
- "test_foo.results[0].stdout == 'in_block'"
- name: test the env var foo has the initial value
command: /bin/echo $foo
loop:
- 1
register: test_foo
- name: assert foo==outer
assert:
that:
- "{{ test_foo.results[0].stdout == 'outer' }}"
|