Debian Codegraph @

test/integration/targets/user/tasks/test_local_expires.yml

raw
1 ---
2 ## local user expires
3 # Date is March 3, 2050
4
5 - name: Remove local_ansibulluser
6 user:
7 name: local_ansibulluser
8 state: absent
9 remove: yes
10 local: yes
11 tags:
12 - user_test_local_mode
13
14 - name: Set user expiration
15 user:
16 name: local_ansibulluser
17 state: present
18 local: yes
19 expires: 2529881062
20 register: user_test_local_expires1
21 tags:
22 - user_test_local_mode
23
24 - name: Set user expiration again to ensure no change is made
25 user:
26 name: local_ansibulluser
27 state: present
28 local: yes
29 expires: 2529881062
30 register: user_test_local_expires2
31 tags:
32 - user_test_local_mode
33
34 - name: Ensure that account with expiration was created and did not change on subsequent run
35 assert:
36 that:
37 - user_test_local_expires1 is changed
38 - user_test_local_expires2 is not changed
39 tags:
40 - user_test_local_mode
41
42 - name: Verify expiration date for Linux
43 block:
44 - name: LINUX | Get expiration date for local_ansibulluser
45 getent:
46 database: shadow
47 key: local_ansibulluser
48 tags:
49 - user_test_local_mode
50
51 - name: LINUX | Ensure proper expiration date was set
52 assert:
53 that:
54 - getent_shadow['local_ansibulluser'][6] == '29281'
55 tags:
56 - user_test_local_mode
57 when: ansible_facts.os_family in ['RedHat', 'Debian']
58
59 - name: Unexpire user
60 user:
61 name: local_ansibulluser
62 state: present
63 local: yes
64 expires: -1
65 register: user_test_local_expires3
66 tags:
67 - user_test_local_mode
68
69 - name: Verify un expiration date for Linux
70 block:
71 - name: LINUX | Get expiration date for local_ansibulluser
72 getent:
73 database: shadow
74 key: local_ansibulluser
75 tags:
76 - user_test_local_mode
77
78 - name: LINUX | Ensure proper expiration date was set
79 assert:
80 msg: "expiry is supposed to be empty or -1, not {{ getent_shadow['local_ansibulluser'][6] }}"
81 that:
82 - not getent_shadow['local_ansibulluser'][6] or getent_shadow['local_ansibulluser'][6] | int < 0
83 tags:
84 - user_test_local_mode
85 when: ansible_facts.os_family in ['RedHat', 'Debian']
86
87 - name: Verify un expiration date for Linux/BSD
88 block:
89 - name: Unexpire user again to check for change
90 user:
91 name: local_ansibulluser
92 state: present
93 local: yes
94 expires: -1
95 register: user_test_local_expires4
96 tags:
97 - user_test_local_mode
98
99 - name: Ensure first expiration reported a change and second did not
100 assert:
101 msg: The second run of the expiration removal task reported a change when it should not
102 that:
103 - user_test_local_expires3 is changed
104 - user_test_local_expires4 is not changed
105 tags:
106 - user_test_local_mode
107 when: ansible_facts.os_family in ['RedHat', 'Debian', 'FreeBSD']
108
109 # Test setting no expiration when creating a new account
110 # https://github.com/ansible/ansible/issues/44155
111 - name: Remove local_ansibulluser
112 user:
113 name: local_ansibulluser
114 state: absent
115 remove: yes
116 local: yes
117 tags:
118 - user_test_local_mode
119
120 - name: Create user account without expiration
121 user:
122 name: local_ansibulluser
123 state: present
124 local: yes
125 expires: -1
126 register: user_test_local_create_no_expires_1
127 tags:
128 - user_test_local_mode
129
130 - name: Create user account without expiration again
131 user:
132 name: local_ansibulluser
133 state: present
134 local: yes
135 expires: -1
136 register: user_test_local_create_no_expires_2
137 tags:
138 - user_test_local_mode
139
140 - name: Ensure changes were made appropriately
141 assert:
142 msg: Setting 'expires='-1 resulted in incorrect changes
143 that:
144 - user_test_local_create_no_expires_1 is changed
145 - user_test_local_create_no_expires_2 is not changed
146 tags:
147 - user_test_local_mode
148
149 - name: Verify un expiration date for Linux
150 block:
151 - name: LINUX | Get expiration date for local_ansibulluser
152 getent:
153 database: shadow
154 key: local_ansibulluser
155 tags:
156 - user_test_local_mode
157
158 - name: LINUX | Ensure proper expiration date was set
159 assert:
160 msg: "expiry is supposed to be empty or -1, not {{ getent_shadow['local_ansibulluser'][6] }}"
161 that:
162 - not getent_shadow['local_ansibulluser'][6] or getent_shadow['local_ansibulluser'][6] | int < 0
163 tags:
164 - user_test_local_mode
165 when: ansible_facts.os_family in ['RedHat', 'Debian']
166
167 # Test setting epoch 0 expiration when creating a new account, then removing the expiry
168 # https://github.com/ansible/ansible/issues/47114
169 - name: Remove local_ansibulluser
170 user:
171 name: local_ansibulluser
172 state: absent
173 remove: yes
174 local: yes
175 tags:
176 - user_test_local_mode
177
178 - name: Create user account with epoch 0 expiration
179 user:
180 name: local_ansibulluser
181 state: present
182 local: yes
183 expires: 0
184 register: user_test_local_expires_create0_1
185 tags:
186 - user_test_local_mode
187
188 - name: Create user account with epoch 0 expiration again
189 user:
190 name: local_ansibulluser
191 state: present
192 local: yes
193 expires: 0
194 register: user_test_local_expires_create0_2
195 tags:
196 - user_test_local_mode
197
198 - name: Change the user account to remove the expiry time
199 user:
200 name: local_ansibulluser
201 expires: -1
202 local: yes
203 register: user_test_local_remove_expires_1
204 tags:
205 - user_test_local_mode
206
207 - name: Change the user account to remove the expiry time again
208 user:
209 name: local_ansibulluser
210 expires: -1
211 local: yes
212 register: user_test_local_remove_expires_2
213 tags:
214 - user_test_local_mode
215
216
217 - name: Verify un expiration date for Linux
218 block:
219 - name: LINUX | Ensure changes were made appropriately
220 assert:
221 msg: Creating an account with 'expries=0' then removing that expriation with 'expires=-1' resulted in incorrect changes
222 that:
223 - user_test_local_expires_create0_1 is changed
224 - user_test_local_expires_create0_2 is not changed
225 - user_test_local_remove_expires_1 is changed
226 - user_test_local_remove_expires_2 is not changed
227 tags:
228 - user_test_local_mode
229
230 - name: LINUX | Get expiration date for local_ansibulluser
231 getent:
232 database: shadow
233 key: local_ansibulluser
234 tags:
235 - user_test_local_mode
236
237 - name: LINUX | Ensure proper expiration date was set
238 assert:
239 msg: "expiry is supposed to be empty or -1, not {{ getent_shadow['local_ansibulluser'][6] }}"
240 that:
241 - not getent_shadow['local_ansibulluser'][6] or getent_shadow['local_ansibulluser'][6] | int < 0
242 tags:
243 - user_test_local_mode
244 when: ansible_facts.os_family in ['RedHat', 'Debian']
245
246 # Test expiration with a very large negative number. This should have the same
247 # result as setting -1.
248 - name: Set expiration date using very long negative number
249 user:
250 name: local_ansibulluser
251 state: present
252 local: yes
253 expires: -2529881062
254 register: user_test_local_expires5
255 tags:
256 - user_test_local_mode
257
258 - name: Ensure no change was made
259 assert:
260 that:
261 - user_test_local_expires5 is not changed
262 tags:
263 - user_test_local_mode
264
265 - name: Verify un expiration date for Linux
266 block:
267 - name: LINUX | Get expiration date for local_ansibulluser
268 getent:
269 database: shadow
270 key: local_ansibulluser
271 tags:
272 - user_test_local_mode
273
274 - name: LINUX | Ensure proper expiration date was set
275 assert:
276 msg: "expiry is supposed to be empty or -1, not {{ getent_shadow['local_ansibulluser'][6] }}"
277 that:
278 - not getent_shadow['local_ansibulluser'][6] or getent_shadow['local_ansibulluser'][6] | int < 0
279 tags:
280 - user_test_local_mode
281 when: ansible_facts.os_family in ['RedHat', 'Debian']