Debian Codegraph @

ansible_collections/community/general/tests/integration/targets/shutdown/tasks/main.yml

raw
1 ---
2 ####################################################################
3 # WARNING: These are designed specifically for Ansible tests #
4 # and should not be used as examples of how to write Ansible roles #
5 ####################################################################
6
7 # Copyright (c) Ansible Project
8 # GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
9 # SPDX-License-Identifier: GPL-3.0-or-later
10 #
11
12 - name: Execute shutdown with custom message and delay
13 community.general.shutdown:
14 delay: 100
15 msg: "Custom Message"
16 register: shutdown_result
17 check_mode: true
18
19 - name: Execute shutdown with minus delay
20 community.general.shutdown:
21 delay: -100
22 register: shutdown_result_minus
23 check_mode: true
24
25 - name: Verify Custom Message except Alpine, AIX
26 assert:
27 that:
28 - '"Custom Message" in shutdown_result["shutdown_command"]'
29 - '"Shut down initiated by Ansible" in shutdown_result_minus["shutdown_command"]'
30 - '"Custom Message" not in shutdown_result_minus["shutdown_command"]'
31 when:
32 - 'ansible_facts.os_family not in ["Alpine", "AIX"]'
33 - '"systemctl" not in shutdown_result["shutdown_command"]'
34 - '"systemctl" not in shutdown_result_minus["shutdown_command"]'
35
36 - name: Verify shutdown command is present except Alpine or AIX or systemd
37 assert:
38 that: '"shutdown" in shutdown_result["shutdown_command"]'
39 when:
40 - "ansible_facts.os_family != 'Alpine'"
41 - "ansible_facts.system != 'VMKernel'"
42 - '"systemctl" not in shutdown_result["shutdown_command"]'
43
44 - name: Verify shutdown command is present in Alpine except systemd
45 assert:
46 that: '"poweroff" in shutdown_result["shutdown_command"]'
47 when:
48 - "ansible_facts.os_family == 'Alpine'"
49 - '"systemctl" not in shutdown_result["shutdown_command"]'
50
51
52 - name: Verify shutdown command is present in VMKernel except systemd
53 assert:
54 that: '"halt" in shutdown_result["shutdown_command"]'
55 when:
56 - "ansible_facts.system == 'VMKernel'"
57 - '"systemctl" not in shutdown_result["shutdown_command"]'
58
59 - name: Verify shutdown delay is present in minutes in Linux except systemd
60 assert:
61 that:
62 - '"-h 1" in shutdown_result["shutdown_command"]'
63 - '"-h 0" in shutdown_result_minus["shutdown_command"]'
64 when:
65 - "ansible_facts.system == 'Linux'"
66 - "ansible_facts.os_family != 'Alpine'"
67 - '"systemctl" not in shutdown_result["shutdown_command"]'
68 - '"systemctl" not in shutdown_result_minus["shutdown_command"]'
69
70 - name: Verify shutdown delay is present in minutes in Void, MacOSX, OpenBSD
71 assert:
72 that:
73 - '"-h +1" in shutdown_result["shutdown_command"]'
74 - '"-h +0" in shutdown_result_minus["shutdown_command"]'
75 when: ansible_facts.system in ['Void', 'Darwin', 'OpenBSD']
76
77 - name: Verify shutdown delay is present in seconds in FreeBSD
78 assert:
79 that:
80 - '"-p +100s" in shutdown_result["shutdown_command"]'
81 - '"-p +0s" in shutdown_result_minus["shutdown_command"]'
82 when: ansible_facts.system == 'FreeBSD'
83
84 - name: Verify shutdown delay is present in seconds in Solaris, SunOS
85 assert:
86 that:
87 - '"-g 100" in shutdown_result["shutdown_command"]'
88 - '"-g 0" in shutdown_result_minus["shutdown_command"]'
89 when: ansible_facts.system in ['Solaris', 'SunOS']
90
91 - name: Verify shutdown delay is present in seconds, VMKernel
92 assert:
93 that:
94 - '"-d 100" in shutdown_result["shutdown_command"]'
95 - '"-d 0" in shutdown_result_minus["shutdown_command"]'
96 when: ansible_facts.system == 'VMKernel'
97
98 - name: Ensure that systemd-sysv is absent in Ubuntu 18 and Debian
99 apt:
100 name: sytemd-sysv
101 state: absent
102 when: (ansible_facts.distribution == 'Ubuntu' and ansible_facts.distribution_major_version is version('18', '>=')) or (ansible_facts.distribution == 'Debian')
103 register: systemd_sysv_install
104
105 - name: Gather package facts
106 package_facts:
107 manager: apt
108 when: (ansible_facts.distribution == 'Ubuntu' and ansible_facts.distribution_major_version is version('18', '>=')) or (ansible_facts.distribution == 'Debian')
109
110 - name: Execute shutdown if no systemd-sysv
111 community.general.shutdown:
112 register: shutdown_result
113 check_mode: true
114 when:
115 - "(ansible_facts.distribution == 'Ubuntu' and ansible_facts.distribution_major_version is version('18', '>=')) or (ansible_facts.distribution == 'Debian')"
116 - '"systemd-sysv" not in ansible_facts.packages'
117
118 - name: Install systemd_sysv in case it has been removed in test
119 apt:
120 name: systemd-sysv
121 state: present
122 when:
123 - "(ansible_facts.distribution == 'Ubuntu' and ansible_facts.distribution_major_version is version('18', '>=')) or (ansible_facts.distribution == 'Debian')"
124 - "systemd_sysv_install is changed"