Debian Codegraph @

ansible_collections/community/general/tests/integration/targets/ssh_config/tasks/options.yml

raw
1 ---
2 # Copyright (c) Ansible Project
3 # GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
4 # SPDX-License-Identifier: GPL-3.0-or-later
5
6 # Reset ssh_config before testing options
7 - name: Copy sample config file
8 copy:
9 src: 'files/ssh_config_test'
10 dest: '{{ ssh_config_test }}'
11
12 - name: Options - Add in check mode
13 community.general.ssh_config:
14 ssh_config_file: "{{ ssh_config_test }}"
15 host: "options.example.com"
16 proxycommand: "ssh jumphost.example.com -W %h:%p"
17 forward_agent: true
18 add_keys_to_agent: true
19 host_key_algorithms: "+ssh-rsa"
20 identities_only: true
21 controlmaster: "auto"
22 controlpath: "~/.ssh/sockets/%r@%h-%p"
23 controlpersist: "yes"
24 dynamicforward: '10080'
25 other_options:
26 serveraliveinterval: '30'
27 address_family: "inet"
28 state: present
29 register: options_add
30 check_mode: true
31
32 - name: Options - Check if changes are made in check mode
33 assert:
34 that:
35 - options_add.changed
36 - "'options.example.com' in options_add.hosts_added"
37 - options_add.hosts_changed is defined
38 - options_add.hosts_removed is defined
39
40 - name: "Options - Get content of {{ ssh_config_test }}"
41 slurp:
42 src: "{{ ssh_config_test }}"
43 register: slurp_ssh_config
44
45 - name: "Options - Verify that nothing was added to {{ ssh_config_test }} during change mode"
46 assert:
47 that:
48 - "'options.example.com' not in slurp_ssh_config['content'] | b64decode"
49
50 - name: Options - Add a host
51 community.general.ssh_config:
52 ssh_config_file: "{{ ssh_config_test }}"
53 host: "options.example.com"
54 proxycommand: "ssh jumphost.example.com -W %h:%p"
55 forward_agent: true
56 add_keys_to_agent: true
57 host_key_algorithms: "+ssh-rsa"
58 identities_only: true
59 controlmaster: "auto"
60 controlpath: "~/.ssh/sockets/%r@%h-%p"
61 controlpersist: "yes"
62 dynamicforward: '10080'
63 other_options:
64 serveraliveinterval: '30'
65 address_family: "inet"
66 state: present
67 register: options_add
68
69 - name: Options - Check if changes are made
70 assert:
71 that:
72 - options_add.changed
73 - "'options.example.com' in options_add.hosts_added"
74 - options_add.hosts_changed is defined
75 - options_add.hosts_removed is defined
76
77 - name: Options - Add same host again for idempotency
78 community.general.ssh_config:
79 ssh_config_file: "{{ ssh_config_test }}"
80 host: "options.example.com"
81 proxycommand: "ssh jumphost.example.com -W %h:%p"
82 forward_agent: true
83 add_keys_to_agent: true
84 host_key_algorithms: "+ssh-rsa"
85 identities_only: true
86 controlmaster: "auto"
87 controlpath: "~/.ssh/sockets/%r@%h-%p"
88 controlpersist: "yes"
89 dynamicforward: '10080'
90 other_options:
91 serveraliveinterval: '30'
92 address_family: "inet"
93 state: present
94 register: options_add_again
95
96 - name: Options - Check for idempotency
97 assert:
98 that:
99 - not options_add_again.changed
100 - options_add.hosts_changed is defined
101 - options_add.hosts_removed is defined
102 - options_add.hosts_added is defined
103
104 - name: "Options - Get content of {{ ssh_config_test }}"
105 slurp:
106 src: "{{ ssh_config_test }}"
107 register: slurp_ssh_config
108
109 - name: "Verify that {{ ssh_config_test }} contains added options"
110 assert:
111 that:
112 - "'proxycommand ssh jumphost.example.com -W %h:%p' in slurp_ssh_config['content'] | b64decode"
113 - "'forwardagent yes' in slurp_ssh_config['content'] | b64decode"
114 - "'addkeystoagent yes' in slurp_ssh_config['content'] | b64decode"
115 - "'hostkeyalgorithms +ssh-rsa' in slurp_ssh_config['content'] | b64decode"
116 - "'identitiesonly yes' in slurp_ssh_config['content'] | b64decode"
117 - "'controlmaster auto' in slurp_ssh_config['content'] | b64decode"
118 - "'controlpath ~/.ssh/sockets/%r@%h-%p' in slurp_ssh_config['content'] | b64decode"
119 - "'controlpersist yes' in slurp_ssh_config['content'] | b64decode"
120 - "'dynamicforward 10080' in slurp_ssh_config['content'] | b64decode"
121 - "'serveraliveinterval 30' in slurp_ssh_config['content'] | b64decode"
122 - "'addressfamily inet' in slurp_ssh_config['content'] | b64decode"
123
124 - name: Options - Update host
125 community.general.ssh_config:
126 ssh_config_file: "{{ ssh_config_test }}"
127 host: "options.example.com"
128 proxycommand: "ssh new-jumphost.example.com -W %h:%p"
129 forward_agent: false
130 add_keys_to_agent: false
131 host_key_algorithms: "+ssh-ed25519"
132 identities_only: false
133 controlmaster: "no"
134 controlpath: "~/.ssh/new-sockets/%r@%h-%p"
135 controlpersist: "600"
136 dynamicforward: '11080'
137 other_options:
138 serveraliveinterval: '30'
139 address_family: "inet6"
140 state: present
141 register: options_update
142
143 - name: Options - Check for update operation
144 assert:
145 that:
146 - options_update.changed
147 - options_update.hosts_changed is defined
148 - "'options.example.com' in options_update.hosts_changed"
149 - options_update.hosts_removed is defined
150 - options_update.hosts_added is defined
151 - options_update.hosts_change_diff is defined
152
153 - name: Options - Update host again
154 community.general.ssh_config:
155 ssh_config_file: "{{ ssh_config_test }}"
156 host: "options.example.com"
157 proxycommand: "ssh new-jumphost.example.com -W %h:%p"
158 forward_agent: false
159 add_keys_to_agent: false
160 host_key_algorithms: "+ssh-ed25519"
161 identities_only: false
162 controlmaster: "no"
163 controlpath: "~/.ssh/new-sockets/%r@%h-%p"
164 controlpersist: "600"
165 dynamicforward: '11080'
166 other_options:
167 serveraliveinterval: '30'
168 address_family: "inet6"
169 state: present
170 register: options_update
171
172 - name: Options - Check update operation for idempotency
173 assert:
174 that:
175 - not options_update.changed
176 - options_update.hosts_changed is defined
177 - options_update.hosts_removed is defined
178 - options_update.hosts_added is defined
179 - options_update.hosts_change_diff is defined
180
181 - name: "Options - Get content of {{ ssh_config_test }}"
182 slurp:
183 src: "{{ ssh_config_test }}"
184 register: slurp_ssh_config
185
186 - name: "Verify that {{ ssh_config_test }} contains changed options"
187 assert:
188 that:
189 - "'proxycommand ssh new-jumphost.example.com -W %h:%p' in slurp_ssh_config['content'] | b64decode"
190 - "'forwardagent no' in slurp_ssh_config['content'] | b64decode"
191 - "'addkeystoagent no' in slurp_ssh_config['content'] | b64decode"
192 - "'hostkeyalgorithms +ssh-ed25519' in slurp_ssh_config['content'] | b64decode"
193 - "'identitiesonly no' in slurp_ssh_config['content'] | b64decode"
194 - "'controlmaster no' in slurp_ssh_config['content'] | b64decode"
195 - "'controlpath ~/.ssh/new-sockets/%r@%h-%p' in slurp_ssh_config['content'] | b64decode"
196 - "'controlpersist 600' in slurp_ssh_config['content'] | b64decode"
197 - "'dynamicforward 11080' in slurp_ssh_config['content'] | b64decode"
198 - "'serveraliveinterval 30' in slurp_ssh_config['content'] | b64decode"
199 - "'addressfamily inet6' in slurp_ssh_config['content'] | b64decode"
200
201 - name: Options - Ensure no update in case option exist in ssh_config file but wasn't defined in playbook
202 community.general.ssh_config:
203 ssh_config_file: "{{ ssh_config_test }}"
204 host: "options.example.com"
205 state: present
206 register: options_no_update
207
208 - name: Options - Check that no update took place
209 assert:
210 that:
211 - not options_update.changed
212 - options_update.hosts_changed is defined
213 - options_update.hosts_removed is defined
214 - options_update.hosts_added is defined
215 - options_update.hosts_change_diff is defined
216
217 - name: "Options - Get content of {{ ssh_config_test }}"
218 slurp:
219 src: "{{ ssh_config_test }}"
220 register: slurp_ssh_config
221
222 - name: "Verify that {{ ssh_config_test }} wasn't changed"
223 assert:
224 that:
225 - "'proxycommand ssh new-jumphost.example.com -W %h:%p' in slurp_ssh_config['content'] | b64decode"
226 - "'forwardagent no' in slurp_ssh_config['content'] | b64decode"
227 - "'addkeystoagent no' in slurp_ssh_config['content'] | b64decode"
228 - "'hostkeyalgorithms +ssh-ed25519' in slurp_ssh_config['content'] | b64decode"
229 - "'identitiesonly no' in slurp_ssh_config['content'] | b64decode"
230 - "'controlmaster no' in slurp_ssh_config['content'] | b64decode"
231 - "'controlpath ~/.ssh/new-sockets/%r@%h-%p' in slurp_ssh_config['content'] | b64decode"
232 - "'controlpersist 600' in slurp_ssh_config['content'] | b64decode"
233 - "'dynamicforward 11080' in slurp_ssh_config['content'] | b64decode"
234 - "'serveraliveinterval 30' in slurp_ssh_config['content'] | b64decode"
235 - "'addressfamily inet6' in slurp_ssh_config['content'] | b64decode"
236
237 - name: Debug
238 debug:
239 msg: "{{ slurp_ssh_config['content'] | b64decode }}"
240
241 - name: Options - Delete a host
242 community.general.ssh_config:
243 ssh_config_file: "{{ ssh_config_test }}"
244 host: "options.example.com"
245 state: absent
246 register: options_delete
247
248 - name: Options - Check if host was removed
249 assert:
250 that:
251 - options_delete.changed
252 - "'options.example.com' in options_delete.hosts_removed"
253 - options_delete.hosts_changed is defined
254 - options_delete.hosts_added is defined
255
256 - name: Options - Delete same host again for idempotency
257 community.general.ssh_config:
258 ssh_config_file: "{{ ssh_config_test }}"
259 host: "options.example.com"
260 state: absent
261 register: options_delete_again
262
263 - name: Options - Check delete operation for idempotency
264 assert:
265 that:
266 - not options_delete_again.changed
267 - options_delete_again.hosts_changed is defined
268 - options_delete_again.hosts_removed is defined
269 - options_delete_again.hosts_added is defined
270
271 - name: "Options - Get content of {{ ssh_config_test }}"
272 slurp:
273 src: "{{ ssh_config_test }}"
274 register: slurp_ssh_config
275
276 - name: "Verify that {{ ssh_config_test }} does not contains deleted options"
277 assert:
278 that:
279 - "'proxycommand ssh new-jumphost.example.com -W %h:%p' not in slurp_ssh_config['content'] | b64decode"
280 - "'forwardagent no' not in slurp_ssh_config['content'] | b64decode"
281 - "'addkeystoagent no' not in slurp_ssh_config['content'] | b64decode"
282 - "'hostkeyalgorithms +ssh-ed25519' not in slurp_ssh_config['content'] | b64decode"
283 - "'identitiesonly no' not in slurp_ssh_config['content'] | b64decode"
284 - "'controlmaster auto' not in slurp_ssh_config['content'] | b64decode"
285 - "'controlpath ~/.ssh/sockets/%r@%h-%p' not in slurp_ssh_config['content'] | b64decode"
286 - "'controlpersist yes' not in slurp_ssh_config['content'] | b64decode"
287 - "'dynamicforward 10080' not in slurp_ssh_config['content'] | b64decode"
288 - "'serveraliveinterval 30' not in slurp_ssh_config['content'] | b64decode"
289 - "'addressfamily inet' not in slurp_ssh_config['content'] | b64decode"
290
291 # Proxycommand and ProxyJump are mutually exclusive.
292 # Reset ssh_config before testing options with proxyjump
293
294 - name: Copy sample config file
295 copy:
296 src: 'files/ssh_config_test'
297 dest: '{{ ssh_config_test }}'
298
299 - name: Options - Add in check mode
300 community.general.ssh_config:
301 ssh_config_file: "{{ ssh_config_test }}"
302 host: "options.example.com"
303 proxyjump: "jumphost.example.com"
304 forward_agent: true
305 add_keys_to_agent: true
306 host_key_algorithms: "+ssh-rsa"
307 identities_only: true
308 controlmaster: "auto"
309 controlpath: "~/.ssh/sockets/%r@%h-%p"
310 controlpersist: "yes"
311 dynamicforward: '10080'
312 other_options:
313 serveraliveinterval: '30'
314 address_family: "inet"
315 state: present
316 register: options_add
317 check_mode: true
318
319 - name: Options - Check if changes are made in check mode
320 assert:
321 that:
322 - options_add.changed
323 - "'options.example.com' in options_add.hosts_added"
324 - options_add.hosts_changed is defined
325 - options_add.hosts_removed is defined
326
327 - name: "Options - Get content of {{ ssh_config_test }}"
328 slurp:
329 src: "{{ ssh_config_test }}"
330 register: slurp_ssh_config
331
332 - name: "Options - Verify that nothing was added to {{ ssh_config_test }} during change mode"
333 assert:
334 that:
335 - "'options.example.com' not in slurp_ssh_config['content'] | b64decode"
336
337 - name: Options - Add a host
338 community.general.ssh_config:
339 ssh_config_file: "{{ ssh_config_test }}"
340 host: "options.example.com"
341 proxyjump: "jumphost.example.com"
342 forward_agent: true
343 add_keys_to_agent: true
344 host_key_algorithms: "+ssh-rsa"
345 identities_only: true
346 controlmaster: "auto"
347 controlpath: "~/.ssh/sockets/%r@%h-%p"
348 controlpersist: "yes"
349 dynamicforward: '10080'
350 other_options:
351 serveraliveinterval: '30'
352 address_family: "inet"
353 state: present
354 register: options_add
355
356 - name: Options - Check if changes are made
357 assert:
358 that:
359 - options_add.changed
360 - "'options.example.com' in options_add.hosts_added"
361 - options_add.hosts_changed is defined
362 - options_add.hosts_removed is defined
363
364 - name: Options - Add same host again for idempotency
365 community.general.ssh_config:
366 ssh_config_file: "{{ ssh_config_test }}"
367 host: "options.example.com"
368 proxyjump: "jumphost.example.com"
369 forward_agent: true
370 add_keys_to_agent: true
371 host_key_algorithms: "+ssh-rsa"
372 identities_only: true
373 controlmaster: "auto"
374 controlpath: "~/.ssh/sockets/%r@%h-%p"
375 controlpersist: "yes"
376 dynamicforward: '10080'
377 other_options:
378 serveraliveinterval: '30'
379 address_family: "inet"
380 state: present
381 register: options_add_again
382
383 - name: Options - Check for idempotency
384 assert:
385 that:
386 - not options_add_again.changed
387 - options_add.hosts_changed is defined
388 - options_add.hosts_removed is defined
389 - options_add.hosts_added is defined
390
391 - name: "Options - Get content of {{ ssh_config_test }}"
392 slurp:
393 src: "{{ ssh_config_test }}"
394 register: slurp_ssh_config
395
396 - name: "Verify that {{ ssh_config_test }} contains added options"
397 assert:
398 that:
399 - "'proxyjump jumphost.example.com' in slurp_ssh_config['content'] | b64decode"
400 - "'forwardagent yes' in slurp_ssh_config['content'] | b64decode"
401 - "'addkeystoagent yes' in slurp_ssh_config['content'] | b64decode"
402 - "'hostkeyalgorithms +ssh-rsa' in slurp_ssh_config['content'] | b64decode"
403 - "'identitiesonly yes' in slurp_ssh_config['content'] | b64decode"
404 - "'controlmaster auto' in slurp_ssh_config['content'] | b64decode"
405 - "'controlpath ~/.ssh/sockets/%r@%h-%p' in slurp_ssh_config['content'] | b64decode"
406 - "'controlpersist yes' in slurp_ssh_config['content'] | b64decode"
407 - "'dynamicforward 10080' in slurp_ssh_config['content'] | b64decode"
408 - "'serveraliveinterval 30' in slurp_ssh_config['content'] | b64decode"
409 - "'addressfamily inet' in slurp_ssh_config['content'] | b64decode"
410
411 - name: Options - Update host
412 community.general.ssh_config:
413 ssh_config_file: "{{ ssh_config_test }}"
414 host: "options.example.com"
415 proxyjump: "new-jumphost.example.com"
416 forward_agent: false
417 add_keys_to_agent: false
418 host_key_algorithms: "+ssh-ed25519"
419 identities_only: false
420 controlmaster: "no"
421 controlpath: "~/.ssh/new-sockets/%r@%h-%p"
422 controlpersist: "600"
423 dynamicforward: '11080'
424 other_options:
425 serveraliveinterval: '30'
426 address_family: "inet6"
427 state: present
428 register: options_update
429
430 - name: Options - Check for update operation
431 assert:
432 that:
433 - options_update.changed
434 - options_update.hosts_changed is defined
435 - "'options.example.com' in options_update.hosts_changed"
436 - options_update.hosts_removed is defined
437 - options_update.hosts_added is defined
438 - options_update.hosts_change_diff is defined
439
440 - name: Options - Update host again
441 community.general.ssh_config:
442 ssh_config_file: "{{ ssh_config_test }}"
443 host: "options.example.com"
444 proxyjump: "new-jumphost.example.com"
445 forward_agent: false
446 add_keys_to_agent: false
447 host_key_algorithms: "+ssh-ed25519"
448 identities_only: false
449 controlmaster: "no"
450 controlpath: "~/.ssh/new-sockets/%r@%h-%p"
451 controlpersist: "600"
452 dynamicforward: '11080'
453 other_options:
454 serveraliveinterval: '30'
455 address_family: "inet6"
456 state: present
457 register: options_update
458
459 - name: Options - Check update operation for idempotency
460 assert:
461 that:
462 - not options_update.changed
463 - options_update.hosts_changed is defined
464 - options_update.hosts_removed is defined
465 - options_update.hosts_added is defined
466 - options_update.hosts_change_diff is defined
467
468 - name: "Options - Get content of {{ ssh_config_test }}"
469 slurp:
470 src: "{{ ssh_config_test }}"
471 register: slurp_ssh_config
472
473 - name: "Verify that {{ ssh_config_test }} contains changed options"
474 assert:
475 that:
476 - "'proxyjump new-jumphost.example.com' in slurp_ssh_config['content'] | b64decode"
477 - "'forwardagent no' in slurp_ssh_config['content'] | b64decode"
478 - "'addkeystoagent no' in slurp_ssh_config['content'] | b64decode"
479 - "'hostkeyalgorithms +ssh-ed25519' in slurp_ssh_config['content'] | b64decode"
480 - "'identitiesonly no' in slurp_ssh_config['content'] | b64decode"
481 - "'controlmaster no' in slurp_ssh_config['content'] | b64decode"
482 - "'controlpath ~/.ssh/new-sockets/%r@%h-%p' in slurp_ssh_config['content'] | b64decode"
483 - "'controlpersist 600' in slurp_ssh_config['content'] | b64decode"
484 - "'dynamicforward 11080' in slurp_ssh_config['content'] | b64decode"
485 - "'serveraliveinterval 30' in slurp_ssh_config['content'] | b64decode"
486 - "'addressfamily inet6' in slurp_ssh_config['content'] | b64decode"
487
488 - name: Options - Ensure no update in case option exist in ssh_config file but wasn't defined in playbook
489 community.general.ssh_config:
490 ssh_config_file: "{{ ssh_config_test }}"
491 host: "options.example.com"
492 state: present
493 register: options_no_update
494
495 - name: Options - Check that no update took place
496 assert:
497 that:
498 - not options_update.changed
499 - options_update.hosts_changed is defined
500 - options_update.hosts_removed is defined
501 - options_update.hosts_added is defined
502 - options_update.hosts_change_diff is defined
503
504 - name: "Options - Get content of {{ ssh_config_test }}"
505 slurp:
506 src: "{{ ssh_config_test }}"
507 register: slurp_ssh_config
508
509 - name: "Verify that {{ ssh_config_test }} wasn't changed"
510 assert:
511 that:
512 - "'proxyjump new-jumphost.example.com' in slurp_ssh_config['content'] | b64decode"
513 - "'forwardagent no' in slurp_ssh_config['content'] | b64decode"
514 - "'addkeystoagent no' in slurp_ssh_config['content'] | b64decode"
515 - "'hostkeyalgorithms +ssh-ed25519' in slurp_ssh_config['content'] | b64decode"
516 - "'identitiesonly no' in slurp_ssh_config['content'] | b64decode"
517 - "'controlmaster no' in slurp_ssh_config['content'] | b64decode"
518 - "'controlpath ~/.ssh/new-sockets/%r@%h-%p' in slurp_ssh_config['content'] | b64decode"
519 - "'controlpersist 600' in slurp_ssh_config['content'] | b64decode"
520 - "'dynamicforward 11080' in slurp_ssh_config['content'] | b64decode"
521 - "'serveraliveinterval 30' in slurp_ssh_config['content'] | b64decode"
522 - "'addressfamily inet6' in slurp_ssh_config['content'] | b64decode"
523
524 - name: Debug
525 debug:
526 msg: "{{ slurp_ssh_config['content'] | b64decode }}"
527
528 - name: Options - Delete a host
529 community.general.ssh_config:
530 ssh_config_file: "{{ ssh_config_test }}"
531 host: "options.example.com"
532 state: absent
533 register: options_delete
534
535 - name: Options - Check if host was removed
536 assert:
537 that:
538 - options_delete.changed
539 - "'options.example.com' in options_delete.hosts_removed"
540 - options_delete.hosts_changed is defined
541 - options_delete.hosts_added is defined
542
543 - name: Options - Delete same host again for idempotency
544 community.general.ssh_config:
545 ssh_config_file: "{{ ssh_config_test }}"
546 host: "options.example.com"
547 state: absent
548 register: options_delete_again
549
550 - name: Options - Check delete operation for idempotency
551 assert:
552 that:
553 - not options_delete_again.changed
554 - options_delete_again.hosts_changed is defined
555 - options_delete_again.hosts_removed is defined
556 - options_delete_again.hosts_added is defined
557
558 - name: "Options - Get content of {{ ssh_config_test }}"
559 slurp:
560 src: "{{ ssh_config_test }}"
561 register: slurp_ssh_config
562
563 - name: "Verify that {{ ssh_config_test }} does not contains deleted options"
564 assert:
565 that:
566 - "'proxyjump new-jumphost.example.com' not in slurp_ssh_config['content'] | b64decode"
567 - "'forwardagent no' not in slurp_ssh_config['content'] | b64decode"
568 - "'addkeystoagent no' not in slurp_ssh_config['content'] | b64decode"
569 - "'hostkeyalgorithms +ssh-ed25519' not in slurp_ssh_config['content'] | b64decode"
570 - "'identitiesonly no' not in slurp_ssh_config['content'] | b64decode"
571 - "'controlmaster auto' not in slurp_ssh_config['content'] | b64decode"
572 - "'controlpath ~/.ssh/sockets/%r@%h-%p' not in slurp_ssh_config['content'] | b64decode"
573 - "'controlpersist yes' not in slurp_ssh_config['content'] | b64decode"
574 - "'dynamicforward 10080' not in slurp_ssh_config['content'] | b64decode"
575 - "'serveraliveinterval 30' not in slurp_ssh_config['content'] | b64decode"
576 - "'addressfamily inet' not in slurp_ssh_config['content'] | b64decode"