summaryrefslogtreecommitdiff
path: root/test/integration/targets/apt/tasks/apt.yml
blob: bd8f225a546036f62367b46bb6ef8bddbde76746 (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
- name: use python-apt
  set_fact:
    python_apt: python-apt
  when: ansible_python_version is version('3', '<')

- name: use python3-apt
  set_fact:
    python_apt: python3-apt
  when: ansible_python_version is version('3', '>=')

- 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`.  To test, we
#  will first uninstall `python-apt`.
- name: check {{ python_apt }} with dpkg
  shell: dpkg -s {{ python_apt }}
  register: dpkg_result
  ignore_errors: true

- name: uninstall {{ python_apt }} with apt
  apt: pkg={{ python_apt }} state=absent purge=yes
  register: apt_result
  when: dpkg_result is successful

# 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

- 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"
        - "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

- 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

# 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 sane error message
  apt:
    update_cache: yes
  register: apt_result
  ignore_errors: yes

- name: verify sane error message
  assert:
    that:
      - "'Failed to fetch' 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: "{{ item }}"
    state: absent
  with_items:
    - 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