Debian Codegraph @

test/integration/targets/package/tasks/main.yml

raw
1 # Test code for the package module.
2 # (c) 2017, James Tanner <[email protected]>
3
4 # This file is part of Ansible
5 #
6 # Ansible is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
10 #
11 # Ansible is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with Ansible. If not, see <http://www.gnu.org/licenses/>.
18
19 # Verify correct default package manager for Fedora
20 # Validates: https://github.com/ansible/ansible/issues/34014
21 - block:
22 - name: install apt
23 dnf:
24 name: apt
25 state: present
26 - name: gather facts again
27 setup:
28 - name: validate output
29 assert:
30 that:
31 - 'ansible_pkg_mgr in ("dnf", "dnf5")'
32 always:
33 - name: remove apt
34 dnf:
35 name: apt
36 state: absent
37 - name: gather facts again
38 setup:
39 when: ansible_distribution == "Fedora"
40
41 # Verify correct default package manager for Debian/Ubuntu when Zypper installed
42 - block:
43 # Just make an executable file called "zypper" - installing zypper itself
44 # consistently is hard - and we're not going to use it
45 - name: install fake zypper
46 file:
47 state: touch
48 mode: 0755
49 path: /usr/bin/zypper
50 - name: gather facts again
51 setup:
52 - name: validate output
53 assert:
54 that:
55 - 'ansible_pkg_mgr == "apt"'
56 always:
57 - name: remove fake zypper
58 file:
59 path: /usr/bin/zypper
60 state: absent
61 - name: gather facts again
62 setup:
63 when: ansible_os_family == "Debian"
64
65 ##
66 ## package
67 ##
68
69 # Verify module_defaults for package and the underlying module are utilized
70 # Validates: https://github.com/ansible/ansible/issues/72918
71 - block:
72 # note: dnf module unexpectedly succeeds when no arguments are provided.
73 # Until the requires_one_of (?) bug is fixed, this test asserts changes are made to avoid false positives.
74 - name: install apt with package defaults
75 package:
76 module_defaults:
77 package:
78 name: apt
79 state: present
80 register: result
81
82 - assert:
83 that: result is changed
84
85 - name: uninstall apt between tests
86 dnf5:
87 name: apt
88 state: absent
89
90 # Validate package handles applying templated defaults for dnf
91 # https://github.com/ansible/ansible/issues/85848
92 - name: install apt with dnf defaults (auto)
93 package:
94 module_defaults:
95 dnf5:
96 name: "{{ 'apt' }}"
97 state: present
98 register: result
99
100 - assert:
101 that: result is changed
102
103 - name: uninstall apt between tests
104 dnf5:
105 name: apt
106 state: absent
107
108 - name: install apt with dnf defaults (use dnf5)
109 package:
110 use: dnf5
111 module_defaults:
112 dnf5:
113 name: apt
114 state: present
115 register: result
116
117 - assert:
118 that: result is changed
119 always:
120 - name: remove apt
121 dnf:
122 name: apt
123 state: absent
124 when: ansible_distribution == "Fedora"
125
126 - name: define distros to attempt installing at on
127 set_fact:
128 package_distros:
129 - RedHat
130 - Fedora
131 - Ubuntu
132
133 - block:
134 - name: remove at package
135 package:
136 name: at
137 state: absent
138 register: at_check0
139
140 - name: verify at command is missing
141 shell: which at
142 register: at_check1
143 failed_when: at_check1.rc == 0
144
145 - name: reinstall at package
146 package:
147 name: at
148 state: present
149 register: at_install0
150 - debug: var=at_install0
151 - name: validate results
152 assert:
153 that:
154 - 'at_install0.changed is defined'
155 - 'at_install0.changed'
156
157 - name: verify at command is installed
158 shell: which at
159
160 - name: remove at package
161 package:
162 name: at
163 state: absent
164 register: at_install0
165
166 - name: validate package removal
167 assert:
168 that:
169 - "at_install0 is changed"
170
171 when: ansible_distribution in package_distros
172
173 ##
174 ## dnf
175 ##
176 #Validation for new parameter 'use' in dnf action plugin which aliases to 'use_backend'
177 #Issue: https://github.com/ansible/ansible/issues/70774
178 - block:
179 - name: verify if using both the parameters 'use' and 'use_backend' throw error
180 dnf:
181 name: at
182 state: present
183 use_backend: dnf
184 use: dnf
185 ignore_errors: yes
186 register: result
187
188 - name: verify error
189 assert:
190 that:
191 - "'parameters are mutually exclusive' in result.msg"
192 - "not result is changed"
193
194 - name: verify if package installation is successful using 'use' parameter
195 dnf:
196 name: at
197 state: present
198 use: dnf
199 register: result
200
201 - name: verify the result
202 assert:
203 that:
204 - "result is changed"
205
206 - name: remove at package
207 dnf:
208 name: at
209 state: absent
210 use: dnf
211 register: result
212
213 - name: verify package removal
214 assert:
215 that:
216 - "result is changed"
217
218 - name: verify if package installation is successful using 'use_backend' parameter
219 dnf:
220 name: at
221 state: present
222 use_backend: dnf
223 register: result
224
225 - name: verify the result
226 assert:
227 that:
228 - "result is changed"
229
230 - name: remove at package
231 dnf:
232 name: at
233 state: absent
234 use_backend: dnf
235 register: result
236
237 - name: verify package removal
238 assert:
239 that:
240 - "result is changed"
241
242 - name: verify if package installation is successful without using 'use_backend' and 'use' parameters
243 dnf:
244 name: at
245 state: present
246 register: result
247
248 - name: verify the result
249 assert:
250 that:
251 - "result is changed"
252
253 - name: remove at package
254 dnf:
255 name: at
256 state: absent
257 register: result
258
259 - name: verify package removal
260 assert:
261 that:
262 - "result is changed"
263
264 when: ansible_distribution == "Fedora"
265
266
267 - name: test ansible_package_use
268 block:
269 - name: test with var
270 package:
271 name: doesnotmatter
272 vars:
273 ansible_package_use: lola
274 ignore_errors: true
275 register: use_to_use
276
277 - assert:
278 that:
279 - use_to_use is failed
280 - "'Could not find a matching action' in use_to_use['msg']"