blob: 64e00d3ca9afe30b0d34868f6603fb42e2cb0737 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
|
- name: use Debian mirror
set_fact:
distro_mirror: http://ftp.debian.org/debian
when: ansible_distribution == 'Debian'
- name: use Ubuntu mirror
set_fact:
distro_mirror: http://archive.ubuntu.com/ubuntu
when: ansible_distribution == 'Ubuntu'
# UNINSTALL 'python-apt'
# The `apt` module has the smarts to auto-install `python-apt(3)`. To test, we
# will first uninstall `python-apt`.
- name: uninstall python-apt with apt
apt:
pkg: [python-apt, python3-apt]
state: absent
purge: yes
register: apt_result
# In check mode, auto-install of `python-apt` must fail
- name: test fail uninstall hello without required apt deps in check mode
apt:
pkg: hello
state: absent
purge: yes
register: apt_result
check_mode: yes
ignore_errors: yes
- name: verify fail uninstall hello without required apt deps in check mode
assert:
that:
- apt_result is failed
- '"If run normally this module can auto-install it." in apt_result.msg'
- name: check with dpkg
shell: dpkg -s python-apt python3-apt
register: dpkg_result
ignore_errors: true
# UNINSTALL 'hello'
# With 'python-apt' uninstalled, the first call to 'apt' should install
# python-apt without updating the cache.
- name: uninstall hello with apt and prevent updating the cache
apt:
pkg: hello
state: absent
purge: yes
update_cache: no
register: apt_result
- name: check hello with dpkg
shell: dpkg-query -l hello
failed_when: False
register: dpkg_result
- name: verify uninstall hello with apt and prevent updating the cache
assert:
that:
- "'changed' in apt_result"
- apt_result is not changed
- "dpkg_result.rc == 1"
- name: Test installing fnmatch package
apt:
name:
- hel?o
- he?lo
register: apt_install_fnmatch
- name: Test uninstalling fnmatch package
apt:
name:
- hel?o
- he?lo
state: absent
register: apt_uninstall_fnmatch
- name: verify fnmatch
assert:
that:
- apt_install_fnmatch is changed
- apt_uninstall_fnmatch is changed
- name: Test update_cache 1 (check mode)
apt:
update_cache: true
cache_valid_time: 10
register: apt_update_cache_1_check_mode
check_mode: true
- name: Test update_cache 1
apt:
update_cache: true
cache_valid_time: 10
register: apt_update_cache_1
- name: Test update_cache 2 (check mode)
apt:
update_cache: true
cache_valid_time: 10
register: apt_update_cache_2_check_mode
check_mode: true
- name: Test update_cache 2
apt:
update_cache: true
cache_valid_time: 10
register: apt_update_cache_2
- name: verify update_cache
assert:
that:
- apt_update_cache_1_check_mode is changed
- apt_update_cache_1 is changed
- apt_update_cache_2_check_mode is not changed
- apt_update_cache_2 is not changed
- name: uninstall apt bindings with apt again
apt:
pkg: [python-apt, python3-apt]
state: absent
purge: yes
# UNINSTALL 'hello'
# With 'python-apt' uninstalled, the first call to 'apt' should install
# python-apt.
- name: uninstall hello with apt
apt: pkg=hello state=absent purge=yes
register: apt_result
until: apt_result is success
- name: check hello with dpkg
shell: dpkg-query -l hello
failed_when: False
register: dpkg_result
- name: verify uninstallation of hello
assert:
that:
- "'changed' in apt_result"
- apt_result is not changed
- "dpkg_result.rc == 1"
# UNINSTALL AGAIN
- name: uninstall hello with apt
apt: pkg=hello state=absent purge=yes
register: apt_result
- name: verify no change on re-uninstall
assert:
that:
- "not apt_result.changed"
# INSTALL
- name: install hello with apt
apt: name=hello state=present
register: apt_result
- name: check hello with dpkg
shell: dpkg-query -l hello
failed_when: False
register: dpkg_result
- name: verify installation of hello
assert:
that:
- "apt_result.changed"
- "dpkg_result.rc == 0"
- name: verify apt module outputs
assert:
that:
- "'changed' in apt_result"
- "'stderr' in apt_result"
- "'stdout' in apt_result"
- "'stdout_lines' in apt_result"
# INSTALL AGAIN
- name: install hello with apt
apt: name=hello state=present
register: apt_result
- name: verify no change on re-install
assert:
that:
- "not apt_result.changed"
# UNINSTALL AGAIN
- name: uninstall hello with apt
apt: pkg=hello state=absent purge=yes
register: apt_result
# INSTALL WITH VERSION WILDCARD
- name: install hello with apt
apt: name=hello=2.* state=present
register: apt_result
- name: check hello with wildcard with dpkg
shell: dpkg-query -l hello
failed_when: False
register: dpkg_result
- name: verify installation of hello
assert:
that:
- "apt_result.changed"
- "dpkg_result.rc == 0"
- name: check hello version
shell: dpkg -s hello | grep Version | awk '{print $2}'
register: hello_version
- name: check hello architecture
shell: dpkg -s hello | grep Architecture | awk '{print $2}'
register: hello_architecture
- name: uninstall hello with apt
apt: pkg=hello state=absent purge=yes
# INSTALL WITHOUT REMOVALS
- name: Install hello, that conflicts with hello-traditional
apt:
pkg: hello
state: present
update_cache: no
- name: check hello
shell: dpkg-query -l hello
register: dpkg_result
- name: verify installation of hello
assert:
that:
- "apt_result.changed"
- "dpkg_result.rc == 0"
- name: Try installing hello-traditional, that conflicts with hello
apt:
pkg: hello-traditional
state: present
fail_on_autoremove: yes
ignore_errors: yes
register: apt_result
- name: verify failure of installing hello-traditional, because it is required to remove hello to install.
assert:
that:
- apt_result is failed
- '"Packages need to be removed but remove is disabled." in apt_result.msg'
- name: uninstall hello with apt
apt:
pkg: hello
state: absent
purge: yes
update_cache: no
- name: install deb file
apt: deb="/var/cache/apt/archives/hello_{{ hello_version.stdout }}_{{ hello_architecture.stdout }}.deb"
register: apt_initial
- name: install deb file again
apt: deb="/var/cache/apt/archives/hello_{{ hello_version.stdout }}_{{ hello_architecture.stdout }}.deb"
register: apt_secondary
- name: verify installation of hello
assert:
that:
- "apt_initial.changed"
- "not apt_secondary.changed"
- name: uninstall hello with apt
apt: pkg=hello state=absent purge=yes
- name: install deb file from URL
apt: deb="{{ distro_mirror }}/pool/main/h/hello/hello_{{ hello_version.stdout }}_{{ hello_architecture.stdout }}.deb"
register: apt_url
- name: verify installation of hello
assert:
that:
- "apt_url.changed"
- name: uninstall hello with apt
apt: pkg=hello state=absent purge=yes
- name: force install of deb
apt: deb="/var/cache/apt/archives/hello_{{ hello_version.stdout }}_{{ hello_architecture.stdout }}.deb" force=true
register: dpkg_force
- name: verify installation of hello
assert:
that:
- "dpkg_force.changed"
# NEGATIVE: upgrade all packages while providing additional packages to install
- name: provide additional packages to install while upgrading all installed packages
apt: pkg=*,test state=latest
ignore_errors: True
register: apt_result
- name: verify failure of upgrade packages and install
assert:
that:
- "not apt_result.changed"
- "apt_result.failed"
- name: autoclean during install
apt: pkg=hello state=present autoclean=yes
- name: undo previous install
apt: pkg=hello state=absent
# https://github.com/ansible/ansible/issues/23155
- name: create a repo file
copy:
dest: /etc/apt/sources.list.d/non-existing.list
content: deb http://ppa.launchpad.net/non-existing trusty main
- name: test for logical error message
apt:
update_cache: yes
register: apt_result
ignore_errors: yes
- name: verify logical error message
assert:
that:
- "'Failed to update apt cache' in apt_result['msg']"
- "'403' in apt_result['msg']"
- name: Clean up
file:
name: /etc/apt/sources.list.d/non-existing.list
state: absent
# https://github.com/ansible/ansible/issues/28907
- name: Install parent package
apt:
name: libcaca-dev
- name: Install child package
apt:
name: libslang2-dev
- shell: apt-mark showmanual | grep libcaca-dev
ignore_errors: yes
register: parent_output
- name: Check that parent package is marked as installed manually
assert:
that:
- "'libcaca-dev' in parent_output.stdout"
- shell: apt-mark showmanual | grep libslang2-dev
ignore_errors: yes
register: child_output
- name: Check that child package is marked as installed manually
assert:
that:
- "'libslang2-dev' in child_output.stdout"
- name: Clean up
apt:
name: "{{ pkgs }}"
state: absent
vars:
pkgs:
- libcaca-dev
- libslang2-dev
# # https://github.com/ansible/ansible/issues/38995
- name: build-dep for a package
apt:
name: tree
state: build-dep
register: apt_result
- name: Check the result
assert:
that:
- apt_result is changed
- name: build-dep for a package (idempotency)
apt:
name: tree
state: build-dep
register: apt_result
- name: Check the result
assert:
that:
- apt_result is not changed
# check policy_rc_d parameter
- name: Install unscd but forbid service start
apt:
name: unscd
policy_rc_d: 101
- name: Stop unscd service
service:
name: unscd
state: stopped
register: service_unscd_stop
- name: unscd service shouldn't have been stopped by previous task
assert:
that: service_unscd_stop is not changed
- name: Uninstall unscd
apt:
name: unscd
policy_rc_d: 101
- name: Create incorrect /usr/sbin/policy-rc.d
copy:
dest: /usr/sbin/policy-rc.d
content: apt integration test
mode: 0755
- name: Install unscd but forbid service start
apt:
name: unscd
policy_rc_d: 101
- name: Stop unscd service
service:
name: unscd
state: stopped
register: service_unscd_stop
- name: unscd service shouldn't have been stopped by previous task
assert:
that: service_unscd_stop is not changed
- name: Create incorrect /usr/sbin/policy-rc.d
copy:
dest: /usr/sbin/policy-rc.d
content: apt integration test
mode: 0755
register: policy_rc_d
- name: Check if /usr/sbin/policy-rc.d was correctly backed-up during unscd install
assert:
that: policy_rc_d is not changed
- name: Delete /usr/sbin/policy-rc.d
file:
path: /usr/sbin/policy-rc.d
state: absent
# https://github.com/ansible/ansible/issues/65325
- name: Download and install old version of hello (to test allow_change_held_packages option)
apt: "deb=https://ci-files.testing.ansible.com/test/integration/targets/dpkg_selections/hello_{{ hello_old_version }}_amd64.deb"
notify:
- remove package hello
- name: Put hello on hold
shell: apt-mark hold hello
- name: Get hold list
shell: apt-mark showhold
register: allow_change_held_packages_hold
- name: Check that the package hello is on the hold list
assert:
that:
- "'hello' in allow_change_held_packages_hold.stdout"
- name: Try updating package to the latest version (allow_change_held_packages=no)
apt:
name: hello
state: latest
ignore_errors: True
register: allow_change_held_packages_failed_update
- name: Get the version of the package
shell: dpkg -s hello | grep Version | awk '{print $2}'
register: allow_change_held_packages_hello_version
- name: Verify that the package was not updated (apt returns with an error)
assert:
that:
- "allow_change_held_packages_failed_update is failed"
- "'--allow-change-held-packages' in allow_change_held_packages_failed_update.stderr"
- "allow_change_held_packages_hello_version.stdout == hello_old_version"
- name: Try updating package to the latest version (allow_change_held_packages=yes)
apt:
name: hello
state: latest
allow_change_held_packages: yes
register: allow_change_held_packages_successful_update
- name: Get the version of the package
shell: dpkg -s hello | grep Version | awk '{print $2}'
register: allow_change_held_packages_hello_version
- name: Verify that the package was updated
assert:
that:
- "allow_change_held_packages_successful_update is changed"
- "allow_change_held_packages_hello_version.stdout != hello_old_version"
- name: Try updating package to the latest version again
apt:
name: hello
state: latest
allow_change_held_packages: yes
register: allow_change_held_packages_no_update
- name: Get the version of the package
shell: dpkg -s hello | grep Version | awk '{print $2}'
register: allow_change_held_packages_hello_version_again
- name: Verify that the package was not updated
assert:
that:
- "allow_change_held_packages_no_update is not changed"
- "allow_change_held_packages_hello_version.stdout == allow_change_held_packages_hello_version_again.stdout"
# Remove pkg on hold
- name: Put hello on hold
shell: apt-mark hold hello
- name: Get hold list
shell: apt-mark showhold
register: hello_hold
- name: Check that the package hello is on the hold list
assert:
that:
- "'hello' in hello_hold.stdout"
- name: Try removing package hello
apt:
name: hello
state: absent
register: package_removed
ignore_errors: true
- name: verify the package is not removed with dpkg
shell: dpkg -l hello
register: dpkg_result
- name: Verify that package was not removed
assert:
that:
- package_removed is failed
- dpkg_result is success
- name: Try removing package (allow_change_held_packages=yes)
apt:
name: hello
state: absent
allow_change_held_packages: yes
register: package_removed
- name: verify the package is removed with dpkg
shell: dpkg -l hello
register: dpkg_result
ignore_errors: true
- name: Verify that package removal was succesfull
assert:
that:
- package_removed is success
- dpkg_result is failed
- package_removed.changed
# Virtual package
- name: Install a virtual package
apt:
package:
- emacs-nox
- yaml-mode # <- the virtual package
state: latest
register: install_virtual_package_result
- name: Check the virtual package install result
assert:
that:
- install_virtual_package_result is changed
- name: Clean up virtual-package install
apt:
package:
- emacs-nox
- elpa-yaml-mode
state: absent
purge: yes
# https://github.com/ansible/ansible/issues/82611
- name: clean apt cache
apt:
clean: true
- name: check for /var/cache/apt/pkgcache.bin
stat:
path: /var/cache/apt/pkgcache.bin
register: pkgcache_bin
- name: check for /var/cache/apt/srcpkgcache.bin
stat:
path: /var/cache/apt/srcpkgcache.bin
register: srcpkgcache_bin
- name: verify apt cache files are cleaned
assert:
that:
- not pkgcache_bin.stat.exists
- not srcpkgcache_bin.stat.exists
fail_msg: "apt cache files still exist."
success_msg: "apt cache files are cleaned."
|