Debian Codegraph @

test/integration/targets/apt/tasks/repo.yml

raw ◀ ▶
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
1 Debian patch touch this file
1 - block:
2 - name: Install foo package version 1.0.0
3 apt:
4 name: foo=1.0.0
5 allow_unauthenticated: yes
6 register: apt_result
7
8 - name: Check install with dpkg
9 shell: dpkg-query -l foo
10 register: dpkg_result
11
12 - name: Check if install was successful
13 assert:
14 that:
15 - "apt_result is success"
16 - "dpkg_result is success"
17 - "'1.0.0' in dpkg_result.stdout"
18
19 - name: Update to foo version 1.0.1
20 apt:
21 name: foo
22 state: latest
23 allow_unauthenticated: yes
24 register: apt_result
25
26 - name: Check install with dpkg
27 shell: dpkg-query -l foo
28 register: dpkg_result
29
30 - name: Check if install was successful
31 assert:
32 that:
33 - "apt_result is success"
34 - "dpkg_result is success"
35 - "'1.0.1' in dpkg_result.stdout"
36 always:
37 - name: Clean up
38 apt:
39 name: foo
40 state: absent
41 allow_unauthenticated: yes
42
43 - name: Try to install non-existent version
44 apt:
45 name: foo=99
46 state: present
47 ignore_errors: true
48 register: apt_result
49
50 - name: Check if install failed
51 assert:
52 that:
53 - apt_result is failed
54
55 # https://github.com/ansible/ansible/issues/30638
56 - block:
57 - name: Don't install foo=1.0.1 since foo is not installed and only_upgrade is set
58 apt:
59 name: foo=1.0.1
60 state: present
61 only_upgrade: yes
62 allow_unauthenticated: yes
63 ignore_errors: yes
64 register: apt_result
65
66 - name: Check that foo was not upgraded
67 assert:
68 that:
69 - "apt_result is not changed"
70 - "apt_result is success"
71
72 - apt:
73 name: foo=1.0.0
74 allow_unauthenticated: yes
75
76 - name: Upgrade foo to 1.0.1 but don't upgrade foobar since it is not installed
77 apt:
78 name: foobar=1.0.1,foo=1.0.1
79 state: present
80 only_upgrade: yes
81 allow_unauthenticated: yes
82 register: apt_result
83
84 - name: Check install with dpkg
85 shell: "dpkg-query -l {{ item }}"
86 register: dpkg_result
87 ignore_errors: yes
88 loop:
89 - foobar
90 - foo
91
92 - name: Check if install was successful
93 assert:
94 that:
95 - "apt_result is success"
96 - "dpkg_result.results[0] is failure"
97 - "'1.0.1' not in dpkg_result.results[0].stdout"
98 - "dpkg_result.results[1] is success"
99 - "'1.0.1' in dpkg_result.results[1].stdout"
100 always:
101 - name: Clean up
102 apt:
103 name: foo
104 state: absent
105 allow_unauthenticated: yes
106
107 - block:
108 - name: Install foo=1.0.0
109 apt:
110 name: foo=1.0.0
111
112 - name: Run version test matrix
113 apt:
114 name: foo{{ item.0 }}
115 default_release: '{{ item.1 }}'
116 state: '{{ item.2 | ternary("latest","present") }}'
117 check_mode: true
118 register: apt_result
119 loop:
120 # [filter, release, state_latest, expected]
121 - ["", null, false, null]
122 - ["", null, true, "1.0.1"]
123 - ["=1.0.0", null, false, null]
124 - ["=1.0.0", null, true, null]
125 - ["=1.0.1", null, false, "1.0.1"]
126 #- ["=1.0.*", null, false, null] # legacy behavior. should not upgrade without state=latest
127 - ["=1.0.*", null, true, "1.0.1"]
128 - [">=1.0.0", null, false, null]
129 - [">=1.0.0", null, true, "1.0.1"]
130 - [">=1.0.1", null, false, "1.0.1"]
131 - ["", "testing", false, null]
132 - ["", "testing", true, "2.0.1"]
133 - ["=2.0.0", null, false, "2.0.0"]
134 - [">=2.0.0", "testing", false, "2.0.1"]
135
136 - name: Validate version test matrix
137 assert:
138 that:
139 - (item.item.3 is not none) == (item.stdout is defined)
140 - item.item.3 is none or "Inst foo [1.0.0] (" + item.item.3 + " localhost [all])" in item.stdout_lines
141 loop: '{{ apt_result.results }}'
142
143 - name: Pin foo=1.0.0
144 copy:
145 content: |-
146 Package: foo
147 Pin: version 1.0.0
148 Pin-Priority: 1000
149 dest: /etc/apt/preferences.d/foo
150
151 - name: Run pinning version test matrix
152 apt:
153 name: foo{{ item.0 }}
154 default_release: '{{ item.1 }}'
155 state: '{{ item.2 | ternary("latest","present") }}'
156 check_mode: true
157 ignore_errors: true
158 register: apt_result
159 loop:
160 # [filter, release, state_latest, expected] # expected=null for no change. expected=False to assert an error
161 - ["", null, false, null]
162 - ["", null, true, null]
163 - ["=1.0.0", null, false, null]
164 - ["=1.0.0", null, true, null]
165 - ["=1.0.1", null, false, "1.0.1"]
166 #- ["=1.0.*", null, false, null] # legacy behavior. should not upgrade without state=latest
167 - ["=1.0.*", null, true, "1.0.1"]
168 - [">=1.0.0", null, false, null]
169 - [">=1.0.0", null, true, null]
170 - [">=1.0.1", null, false, False]
171 - ["", "testing", false, null]
172 - ["", "testing", true, null]
173 - ["=2.0.0", null, false, "2.0.0"]
174 - [">=2.0.0", "testing", false, False]
175
176 - name: Validate pinning version test matrix
177 assert:
178 that:
179 - (item.item.3 != False) or (item.item.3 == False and item is failed)
180 - (item.item.3 is string) == (item.stdout is defined)
181 - item.item.3 is not string or "Inst foo [1.0.0] (" + item.item.3 + " localhost [all])" in item.stdout_lines
182 loop: '{{ apt_result.results }}'
183
184 always:
185 - name: Uninstall foo
186 apt:
187 name: foo
188 state: absent
189
190 - name: Unpin foo
191 file:
192 path: /etc/apt/preferences.d/foo
193 state: absent
194
195 # https://github.com/ansible/ansible/issues/35900
196 - block:
197 - name: Disable ubuntu repos so system packages are not upgraded and do not change testing env
198 command: mv /etc/apt/sources.list /etc/apt/sources.list.backup
199
200 - name: Install foobar, installs foo as a dependency
201 apt:
202 name: foobar=1.0.0
203 allow_unauthenticated: yes
204
205 - name: mark foobar as auto for next test
206 shell: apt-mark auto foobar
207
208 - name: Install foobar (marked as manual) (check mode)
209 apt:
210 name: foobar=1.0.1
211 allow_unauthenticated: yes
212 check_mode: yes
213 register: manual_foobar_install_check_mode
214
215 - name: check foobar was not marked as manually installed by check mode
216 shell: apt-mark showmanual | grep foobar
217 ignore_errors: yes
218 register: showmanual
219
220 - assert:
221 that:
222 - manual_foobar_install_check_mode.changed
223 - "'foobar' not in showmanual.stdout"
224
225 - name: Install foobar (marked as manual)
226 apt:
227 name: foobar=1.0.1
228 allow_unauthenticated: yes
229 register: manual_foobar_install
230
231 - name: check foobar was marked as manually installed
232 shell: apt-mark showmanual | grep foobar
233 ignore_errors: yes
234 register: showmanual
235
236 - assert:
237 that:
238 - manual_foobar_install.changed
239 - "'foobar' in showmanual.stdout"
240
241 - name: Upgrade foobar to a version which does not depend on foo, autoremove should remove foo
242 apt:
243 upgrade: dist
244 autoremove: yes
245 allow_unauthenticated: yes
246
247 - name: Check foo with dpkg
248 shell: dpkg-query -l foo
249 register: dpkg_result
250 ignore_errors: yes
251
252 - name: Check that foo was removed by autoremove
253 assert:
254 that:
255 - "dpkg_result is failed"
256
257 always:
258 - name: Clean up
259 apt:
260 pkg: foo,foobar
261 state: absent
262 autoclean: yes
263
264 - name: Restore ubuntu repos
265 command: mv /etc/apt/sources.list.backup /etc/apt/sources.list
266
267
268 # https://github.com/ansible/ansible/issues/26298
269 - block:
270 - name: Disable ubuntu repos so system packages are not upgraded and do not change testing env
271 command: mv /etc/apt/sources.list /etc/apt/sources.list.backup
272
273 - name: Install foobar, installs foo as a dependency
274 apt:
275 name: foobar=1.0.0
276 allow_unauthenticated: yes
277
278 - name: Upgrade foobar to a version which does not depend on foo
279 apt:
280 upgrade: dist
281 force: yes # workaround for --allow-unauthenticated used along with upgrade
282
283 - name: autoremove should remove foo
284 apt:
285 autoremove: yes
286 register: autoremove_result
287
288 - name: Check that autoremove correctly reports changed=True
289 assert:
290 that:
291 - "autoremove_result is changed"
292
293 - name: Check foo with dpkg
294 shell: dpkg-query -l foo
295 register: dpkg_result
296 ignore_errors: yes
297
298 - name: Check that foo was removed by autoremove
299 assert:
300 that:
301 - "dpkg_result is failed"
302
303 - name: Nothing to autoremove
304 apt:
305 autoremove: yes
306 register: autoremove_result
307
308 - name: Check that autoremove correctly reports changed=False
309 assert:
310 that:
311 - "autoremove_result is not changed"
312
313 - name: Create a fake .deb file for autoclean to remove
314 file:
315 name: /var/cache/apt/archives/python3-q_2.4-1_all.deb
316 state: touch
317
318 - name: autoclean fake .deb file
319 apt:
320 autoclean: yes
321 register: autoclean_result
322
323 - name: Check if the .deb file exists
324 stat:
325 path: /var/cache/apt/archives/python3-q_2.4-1_all.deb
326 register: stat_result
327
328 - name: Check that autoclean correctly reports changed=True and file was removed
329 assert:
330 that:
331 - "autoclean_result is changed"
332 - "not stat_result.stat.exists"
333
334 - name: Nothing to autoclean
335 apt:
336 autoclean: yes
337 register: autoclean_result
338
339 - name: Check that autoclean correctly reports changed=False
340 assert:
341 that:
342 - "autoclean_result is not changed"
343
344 always:
345 - name: Clean up
346 apt:
347 pkg: foo,foobar
348 state: absent
349 autoclean: yes
350
351 - name: Restore ubuntu repos
352 command: mv /etc/apt/sources.list.backup /etc/apt/sources.list
353
354 - name: Downgrades
355 import_tasks: "downgrade.yml"
356
357 - name: Upgrades
358 block:
359 - import_tasks: "upgrade.yml"
360 vars:
361 aptitude_present: "{{ True | bool }}"
362 upgrade_type: "dist"
363 force_apt_get: "{{ False | bool }}"
364
365 - name: Check if aptitude is installed
366 command: dpkg-query --show --showformat='${db:Status-Abbrev}' aptitude
367 register: aptitude_status
368
369 - name: Remove aptitude, if installed, to test fall-back to apt-get
370 apt:
371 pkg: aptitude
372 state: absent
373 when:
374 - aptitude_status.stdout.find('ii') != -1
375
376 - include_tasks: "upgrade.yml"
377 vars:
378 aptitude_present: "{{ False | bool }}"
379 upgrade_type: "{{ item.upgrade_type }}"
380 force_apt_get: "{{ item.force_apt_get }}"
381 with_items:
382 - { upgrade_type: safe, force_apt_get: False }
383 - { upgrade_type: full, force_apt_get: False }
384 - { upgrade_type: safe, force_apt_get: True }
385 - { upgrade_type: full, force_apt_get: True }
386
387 - include_tasks: "upgrade_autoremove.yml"
388
389 - name: (Re-)Install aptitude, run same tests again
390 apt:
391 pkg: aptitude
392 state: present
393
394 - include_tasks: "upgrade.yml"
395 vars:
396 aptitude_present: "{{ True | bool }}"
397 upgrade_type: "{{ item.upgrade_type }}"
398 force_apt_get: "{{ item.force_apt_get }}"
399 with_items:
400 - { upgrade_type: safe, force_apt_get: False }
401 - { upgrade_type: full, force_apt_get: False }
402 - { upgrade_type: safe, force_apt_get: True }
403 - { upgrade_type: full, force_apt_get: True }
404
405 - include_tasks: "upgrade_scenarios.yml"
406 - include_tasks: "upgrade_autoremove.yml"
407
408 - name: Remove aptitude if not originally present
409 apt:
410 pkg: aptitude
411 state: absent
412 when:
413 - aptitude_status.stdout.find('ii') == -1
414
415 - block:
416 - name: Install the foo package with diff=yes
417 apt:
418 name: foo
419 allow_unauthenticated: yes
420 diff: yes
421 register: apt_result
422
423 - name: Check the content of diff.prepared
424 assert:
425 that:
426 - apt_result is success
427 - "'The following NEW packages will be installed:\n foo' in apt_result.diff.prepared"
428 always:
429 - name: Clean up
430 apt:
431 name: foo
432 state: absent
433 allow_unauthenticated: yes
434
435 - block:
436 - name: Install foo package version 1.0.0 with force=yes, implies allow_unauthenticated=yes
437 apt:
438 name: foo=1.0.0
439 force: yes
440 register: apt_result
441
442 - name: Check install with dpkg
443 shell: dpkg-query -l foo
444 register: dpkg_result
445
446 - name: Check if install was successful
447 assert:
448 that:
449 - "apt_result is success"
450 - "dpkg_result is success"
451 - "'1.0.0' in dpkg_result.stdout"
452 always:
453 - name: Clean up
454 apt:
455 name: foo
456 state: absent
457 allow_unauthenticated: yes