2016-09-14 22:38:27 +00:00
|
|
|
- name: show python version
|
|
|
|
debug: var=ansible_python_version
|
2015-01-08 03:44:31 +00:00
|
|
|
|
2016-09-14 22:38:27 +00:00
|
|
|
- name: use python-apt
|
|
|
|
set_fact:
|
|
|
|
python_apt: python-apt
|
2017-11-27 22:58:08 +00:00
|
|
|
when: ansible_python_version is version('3', '<')
|
2016-09-14 22:38:27 +00:00
|
|
|
|
|
|
|
- name: use python3-apt
|
|
|
|
set_fact:
|
|
|
|
python_apt: python3-apt
|
2017-11-27 22:58:08 +00:00
|
|
|
when: ansible_python_version is version('3', '>=')
|
2015-01-08 03:44:31 +00:00
|
|
|
|
2014-03-17 14:41:02 +00:00
|
|
|
# UNINSTALL 'python-apt'
|
|
|
|
# The `apt` module has the smarts to auto-install `python-apt`. To test, we
|
|
|
|
# will first uninstall `python-apt`.
|
2016-09-14 22:38:27 +00:00
|
|
|
- name: check {{ python_apt }} with dpkg
|
|
|
|
shell: dpkg -s {{ python_apt }}
|
2014-03-17 14:41:02 +00:00
|
|
|
register: dpkg_result
|
|
|
|
ignore_errors: true
|
|
|
|
|
2016-09-14 22:38:27 +00:00
|
|
|
- name: uninstall {{ python_apt }} with apt
|
|
|
|
apt: pkg={{ python_apt }} state=absent purge=yes
|
2014-03-17 14:41:02 +00:00
|
|
|
register: apt_result
|
2017-11-27 22:58:08 +00:00
|
|
|
when: dpkg_result is successful
|
2014-03-17 14:41:02 +00:00
|
|
|
|
|
|
|
# UNINSTALL 'hello'
|
|
|
|
# With 'python-apt' uninstalled, the first call to 'apt' should install
|
|
|
|
# python-apt.
|
2014-02-23 10:46:39 +00:00
|
|
|
- name: uninstall hello with apt
|
|
|
|
apt: pkg=hello state=absent purge=yes
|
2014-02-20 19:55:55 +00:00
|
|
|
register: apt_result
|
|
|
|
|
2014-02-23 10:46:39 +00:00
|
|
|
- name: check hello with dpkg
|
2016-04-23 20:43:11 +00:00
|
|
|
shell: dpkg-query -l hello
|
2014-02-20 19:55:55 +00:00
|
|
|
failed_when: False
|
|
|
|
register: dpkg_result
|
|
|
|
|
2014-02-23 10:46:39 +00:00
|
|
|
- name: verify uninstallation of hello
|
2014-02-20 19:55:55 +00:00
|
|
|
assert:
|
2014-02-23 10:46:39 +00:00
|
|
|
that:
|
2014-02-20 19:55:55 +00:00
|
|
|
- "'changed' in apt_result"
|
|
|
|
- "dpkg_result.rc == 1"
|
|
|
|
|
2014-02-20 20:01:23 +00:00
|
|
|
# UNINSTALL AGAIN
|
2014-02-23 10:46:39 +00:00
|
|
|
- name: uninstall hello with apt
|
|
|
|
apt: pkg=hello state=absent purge=yes
|
2014-02-20 20:01:23 +00:00
|
|
|
register: apt_result
|
|
|
|
|
|
|
|
- name: verify no change on re-uninstall
|
|
|
|
assert:
|
2014-02-23 10:46:39 +00:00
|
|
|
that:
|
2014-02-20 20:01:23 +00:00
|
|
|
- "not apt_result.changed"
|
|
|
|
|
2014-02-20 19:55:55 +00:00
|
|
|
# INSTALL
|
2014-02-23 10:46:39 +00:00
|
|
|
- name: install hello with apt
|
|
|
|
apt: name=hello state=present
|
2014-02-20 19:55:55 +00:00
|
|
|
register: apt_result
|
|
|
|
|
2014-02-23 10:46:39 +00:00
|
|
|
- name: check hello with dpkg
|
2016-04-23 20:43:11 +00:00
|
|
|
shell: dpkg-query -l hello
|
2014-02-20 19:55:55 +00:00
|
|
|
failed_when: False
|
|
|
|
register: dpkg_result
|
|
|
|
|
|
|
|
- debug: var=apt_result
|
|
|
|
- debug: var=dpkg_result
|
|
|
|
|
2014-02-23 10:46:39 +00:00
|
|
|
- name: verify installation of hello
|
2014-02-20 19:55:55 +00:00
|
|
|
assert:
|
2014-02-23 10:46:39 +00:00
|
|
|
that:
|
2014-02-20 19:55:55 +00: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 10:46:39 +00:00
|
|
|
- "'stdout' in apt_result"
|
|
|
|
- "'stdout_lines' in apt_result"
|
2014-02-20 20:01:23 +00:00
|
|
|
|
|
|
|
# INSTALL AGAIN
|
2014-02-23 10:46:39 +00:00
|
|
|
- name: install hello with apt
|
|
|
|
apt: name=hello state=present
|
2014-02-20 20:01:23 +00:00
|
|
|
register: apt_result
|
|
|
|
|
|
|
|
- name: verify no change on re-install
|
|
|
|
assert:
|
2014-02-23 10:46:39 +00:00
|
|
|
that:
|
2014-02-20 20:01:23 +00:00
|
|
|
- "not apt_result.changed"
|
|
|
|
|
2014-09-05 06:40:27 +00: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 18:02:21 +00:00
|
|
|
apt: name=hello=2.* state=present
|
2014-09-05 06:40:27 +00:00
|
|
|
register: apt_result
|
|
|
|
|
|
|
|
- name: check hello with wildcard with dpkg
|
2016-04-23 20:43:11 +00:00
|
|
|
shell: dpkg-query -l hello
|
2014-09-05 06:40:27 +00:00
|
|
|
failed_when: False
|
|
|
|
register: dpkg_result
|
|
|
|
|
|
|
|
- debug: var=apt_result
|
|
|
|
- debug: var=dpkg_result
|
|
|
|
|
|
|
|
- name: verify installation of hello
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- "apt_result.changed"
|
|
|
|
- "dpkg_result.rc == 0"
|
2014-02-23 10:46:39 +00:00
|
|
|
|
2015-01-08 03:44:31 +00:00
|
|
|
- name: check hello version
|
2016-04-23 20:43:11 +00:00
|
|
|
shell: dpkg -s hello | grep Version | awk '{print $2}'
|
2015-01-08 03:44:31 +00:00
|
|
|
register: hello_version
|
2017-06-19 12:57:26 +00:00
|
|
|
|
2015-01-08 03:44:31 +00:00
|
|
|
- name: check hello architecture
|
2016-04-23 20:43:11 +00:00
|
|
|
shell: dpkg -s hello | grep Architecture | awk '{print $2}'
|
2015-01-08 03:44:31 +00:00
|
|
|
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: 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-24 23:04:38 +00: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 19:52:41 +00:00
|
|
|
|
2018-05-09 10:27:04 +00: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:
|
|
|
|
name: "{{ item }}"
|
|
|
|
state: absent
|
|
|
|
with_items:
|
|
|
|
- libcaca-dev
|
|
|
|
- libslang2-dev
|
|
|
|
|
2018-05-15 15:43:48 +00: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:
|
|
|
|
- "'E: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
|
|
|
|
|
2017-05-25 19:52:41 +00:00
|
|
|
- name: autoclean during install
|
|
|
|
apt: pkg=hello state=present autoclean=yes
|
|
|
|
|
|
|
|
- name: autoclean
|
|
|
|
apt: autoclean=yes
|
|
|
|
|
|
|
|
- name: autoremove
|
|
|
|
apt: autoremove=yes
|