Path: blob/devel/test/integration/targets/apt/tasks/apt.yml
4752 views
- name: use python-apt1set_fact:2python_apt: python-apt3when: ansible_python_version is version('3', '<')45- name: use python3-apt6set_fact:7python_apt: python3-apt8when: ansible_python_version is version('3', '>=')910- name: use Debian mirror11set_fact:12distro_mirror: http://ftp.debian.org/debian13when: ansible_distribution == 'Debian'1415- name: use Ubuntu mirror16set_fact:17distro_mirror: http://archive.ubuntu.com/ubuntu18when: ansible_distribution == 'Ubuntu'1920# UNINSTALL 'python-apt'21# The `apt` module has the smarts to auto-install `python-apt`. To test, we22# will first uninstall `python-apt`.23- name: check {{ python_apt }} with dpkg24shell: dpkg -s {{ python_apt }}25register: dpkg_result26ignore_errors: true2728- name: uninstall {{ python_apt }} with apt29apt: pkg={{ python_apt }} state=absent purge=yes30register: apt_result31when: dpkg_result is successful3233# In check mode, auto-install of `python-apt` must fail34- name: test fail uninstall hello without required apt deps in check mode35apt:36pkg: hello37state: absent38purge: yes39register: apt_result40check_mode: yes41ignore_errors: yes4243- name: verify fail uninstall hello without required apt deps in check mode44assert:45that:46- apt_result is failed47- '"If run normally this module can auto-install it." in apt_result.msg'4849- name: check {{ python_apt }} with dpkg50shell: dpkg -s {{ python_apt }}51register: dpkg_result52ignore_errors: true5354# UNINSTALL 'hello'55# With 'python-apt' uninstalled, the first call to 'apt' should install56# python-apt without updating the cache.57- name: uninstall hello with apt and prevent updating the cache58apt:59pkg: hello60state: absent61purge: yes62update_cache: no63register: apt_result6465- name: check hello with dpkg66shell: dpkg-query -l hello67failed_when: False68register: dpkg_result6970- name: verify uninstall hello with apt and prevent updating the cache71assert:72that:73- "'changed' in apt_result"74- apt_result is not changed75- "dpkg_result.rc == 1"76- "'Auto-installing missing dependency without updating cache: {{ python_apt }}' in apt_result.warnings"7778- name: uninstall {{ python_apt }} with apt again79apt:80pkg: "{{ python_apt }}"81state: absent82purge: yes8384# UNINSTALL 'hello'85# With 'python-apt' uninstalled, the first call to 'apt' should install86# python-apt.87- name: uninstall hello with apt88apt: pkg=hello state=absent purge=yes89register: apt_result90until: apt_result is success9192- name: check hello with dpkg93shell: dpkg-query -l hello94failed_when: False95register: dpkg_result9697- name: verify uninstallation of hello98assert:99that:100- "'changed' in apt_result"101- apt_result is not changed102- "dpkg_result.rc == 1"103- "'Updating cache and auto-installing missing dependency: {{ python_apt }}' in apt_result.warnings"104105# UNINSTALL AGAIN106- name: uninstall hello with apt107apt: pkg=hello state=absent purge=yes108register: apt_result109110- name: verify no change on re-uninstall111assert:112that:113- "not apt_result.changed"114115# INSTALL116- name: install hello with apt117apt: name=hello state=present118register: apt_result119120- name: check hello with dpkg121shell: dpkg-query -l hello122failed_when: False123register: dpkg_result124125- name: verify installation of hello126assert:127that:128- "apt_result.changed"129- "dpkg_result.rc == 0"130131- name: verify apt module outputs132assert:133that:134- "'changed' in apt_result"135- "'stderr' in apt_result"136- "'stdout' in apt_result"137- "'stdout_lines' in apt_result"138139# INSTALL AGAIN140- name: install hello with apt141apt: name=hello state=present142register: apt_result143144- name: verify no change on re-install145assert:146that:147- "not apt_result.changed"148149# UNINSTALL AGAIN150- name: uninstall hello with apt151apt: pkg=hello state=absent purge=yes152register: apt_result153154# INSTALL WITH VERSION WILDCARD155- name: install hello with apt156apt: name=hello=2.* state=present157register: apt_result158159- name: check hello with wildcard with dpkg160shell: dpkg-query -l hello161failed_when: False162register: dpkg_result163164- name: verify installation of hello165assert:166that:167- "apt_result.changed"168- "dpkg_result.rc == 0"169170- name: check hello version171shell: dpkg -s hello | grep Version | awk '{print $2}'172register: hello_version173174- name: check hello architecture175shell: dpkg -s hello | grep Architecture | awk '{print $2}'176register: hello_architecture177178- name: uninstall hello with apt179apt: pkg=hello state=absent purge=yes180181- name: install deb file182apt: deb="/var/cache/apt/archives/hello_{{ hello_version.stdout }}_{{ hello_architecture.stdout }}.deb"183register: apt_initial184185- name: install deb file again186apt: deb="/var/cache/apt/archives/hello_{{ hello_version.stdout }}_{{ hello_architecture.stdout }}.deb"187register: apt_secondary188189- name: verify installation of hello190assert:191that:192- "apt_initial.changed"193- "not apt_secondary.changed"194195- name: uninstall hello with apt196apt: pkg=hello state=absent purge=yes197198- name: install deb file from URL199apt: deb="{{ distro_mirror }}/pool/main/h/hello/hello_{{ hello_version.stdout }}_{{ hello_architecture.stdout }}.deb"200register: apt_url201202- name: verify installation of hello203assert:204that:205- "apt_url.changed"206207- name: uninstall hello with apt208apt: pkg=hello state=absent purge=yes209210- name: force install of deb211apt: deb="/var/cache/apt/archives/hello_{{ hello_version.stdout }}_{{ hello_architecture.stdout }}.deb" force=true212register: dpkg_force213214- name: verify installation of hello215assert:216that:217- "dpkg_force.changed"218219# NEGATIVE: upgrade all packages while providing additional packages to install220- name: provide additional packages to install while upgrading all installed packages221apt: pkg=*,test state=latest222ignore_errors: True223register: apt_result224225- name: verify failure of upgrade packages and install226assert:227that:228- "not apt_result.changed"229- "apt_result.failed"230231- name: autoclean during install232apt: pkg=hello state=present autoclean=yes233234# https://github.com/ansible/ansible/issues/23155235- name: create a repo file236copy:237dest: /etc/apt/sources.list.d/non-existing.list238content: deb http://ppa.launchpad.net/non-existing trusty main239240- name: test for sane error message241apt:242update_cache: yes243register: apt_result244ignore_errors: yes245246- name: verify sane error message247assert:248that:249- "'Failed to fetch' in apt_result['msg']"250- "'403' in apt_result['msg']"251252- name: Clean up253file:254name: /etc/apt/sources.list.d/non-existing.list255state: absent256257# https://github.com/ansible/ansible/issues/28907258- name: Install parent package259apt:260name: libcaca-dev261262- name: Install child package263apt:264name: libslang2-dev265266- shell: apt-mark showmanual | grep libcaca-dev267ignore_errors: yes268register: parent_output269270- name: Check that parent package is marked as installed manually271assert:272that:273- "'libcaca-dev' in parent_output.stdout"274275- shell: apt-mark showmanual | grep libslang2-dev276ignore_errors: yes277register: child_output278279- name: Check that child package is marked as installed manually280assert:281that:282- "'libslang2-dev' in child_output.stdout"283284- name: Clean up285apt:286name: "{{ pkgs }}"287state: absent288vars:289pkgs:290- libcaca-dev291- libslang2-dev292293# https://github.com/ansible/ansible/issues/38995294- name: build-dep for a package295apt:296name: tree297state: build-dep298register: apt_result299300- name: Check the result301assert:302that:303- apt_result is changed304305- name: build-dep for a package (idempotency)306apt:307name: tree308state: build-dep309register: apt_result310311- name: Check the result312assert:313that:314- apt_result is not changed315316# check policy_rc_d parameter317318- name: Install unscd but forbid service start319apt:320name: unscd321policy_rc_d: 101322323- name: Stop unscd service324service:325name: unscd326state: stopped327register: service_unscd_stop328329- name: unscd service shouldn't have been stopped by previous task330assert:331that: service_unscd_stop is not changed332333- name: Uninstall unscd334apt:335name: unscd336policy_rc_d: 101337338- name: Create incorrect /usr/sbin/policy-rc.d339copy:340dest: /usr/sbin/policy-rc.d341content: apt integration test342mode: 0755343344- name: Install unscd but forbid service start345apt:346name: unscd347policy_rc_d: 101348349- name: Stop unscd service350service:351name: unscd352state: stopped353register: service_unscd_stop354355- name: unscd service shouldn't have been stopped by previous task356assert:357that: service_unscd_stop is not changed358359- name: Create incorrect /usr/sbin/policy-rc.d360copy:361dest: /usr/sbin/policy-rc.d362content: apt integration test363mode: 0755364register: policy_rc_d365366- name: Check if /usr/sbin/policy-rc.d was correctly backed-up during unscd install367assert:368that: policy_rc_d is not changed369370- name: Delete /usr/sbin/policy-rc.d371file:372path: /usr/sbin/policy-rc.d373state: absent374375376