2018-10-08 14:41:57 +02:00
|
|
|
- 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'
|
|
|
|
|
2014-03-17 15:41:02 +01:00
|
|
|
# UNINSTALL 'python-apt'
|
2021-02-11 06:32:59 +01:00
|
|
|
# The `apt` module has the smarts to auto-install `python-apt(3)`. To test, we
|
2014-03-17 15:41:02 +01:00
|
|
|
# will first uninstall `python-apt`.
|
2021-02-11 06:32:59 +01:00
|
|
|
- name: uninstall python-apt with apt
|
|
|
|
apt:
|
|
|
|
pkg: [python-apt, python3-apt]
|
|
|
|
state: absent
|
|
|
|
purge: yes
|
2014-03-17 15:41:02 +01:00
|
|
|
register: apt_result
|
|
|
|
|
2019-08-30 21:57:58 +02:00
|
|
|
# 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'
|
|
|
|
|
2021-02-11 06:32:59 +01:00
|
|
|
- name: check with dpkg
|
|
|
|
shell: dpkg -s python-apt python3-apt
|
2019-08-30 21:57:58 +02:00
|
|
|
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"
|
|
|
|
|
2020-10-08 20:32:59 +02:00
|
|
|
- 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
|
|
|
|
apt:
|
|
|
|
update_cache: true
|
|
|
|
cache_valid_time: 10
|
|
|
|
register: apt_update_cache_1
|
|
|
|
|
|
|
|
- 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 is changed
|
|
|
|
- apt_update_cache_2 is not changed
|
|
|
|
|
2021-02-11 06:32:59 +01:00
|
|
|
- name: uninstall apt bindings with apt again
|
2019-08-30 21:57:58 +02:00
|
|
|
apt:
|
2021-02-11 06:32:59 +01:00
|
|
|
pkg: [python-apt, python3-apt]
|
2019-08-30 21:57:58 +02:00
|
|
|
state: absent
|
|
|
|
purge: yes
|
|
|
|
|
2014-03-17 15:41:02 +01:00
|
|
|
# UNINSTALL 'hello'
|
|
|
|
# With 'python-apt' uninstalled, the first call to 'apt' should install
|
|
|
|
# python-apt.
|
2014-02-23 11:46:39 +01:00
|
|
|
- name: uninstall hello with apt
|
|
|
|
apt: pkg=hello state=absent purge=yes
|
2014-02-20 20:55:55 +01:00
|
|
|
register: apt_result
|
2019-12-12 20:45:54 +01:00
|
|
|
until: apt_result is success
|
2014-02-20 20:55:55 +01:00
|
|
|
|
2014-02-23 11:46:39 +01:00
|
|
|
- name: check hello with dpkg
|
2016-04-23 22:43:11 +02:00
|
|
|
shell: dpkg-query -l hello
|
2014-02-20 20:55:55 +01:00
|
|
|
failed_when: False
|
|
|
|
register: dpkg_result
|
|
|
|
|
2014-02-23 11:46:39 +01:00
|
|
|
- name: verify uninstallation of hello
|
2014-02-20 20:55:55 +01:00
|
|
|
assert:
|
2014-02-23 11:46:39 +01:00
|
|
|
that:
|
2019-08-30 21:57:58 +02:00
|
|
|
- "'changed' in apt_result"
|
|
|
|
- apt_result is not changed
|
|
|
|
- "dpkg_result.rc == 1"
|
2014-02-20 20:55:55 +01:00
|
|
|
|
2014-02-20 21:01:23 +01:00
|
|
|
# UNINSTALL AGAIN
|
2014-02-23 11:46:39 +01:00
|
|
|
- name: uninstall hello with apt
|
|
|
|
apt: pkg=hello state=absent purge=yes
|
2014-02-20 21:01:23 +01:00
|
|
|
register: apt_result
|
|
|
|
|
|
|
|
- name: verify no change on re-uninstall
|
|
|
|
assert:
|
2014-02-23 11:46:39 +01:00
|
|
|
that:
|
2014-02-20 21:01:23 +01:00
|
|
|
- "not apt_result.changed"
|
|
|
|
|
2014-02-20 20:55:55 +01:00
|
|
|
# INSTALL
|
2014-02-23 11:46:39 +01:00
|
|
|
- name: install hello with apt
|
|
|
|
apt: name=hello state=present
|
2014-02-20 20:55:55 +01:00
|
|
|
register: apt_result
|
|
|
|
|
2014-02-23 11:46:39 +01:00
|
|
|
- name: check hello with dpkg
|
2016-04-23 22:43:11 +02:00
|
|
|
shell: dpkg-query -l hello
|
2014-02-20 20:55:55 +01:00
|
|
|
failed_when: False
|
|
|
|
register: dpkg_result
|
|
|
|
|
2014-02-23 11:46:39 +01:00
|
|
|
- name: verify installation of hello
|
2014-02-20 20:55:55 +01:00
|
|
|
assert:
|
2014-02-23 11:46:39 +01:00
|
|
|
that:
|
2014-02-20 20:55:55 +01:00
|
|
|
- "apt_result.changed"
|
|
|
|
- "dpkg_result.rc == 0"
|
|
|
|
|
|
|
|
- name: verify apt module outputs
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- "'changed' in apt_result"
|
|
|
|
- "'stderr' in apt_result"
|
2014-02-23 11:46:39 +01:00
|
|
|
- "'stdout' in apt_result"
|
|
|
|
- "'stdout_lines' in apt_result"
|
2014-02-20 21:01:23 +01:00
|
|
|
|
|
|
|
# INSTALL AGAIN
|
2014-02-23 11:46:39 +01:00
|
|
|
- name: install hello with apt
|
|
|
|
apt: name=hello state=present
|
2014-02-20 21:01:23 +01:00
|
|
|
register: apt_result
|
|
|
|
|
|
|
|
- name: verify no change on re-install
|
|
|
|
assert:
|
2014-02-23 11:46:39 +01:00
|
|
|
that:
|
2014-02-20 21:01:23 +01:00
|
|
|
- "not apt_result.changed"
|
|
|
|
|
2014-09-05 08:40:27 +02:00
|
|
|
# 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
|
2014-11-14 19:02:21 +01:00
|
|
|
apt: name=hello=2.* state=present
|
2014-09-05 08:40:27 +02:00
|
|
|
register: apt_result
|
|
|
|
|
|
|
|
- name: check hello with wildcard with dpkg
|
2016-04-23 22:43:11 +02:00
|
|
|
shell: dpkg-query -l hello
|
2014-09-05 08:40:27 +02:00
|
|
|
failed_when: False
|
|
|
|
register: dpkg_result
|
|
|
|
|
|
|
|
- name: verify installation of hello
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- "apt_result.changed"
|
|
|
|
- "dpkg_result.rc == 0"
|
2014-02-23 11:46:39 +01:00
|
|
|
|
2015-01-08 04:44:31 +01:00
|
|
|
- name: check hello version
|
2016-04-23 22:43:11 +02:00
|
|
|
shell: dpkg -s hello | grep Version | awk '{print $2}'
|
2015-01-08 04:44:31 +01:00
|
|
|
register: hello_version
|
2017-06-19 14:57:26 +02:00
|
|
|
|
2015-01-08 04:44:31 +01:00
|
|
|
- name: check hello architecture
|
2016-04-23 22:43:11 +02:00
|
|
|
shell: dpkg -s hello | grep Architecture | awk '{print $2}'
|
2015-01-08 04:44:31 +01:00
|
|
|
register: hello_architecture
|
|
|
|
|
|
|
|
- name: uninstall hello with apt
|
|
|
|
apt: pkg=hello state=absent purge=yes
|
|
|
|
|
2020-06-30 15:53:14 +02:00
|
|
|
# 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
|
|
|
|
|
2015-01-08 04:44:31 +01:00
|
|
|
- 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
|
|
|
|
|
2018-10-08 14:41:57 +02:00
|
|
|
- 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
|
|
|
|
|
2015-01-08 04:44:31 +01:00
|
|
|
- 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"
|
2017-05-25 01:04:38 +02:00
|
|
|
|
|
|
|
# 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"
|
2017-05-25 21:52:41 +02:00
|
|
|
|
2018-04-09 11:10:42 +02:00
|
|
|
- name: autoclean during install
|
|
|
|
apt: pkg=hello state=present autoclean=yes
|
|
|
|
|
2021-01-22 05:58:31 +01:00
|
|
|
- name: undo previous install
|
|
|
|
apt: pkg=hello state=absent
|
|
|
|
|
2018-03-15 17:32:25 +01:00
|
|
|
# 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:
|
2018-03-29 08:20:10 +02:00
|
|
|
- "'Failed to fetch' in apt_result['msg']"
|
2018-03-15 17:32:25 +01:00
|
|
|
- "'403' in apt_result['msg']"
|
|
|
|
|
|
|
|
- name: Clean up
|
|
|
|
file:
|
|
|
|
name: /etc/apt/sources.list.d/non-existing.list
|
|
|
|
state: absent
|
|
|
|
|
2018-03-23 12:23:12 +01:00
|
|
|
# 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:
|
2019-10-23 21:02:25 +02:00
|
|
|
name: "{{ pkgs }}"
|
2018-03-23 12:23:12 +01:00
|
|
|
state: absent
|
2019-10-23 21:02:25 +02:00
|
|
|
vars:
|
|
|
|
pkgs:
|
|
|
|
- libcaca-dev
|
|
|
|
- libslang2-dev
|
2018-04-20 07:57:14 +02:00
|
|
|
|
|
|
|
# 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
|
2018-11-19 15:45:48 +01:00
|
|
|
|
2019-08-30 21:57:58 +02:00
|
|
|
# check policy_rc_d parameter
|
2018-11-19 15:45:48 +01:00
|
|
|
|
|
|
|
- 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
|