1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00
community.general/test/integration/targets/apt/tasks/upgrade.yml
Valentin Krasontovitsch cfff72e9db Use apt-get as fallback for apt upgrade
In answer to #2540, `aptitude` was introduced as tool of choice for running
upgrades in the apt module and installing new packages that arise as
dependencies during upgrades.

This recently lead to problems, as for example Ubuntu Xenial (16.04) ships
without aptitude (installed).

Studying the man pages of both apt-get and aptitude, it appears that we can
achieve the effects of `aptitude safe-upgrade` using

```
apt-get upgrade --with-new-pkgs --autoremove
```

while `aptitude full-upgrade` seems to be identical to `apt-get dist-upgrade`.

We use `apt-get` as described above as a fall-back in case that `aptitude`
cannot be found, issuing a warning when it does so.

Furthermore it introduces a flag `force_apt_get` which may be used to enforce
usage of apt-get (which does not issue a warning).

The integration tests are updated accordingly.

Cf. also the discussion in #27370.

Fixes #18987
2017-08-10 09:25:56 -04:00

67 lines
2.1 KiB
YAML

---
#### Tests for upgrade/download functions in modules/packaging/os/apt.py ####
- name: download and install old version of hello
apt: "deb=https://launchpad.net/ubuntu/+archive/primary/+files/hello_{{ hello_old_version }}_amd64.deb"
- name: check hello version
shell: dpkg -s hello | grep Version | awk '{print $2}'
register: hello_version
- debug: var=hello_version
- name: ensure the correct version of hello has been installed
assert:
that:
- "{{ hello_version.stdout }}=={{ hello_old_version }}"
- name: "(upgrade type: {{upgrade_type}}) upgrade packages to latest version, force_apt_get: {{force_apt_get|default(False)}}"
apt:
upgrade: "{{ upgrade_type }}"
force_apt_get: "{{ force_apt_get | default(False) }}"
register: upgrade_result
- name: check hello version
shell: dpkg -s hello | grep Version | awk '{print $2}'
register: hello_version
- debug: var=upgrade_result.warnings|default([])
- debug: var=aptitude_present
- debug: var=force_apt_get
- name: check that warning is not given when force_apt_get set
assert:
that:
- "'Could not find aptitude. Using apt-get instead' not in upgrade_result.warnings | default([])"
when:
- force_apt_get | default(False)
- name: check that warning is given when aptitude not found and force_apt_get not set
assert:
that:
- "'Could not find aptitude. Using apt-get instead' in upgrade_result.warnings"
when:
- not aptitude_present|default(True)
- not force_apt_get|default(False)
- name: check that old version upgraded correctly
assert:
that:
- "{{ hello_version.stdout }}!={{ hello_old_version }}"
- "{{ hello_version.changed }}"
- name: "(upgrade type: {{upgrade_type}}) upgrade packages to latest version (Idempotant)"
apt:
upgrade: "{{ upgrade_type }}"
force_apt_get: "{{ force_apt_get | default(False) }}"
register: second_upgrade_result
- name: check that nothing has changed (Idempotant)
assert:
that:
- "second_upgrade_result.changed == false"
- name: remove hello
apt:
pkg: hello
state: absent
autoclean: yes