Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
aos
GitHub Repository: aos/ansible
Path: blob/devel/test/integration/targets/apt/tasks/apt.yml
4752 views
1
- name: use python-apt
2
set_fact:
3
python_apt: python-apt
4
when: ansible_python_version is version('3', '<')
5
6
- name: use python3-apt
7
set_fact:
8
python_apt: python3-apt
9
when: ansible_python_version is version('3', '>=')
10
11
- name: use Debian mirror
12
set_fact:
13
distro_mirror: http://ftp.debian.org/debian
14
when: ansible_distribution == 'Debian'
15
16
- name: use Ubuntu mirror
17
set_fact:
18
distro_mirror: http://archive.ubuntu.com/ubuntu
19
when: ansible_distribution == 'Ubuntu'
20
21
# UNINSTALL 'python-apt'
22
# The `apt` module has the smarts to auto-install `python-apt`. To test, we
23
# will first uninstall `python-apt`.
24
- name: check {{ python_apt }} with dpkg
25
shell: dpkg -s {{ python_apt }}
26
register: dpkg_result
27
ignore_errors: true
28
29
- name: uninstall {{ python_apt }} with apt
30
apt: pkg={{ python_apt }} state=absent purge=yes
31
register: apt_result
32
when: dpkg_result is successful
33
34
# In check mode, auto-install of `python-apt` must fail
35
- name: test fail uninstall hello without required apt deps in check mode
36
apt:
37
pkg: hello
38
state: absent
39
purge: yes
40
register: apt_result
41
check_mode: yes
42
ignore_errors: yes
43
44
- name: verify fail uninstall hello without required apt deps in check mode
45
assert:
46
that:
47
- apt_result is failed
48
- '"If run normally this module can auto-install it." in apt_result.msg'
49
50
- name: check {{ python_apt }} with dpkg
51
shell: dpkg -s {{ python_apt }}
52
register: dpkg_result
53
ignore_errors: true
54
55
# UNINSTALL 'hello'
56
# With 'python-apt' uninstalled, the first call to 'apt' should install
57
# python-apt without updating the cache.
58
- name: uninstall hello with apt and prevent updating the cache
59
apt:
60
pkg: hello
61
state: absent
62
purge: yes
63
update_cache: no
64
register: apt_result
65
66
- name: check hello with dpkg
67
shell: dpkg-query -l hello
68
failed_when: False
69
register: dpkg_result
70
71
- name: verify uninstall hello with apt and prevent updating the cache
72
assert:
73
that:
74
- "'changed' in apt_result"
75
- apt_result is not changed
76
- "dpkg_result.rc == 1"
77
- "'Auto-installing missing dependency without updating cache: {{ python_apt }}' in apt_result.warnings"
78
79
- name: uninstall {{ python_apt }} with apt again
80
apt:
81
pkg: "{{ python_apt }}"
82
state: absent
83
purge: yes
84
85
# UNINSTALL 'hello'
86
# With 'python-apt' uninstalled, the first call to 'apt' should install
87
# python-apt.
88
- name: uninstall hello with apt
89
apt: pkg=hello state=absent purge=yes
90
register: apt_result
91
until: apt_result is success
92
93
- name: check hello with dpkg
94
shell: dpkg-query -l hello
95
failed_when: False
96
register: dpkg_result
97
98
- name: verify uninstallation of hello
99
assert:
100
that:
101
- "'changed' in apt_result"
102
- apt_result is not changed
103
- "dpkg_result.rc == 1"
104
- "'Updating cache and auto-installing missing dependency: {{ python_apt }}' in apt_result.warnings"
105
106
# UNINSTALL AGAIN
107
- name: uninstall hello with apt
108
apt: pkg=hello state=absent purge=yes
109
register: apt_result
110
111
- name: verify no change on re-uninstall
112
assert:
113
that:
114
- "not apt_result.changed"
115
116
# INSTALL
117
- name: install hello with apt
118
apt: name=hello state=present
119
register: apt_result
120
121
- name: check hello with dpkg
122
shell: dpkg-query -l hello
123
failed_when: False
124
register: dpkg_result
125
126
- name: verify installation of hello
127
assert:
128
that:
129
- "apt_result.changed"
130
- "dpkg_result.rc == 0"
131
132
- name: verify apt module outputs
133
assert:
134
that:
135
- "'changed' in apt_result"
136
- "'stderr' in apt_result"
137
- "'stdout' in apt_result"
138
- "'stdout_lines' in apt_result"
139
140
# INSTALL AGAIN
141
- name: install hello with apt
142
apt: name=hello state=present
143
register: apt_result
144
145
- name: verify no change on re-install
146
assert:
147
that:
148
- "not apt_result.changed"
149
150
# UNINSTALL AGAIN
151
- name: uninstall hello with apt
152
apt: pkg=hello state=absent purge=yes
153
register: apt_result
154
155
# INSTALL WITH VERSION WILDCARD
156
- name: install hello with apt
157
apt: name=hello=2.* state=present
158
register: apt_result
159
160
- name: check hello with wildcard with dpkg
161
shell: dpkg-query -l hello
162
failed_when: False
163
register: dpkg_result
164
165
- name: verify installation of hello
166
assert:
167
that:
168
- "apt_result.changed"
169
- "dpkg_result.rc == 0"
170
171
- name: check hello version
172
shell: dpkg -s hello | grep Version | awk '{print $2}'
173
register: hello_version
174
175
- name: check hello architecture
176
shell: dpkg -s hello | grep Architecture | awk '{print $2}'
177
register: hello_architecture
178
179
- name: uninstall hello with apt
180
apt: pkg=hello state=absent purge=yes
181
182
- name: install deb file
183
apt: deb="/var/cache/apt/archives/hello_{{ hello_version.stdout }}_{{ hello_architecture.stdout }}.deb"
184
register: apt_initial
185
186
- name: install deb file again
187
apt: deb="/var/cache/apt/archives/hello_{{ hello_version.stdout }}_{{ hello_architecture.stdout }}.deb"
188
register: apt_secondary
189
190
- name: verify installation of hello
191
assert:
192
that:
193
- "apt_initial.changed"
194
- "not apt_secondary.changed"
195
196
- name: uninstall hello with apt
197
apt: pkg=hello state=absent purge=yes
198
199
- name: install deb file from URL
200
apt: deb="{{ distro_mirror }}/pool/main/h/hello/hello_{{ hello_version.stdout }}_{{ hello_architecture.stdout }}.deb"
201
register: apt_url
202
203
- name: verify installation of hello
204
assert:
205
that:
206
- "apt_url.changed"
207
208
- name: uninstall hello with apt
209
apt: pkg=hello state=absent purge=yes
210
211
- name: force install of deb
212
apt: deb="/var/cache/apt/archives/hello_{{ hello_version.stdout }}_{{ hello_architecture.stdout }}.deb" force=true
213
register: dpkg_force
214
215
- name: verify installation of hello
216
assert:
217
that:
218
- "dpkg_force.changed"
219
220
# NEGATIVE: upgrade all packages while providing additional packages to install
221
- name: provide additional packages to install while upgrading all installed packages
222
apt: pkg=*,test state=latest
223
ignore_errors: True
224
register: apt_result
225
226
- name: verify failure of upgrade packages and install
227
assert:
228
that:
229
- "not apt_result.changed"
230
- "apt_result.failed"
231
232
- name: autoclean during install
233
apt: pkg=hello state=present autoclean=yes
234
235
# https://github.com/ansible/ansible/issues/23155
236
- name: create a repo file
237
copy:
238
dest: /etc/apt/sources.list.d/non-existing.list
239
content: deb http://ppa.launchpad.net/non-existing trusty main
240
241
- name: test for sane error message
242
apt:
243
update_cache: yes
244
register: apt_result
245
ignore_errors: yes
246
247
- name: verify sane error message
248
assert:
249
that:
250
- "'Failed to fetch' in apt_result['msg']"
251
- "'403' in apt_result['msg']"
252
253
- name: Clean up
254
file:
255
name: /etc/apt/sources.list.d/non-existing.list
256
state: absent
257
258
# https://github.com/ansible/ansible/issues/28907
259
- name: Install parent package
260
apt:
261
name: libcaca-dev
262
263
- name: Install child package
264
apt:
265
name: libslang2-dev
266
267
- shell: apt-mark showmanual | grep libcaca-dev
268
ignore_errors: yes
269
register: parent_output
270
271
- name: Check that parent package is marked as installed manually
272
assert:
273
that:
274
- "'libcaca-dev' in parent_output.stdout"
275
276
- shell: apt-mark showmanual | grep libslang2-dev
277
ignore_errors: yes
278
register: child_output
279
280
- name: Check that child package is marked as installed manually
281
assert:
282
that:
283
- "'libslang2-dev' in child_output.stdout"
284
285
- name: Clean up
286
apt:
287
name: "{{ pkgs }}"
288
state: absent
289
vars:
290
pkgs:
291
- libcaca-dev
292
- libslang2-dev
293
294
# https://github.com/ansible/ansible/issues/38995
295
- name: build-dep for a package
296
apt:
297
name: tree
298
state: build-dep
299
register: apt_result
300
301
- name: Check the result
302
assert:
303
that:
304
- apt_result is changed
305
306
- name: build-dep for a package (idempotency)
307
apt:
308
name: tree
309
state: build-dep
310
register: apt_result
311
312
- name: Check the result
313
assert:
314
that:
315
- apt_result is not changed
316
317
# check policy_rc_d parameter
318
319
- name: Install unscd but forbid service start
320
apt:
321
name: unscd
322
policy_rc_d: 101
323
324
- name: Stop unscd service
325
service:
326
name: unscd
327
state: stopped
328
register: service_unscd_stop
329
330
- name: unscd service shouldn't have been stopped by previous task
331
assert:
332
that: service_unscd_stop is not changed
333
334
- name: Uninstall unscd
335
apt:
336
name: unscd
337
policy_rc_d: 101
338
339
- name: Create incorrect /usr/sbin/policy-rc.d
340
copy:
341
dest: /usr/sbin/policy-rc.d
342
content: apt integration test
343
mode: 0755
344
345
- name: Install unscd but forbid service start
346
apt:
347
name: unscd
348
policy_rc_d: 101
349
350
- name: Stop unscd service
351
service:
352
name: unscd
353
state: stopped
354
register: service_unscd_stop
355
356
- name: unscd service shouldn't have been stopped by previous task
357
assert:
358
that: service_unscd_stop is not changed
359
360
- name: Create incorrect /usr/sbin/policy-rc.d
361
copy:
362
dest: /usr/sbin/policy-rc.d
363
content: apt integration test
364
mode: 0755
365
register: policy_rc_d
366
367
- name: Check if /usr/sbin/policy-rc.d was correctly backed-up during unscd install
368
assert:
369
that: policy_rc_d is not changed
370
371
- name: Delete /usr/sbin/policy-rc.d
372
file:
373
path: /usr/sbin/policy-rc.d
374
state: absent
375
376