diff options
Diffstat (limited to '')
-rw-r--r-- | test/integration/targets/yum/tasks/cacheonly.yml | 16 | ||||
-rw-r--r-- | test/integration/targets/yum/tasks/check_mode_consistency.yml | 61 | ||||
-rw-r--r-- | test/integration/targets/yum/tasks/lock.yml | 28 | ||||
-rw-r--r-- | test/integration/targets/yum/tasks/main.yml | 82 | ||||
-rw-r--r-- | test/integration/targets/yum/tasks/multiarch.yml | 154 | ||||
-rw-r--r-- | test/integration/targets/yum/tasks/proxy.yml | 186 | ||||
-rw-r--r-- | test/integration/targets/yum/tasks/repo.yml | 729 | ||||
-rw-r--r-- | test/integration/targets/yum/tasks/yum.yml | 884 | ||||
-rw-r--r-- | test/integration/targets/yum/tasks/yum_group_remove.yml | 152 | ||||
-rw-r--r-- | test/integration/targets/yum/tasks/yuminstallroot.yml | 132 |
10 files changed, 2424 insertions, 0 deletions
diff --git a/test/integration/targets/yum/tasks/cacheonly.yml b/test/integration/targets/yum/tasks/cacheonly.yml new file mode 100644 index 0000000..03cbd0e --- /dev/null +++ b/test/integration/targets/yum/tasks/cacheonly.yml @@ -0,0 +1,16 @@ +--- +- name: Test cacheonly (clean before testing) + command: yum clean all + +- name: Try installing from cache where it has been cleaned + yum: + name: sos + state: latest + cacheonly: true + register: yum_result + ignore_errors: true + +- name: Verify yum failure + assert: + that: + - "yum_result is failed" diff --git a/test/integration/targets/yum/tasks/check_mode_consistency.yml b/test/integration/targets/yum/tasks/check_mode_consistency.yml new file mode 100644 index 0000000..e2a99d9 --- /dev/null +++ b/test/integration/targets/yum/tasks/check_mode_consistency.yml @@ -0,0 +1,61 @@ +- name: install htop in check mode to verify changes dict returned + yum: + name: htop + state: present + check_mode: yes + register: yum_changes_check_mode_result + +- name: install verify changes dict returned in check mode + assert: + that: + - "yum_changes_check_mode_result is success" + - "yum_changes_check_mode_result is changed" + - "'changes' in yum_changes_check_mode_result" + - "'installed' in yum_changes_check_mode_result['changes']" + - "'htop' in yum_changes_check_mode_result['changes']['installed']" + +- name: install htop to verify changes dict returned + yum: + name: htop + state: present + register: yum_changes_result + +- name: install verify changes dict returned + assert: + that: + - "yum_changes_result is success" + - "yum_changes_result is changed" + - "'changes' in yum_changes_result" + - "'installed' in yum_changes_result['changes']" + - "'htop' in yum_changes_result['changes']['installed']" + +- name: remove htop in check mode to verify changes dict returned + yum: + name: htop + state: absent + check_mode: yes + register: yum_changes_check_mode_result + +- name: remove verify changes dict returned in check mode + assert: + that: + - "yum_changes_check_mode_result is success" + - "yum_changes_check_mode_result is changed" + - "'changes' in yum_changes_check_mode_result" + - "'removed' in yum_changes_check_mode_result['changes']" + - "'htop' in yum_changes_check_mode_result['changes']['removed']" + +- name: remove htop to verify changes dict returned + yum: + name: htop + state: absent + register: yum_changes_result + +- name: remove verify changes dict returned + assert: + that: + - "yum_changes_result is success" + - "yum_changes_result is changed" + - "'changes' in yum_changes_result" + - "'removed' in yum_changes_result['changes']" + - "'htop' in yum_changes_result['changes']['removed']" diff --git a/test/integration/targets/yum/tasks/lock.yml b/test/integration/targets/yum/tasks/lock.yml new file mode 100644 index 0000000..3f585c1 --- /dev/null +++ b/test/integration/targets/yum/tasks/lock.yml @@ -0,0 +1,28 @@ +- block: + - name: Make sure testing package is not installed + yum: + name: sos + state: absent + + - name: Create bogus lock file + copy: + content: bogus content for this lock file + dest: /var/run/yum.pid + + - name: Install a package, lock file should be deleted by the module + yum: + name: sos + state: present + register: yum_result + + - assert: + that: + - yum_result is success + + always: + - name: Clean up + yum: + name: sos + state: absent + + when: ansible_pkg_mgr == 'yum' diff --git a/test/integration/targets/yum/tasks/main.yml b/test/integration/targets/yum/tasks/main.yml new file mode 100644 index 0000000..157124a --- /dev/null +++ b/test/integration/targets/yum/tasks/main.yml @@ -0,0 +1,82 @@ +# (c) 2014, James Tanner <tanner.jc@gmail.com> +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +# Note: We install the yum package onto Fedora so that this will work on dnf systems +# We want to test that for people who don't want to upgrade their systems. + +- block: + - name: ensure test packages are removed before starting + yum: + name: + - sos + state: absent + + - import_tasks: yum.yml + always: + - name: remove installed packages + yum: + name: + - sos + state: absent + + - name: remove installed group + yum: + name: "@Custom Group" + state: absent + + - name: On Fedora 28 the above won't remove the group which results in a failure in repo.yml below + yum: + name: dinginessentail + state: absent + when: + - ansible_distribution in ['Fedora'] + + when: + - ansible_distribution in ['RedHat', 'CentOS', 'ScientificLinux', 'Fedora'] + + +- block: + - import_tasks: repo.yml + - import_tasks: yum_group_remove.yml + when: + - ansible_distribution in ['RedHat', 'CentOS', 'ScientificLinux'] + always: + - yum_repository: + name: "{{ item }}" + state: absent + loop: "{{ repos }}" + + - command: yum clean metadata + when: + - ansible_distribution in ['RedHat', 'CentOS', 'ScientificLinux', 'Fedora'] + + +- import_tasks: yuminstallroot.yml + when: + - ansible_distribution in ['RedHat', 'CentOS', 'ScientificLinux', 'Fedora'] + + +- import_tasks: proxy.yml + when: + - ansible_distribution in ['RedHat', 'CentOS', 'ScientificLinux', 'Fedora'] + + +- import_tasks: check_mode_consistency.yml + when: + - (ansible_distribution in ['RedHat', 'CentOS', 'ScientificLinux'] and ansible_distribution_major_version|int == 7) + + +- import_tasks: lock.yml + when: + - ansible_distribution in ['RedHat', 'CentOS', 'ScientificLinux'] + +- import_tasks: multiarch.yml + when: + - ansible_distribution in ['RedHat', 'CentOS', 'ScientificLinux'] + - ansible_architecture == 'x86_64' + # Our output parsing expects us to be on yum, not dnf + - ansible_distribution_major_version is version('7', '<=') + +- import_tasks: cacheonly.yml + when: + - ansible_distribution in ['RedHat', 'CentOS', 'ScientificLinux', 'Fedora'] diff --git a/test/integration/targets/yum/tasks/multiarch.yml b/test/integration/targets/yum/tasks/multiarch.yml new file mode 100644 index 0000000..bced634 --- /dev/null +++ b/test/integration/targets/yum/tasks/multiarch.yml @@ -0,0 +1,154 @@ +- block: + - name: Set up test yum repo + yum_repository: + name: multiarch-test-repo + description: ansible-test multiarch test repo + baseurl: "{{ multiarch_repo_baseurl }}" + gpgcheck: no + repo_gpgcheck: no + + - name: Install two out of date packages from the repo + yum: + name: + - multiarch-a-1.0 + - multiarch-b-1.0 + register: outdated + + - name: See what we installed + command: rpm -q multiarch-a multiarch-b + register: rpm_q + + # Here we assume we're running on x86_64 (and limit to this in main.yml) + # (avoid comparing ansible_architecture because we only have test RPMs + # for i686 and x86_64 and ansible_architecture could be other things.) + - name: Assert that we got the right architecture + assert: + that: + - outdated is changed + - outdated.changes.installed | length == 2 + - rpm_q.stdout_lines | length == 2 + - rpm_q.stdout_lines[0].endswith('x86_64') + - rpm_q.stdout_lines[1].endswith('x86_64') + + - name: Install the same versions, but i686 instead + yum: + name: + - multiarch-a-1.0*.i686 + - multiarch-b-1.0*.i686 + register: outdated_i686 + + - name: See what we installed + command: rpm -q multiarch-a multiarch-b + register: rpm_q + + - name: Assert that all four are installed + assert: + that: + - outdated_i686 is changed + - outdated.changes.installed | length == 2 + - rpm_q.stdout_lines | length == 4 + + - name: Update them all to 2.0 + yum: + name: multiarch-* + state: latest + update_only: true + register: yum_latest + + - name: Assert that all were updated and shown in results + assert: + that: + - yum_latest is changed + # This is just testing UI stability. The behavior is arguably not + # correct, because multiple packages are being updated. But the + # "because of (at least)..." wording kinda locks us in to only + # showing one update in this case. :( + - yum_latest.changes.updated | length == 1 + + - name: Downgrade them so we can upgrade them a different way + yum: + name: + - multiarch-a-1.0* + - multiarch-b-1.0* + allow_downgrade: true + register: downgrade + + - name: See what we installed + command: rpm -q multiarch-a multiarch-b --queryformat '%{name}-%{version}.%{arch}\n' + register: rpm_q + + - name: Ensure downgrade worked + assert: + that: + - downgrade is changed + - rpm_q.stdout_lines | sort == ['multiarch-a-1.0.i686', 'multiarch-a-1.0.x86_64', 'multiarch-b-1.0.i686', 'multiarch-b-1.0.x86_64'] + + # This triggers a different branch of logic that the partial wildcard + # above, but we're limited to check_mode here since it's '*'. + - name: Upgrade with full wildcard + yum: + name: '*' + state: latest + update_only: true + update_cache: true + check_mode: true + register: full_wildcard + + # https://github.com/ansible/ansible/issues/73284 + - name: Ensure we report things correctly (both arches) + assert: + that: + - full_wildcard is changed + - full_wildcard.changes.updated | filter_list_of_tuples_by_first_param('multiarch', startswith=True) | length == 4 + + - name: Downgrade them so we can upgrade them a different way + yum: + name: + - multiarch-a-1.0* + - multiarch-b-1.0* + allow_downgrade: true + register: downgrade + + - name: Try to install again via virtual provides, should be unchanged + yum: + name: + - virtual-provides-multiarch-a + - virtual-provides-multiarch-b + state: present + register: install_vp + + - name: Ensure the above did not change + assert: + that: + - install_vp is not changed + + - name: Try to upgrade via virtual provides + yum: + name: + - virtual-provides-multiarch-a + - virtual-provides-multiarch-b + state: latest + update_only: true + register: upgrade_vp + + - name: Ensure we report things correctly (both arches) + assert: + that: + - upgrade_vp is changed + # This is just testing UI stability, like above. + # We'll only have one package in "updated" per spec, even though + # (in this case) two are getting updated per spec. + - upgrade_vp.changes.updated | length == 2 + + always: + - name: Remove test yum repo + yum_repository: + name: multiarch-test-repo + state: absent + + - name: Remove all test packages installed + yum: + name: + - multiarch-* + - virtual-provides-multiarch-* + state: absent diff --git a/test/integration/targets/yum/tasks/proxy.yml b/test/integration/targets/yum/tasks/proxy.yml new file mode 100644 index 0000000..b011d11 --- /dev/null +++ b/test/integration/targets/yum/tasks/proxy.yml @@ -0,0 +1,186 @@ +- name: test yum proxy settings + block: + - name: install tinyproxy + yum: + name: 'https://ci-files.testing.ansible.com/test/integration/targets/yum/tinyproxy-1.10.0-3.el7.x86_64.rpm' + state: installed + + # systemd doesn't play nice with this in a container for some reason + - name: start tinyproxy (systemd with tiny proxy does not work in container) + shell: tinyproxy + changed_when: false + + # test proxy without auth + - name: set unauthenticated proxy in yum.conf + lineinfile: + path: /etc/yum.conf + line: "proxy=http://127.0.0.1:8888" + state: present + + - name: clear proxy logs + shell: ': > /var/log/tinyproxy/tinyproxy.log' + changed_when: false + args: + executable: /usr/bin/bash + + - name: install ninvaders with unauthenticated proxy + yum: + name: 'https://ci-files.testing.ansible.com/test/integration/targets/yum/ninvaders-0.1.1-18.el7.x86_64.rpm' + state: installed + register: yum_proxy_result + + - assert: + that: + - "yum_proxy_result.changed" + - "'msg' in yum_proxy_result" + - "'rc' in yum_proxy_result" + + - name: check that it install via unauthenticated proxy + command: grep -q Request /var/log/tinyproxy/tinyproxy.log + + - name: uninstall ninvaders with unauthenticated proxy + yum: + name: ninvaders + state: absent + register: yum_proxy_result + + - assert: + that: + - "yum_proxy_result.changed" + - "'msg' in yum_proxy_result" + - "'rc' in yum_proxy_result" + + - name: unset unauthenticated proxy in yum.conf + lineinfile: + path: /etc/yum.conf + line: "proxy=http://127.0.0.1:8888" + state: absent + + # test proxy with auth + - name: set authenticated proxy config in tinyproxy.conf + lineinfile: + path: /etc/tinyproxy/tinyproxy.conf + line: "BasicAuth 1testuser 1testpassword" + state: present + + # systemd doesn't play nice with this in a container for some reason + - name: SIGHUP tinyproxy to reload config (workaround because of systemd+tinyproxy in container) + shell: kill -HUP $(ps -ef | grep tinyproxy | grep -v grep | awk '{print $2}') + changed_when: false + args: + executable: /usr/bin/bash + + - name: set authenticated proxy config in yum.conf + lineinfile: + path: /etc/yum.conf + line: "proxy=http://1testuser:1testpassword@127.0.0.1:8888" + state: present + + - name: clear proxy logs + shell: ': > /var/log/tinyproxy/tinyproxy.log' + changed_when: false + args: + executable: /usr/bin/bash + + - name: install ninvaders with authenticated proxy + yum: + name: 'https://ci-files.testing.ansible.com/test/integration/targets/yum/ninvaders-0.1.1-18.el7.x86_64.rpm' + state: installed + register: yum_proxy_result + + - assert: + that: + - "yum_proxy_result.changed" + - "'msg' in yum_proxy_result" + - "'rc' in yum_proxy_result" + + - name: check that it install via authenticated proxy + command: grep -q Request /var/log/tinyproxy/tinyproxy.log + + - name: uninstall ninvaders with authenticated proxy + yum: + name: ninvaders + state: absent + + - name: unset authenticated proxy config in yum.conf + lineinfile: + path: /etc/yum.conf + line: "proxy=http://1testuser:1testpassword@127.0.0.1:8888" + state: absent + + - name: set proxy config in yum.conf + lineinfile: + path: /etc/yum.conf + line: "proxy=http://127.0.0.1:8888" + state: present + + - name: set proxy_username config in yum.conf + lineinfile: + path: /etc/yum.conf + line: "proxy_username=1testuser" + state: present + + - name: set proxy_password config in yum.conf + lineinfile: + path: /etc/yum.conf + line: "proxy_password=1testpassword" + state: present + + - name: clear proxy logs + shell: ': > /var/log/tinyproxy/tinyproxy.log' + changed_when: false + args: + executable: /usr/bin/bash + + - name: install ninvaders with proxy, proxy_username, and proxy_password config in yum.conf + yum: + name: 'https://ci-files.testing.ansible.com/test/integration/targets/yum/ninvaders-0.1.1-18.el7.x86_64.rpm' + state: installed + register: yum_proxy_result + + - assert: + that: + - "yum_proxy_result.changed" + - "'msg' in yum_proxy_result" + - "'rc' in yum_proxy_result" + + - name: check that it install via proxy with proxy_username, proxy_password config in yum.conf + command: grep -q Request /var/log/tinyproxy/tinyproxy.log + + always: + #cleanup + - name: uninstall tinyproxy + yum: + name: tinyproxy + state: absent + + - name: uninstall ninvaders + yum: + name: ninvaders + state: absent + + - name: ensure unset authenticated proxy + lineinfile: + path: /etc/yum.conf + line: "proxy=http://1testuser:1testpassword@127.0.0.1:8888" + state: absent + + - name: ensure unset proxy + lineinfile: + path: /etc/yum.conf + line: "proxy=http://127.0.0.1:8888" + state: absent + + - name: ensure unset proxy_username + lineinfile: + path: /etc/yum.conf + line: "proxy_username=1testuser" + state: absent + + - name: ensure unset proxy_password + lineinfile: + path: /etc/yum.conf + line: "proxy_password=1testpassword" + state: absent + when: + - (ansible_distribution in ['RedHat', 'CentOS', 'ScientificLinux'] and ansible_distribution_major_version|int == 7 and ansible_architecture in ['x86_64']) diff --git a/test/integration/targets/yum/tasks/repo.yml b/test/integration/targets/yum/tasks/repo.yml new file mode 100644 index 0000000..f312b1c --- /dev/null +++ b/test/integration/targets/yum/tasks/repo.yml @@ -0,0 +1,729 @@ +- block: + - name: Install dinginessentail-1.0-1 + yum: + name: dinginessentail-1.0-1 + state: present + register: yum_result + + - name: Check dinginessentail with rpm + shell: rpm -q dinginessentail + register: rpm_result + + - name: Verify installation + assert: + that: + - "yum_result.changed" + - "rpm_result.stdout.startswith('dinginessentail-1.0-1')" + + - name: Verify yum module outputs + assert: + that: + - "'msg' in yum_result" + - "'rc' in yum_result" + - "'results' in yum_result" + # ============================================================================ + - name: Install dinginessentail-1.0-1 again + yum: + name: dinginessentail-1.0-1 + state: present + register: yum_result + + - name: Check dinginessentail with rpm + shell: rpm -q dinginessentail + register: rpm_result + + - name: Verify installation + assert: + that: + - "not yum_result.changed" + - "rpm_result.stdout.startswith('dinginessentail-1.0-1')" + + - name: Verify yum module outputs + assert: + that: + - "'msg' in yum_result" + - "'rc' in yum_result" + - "'results' in yum_result" + # ============================================================================ + - name: Install dinginessentail-1:1.0-2 + yum: + name: "dinginessentail-1:1.0-2.{{ ansible_architecture }}" + state: present + register: yum_result + + - name: Check dinginessentail with rpm + shell: rpm -q dinginessentail + register: rpm_result + + - name: Verify installation + assert: + that: + - "yum_result.changed" + - "rpm_result.stdout.startswith('dinginessentail-1.0-2')" + + - name: Verify yum module outputs + assert: + that: + - "'msg' in yum_result" + - "'rc' in yum_result" + - "'results' in yum_result" + + - name: Remove dinginessentail + yum: + name: dinginessentail + state: absent + # ============================================================================ + - name: Downgrade dinginessentail + yum: + name: dinginessentail-1.0-1 + state: present + allow_downgrade: yes + register: yum_result + + - name: Check dinginessentail with rpm + shell: rpm -q dinginessentail + register: rpm_result + + - name: Verify installation + assert: + that: + - "yum_result.changed" + - "rpm_result.stdout.startswith('dinginessentail-1.0-1')" + + - name: Verify yum module outputs + assert: + that: + - "'msg' in yum_result" + - "'rc' in yum_result" + - "'results' in yum_result" + # ============================================================================ + - name: Update to the latest dinginessentail + yum: + name: dinginessentail + state: latest + register: yum_result + + - name: Check dinginessentail with rpm + shell: rpm -q dinginessentail + register: rpm_result + + - name: Verify installation + assert: + that: + - "yum_result.changed" + - "rpm_result.stdout.startswith('dinginessentail-1.1-1')" + + - name: Verify yum module outputs + assert: + that: + - "'msg' in yum_result" + - "'rc' in yum_result" + - "'results' in yum_result" + # ============================================================================ + - name: Install dinginessentail-1.0-1 from a file (higher version is already installed) + yum: + name: "{{ repodir }}/dinginessentail-1.0-1.{{ ansible_architecture }}.rpm" + state: present + register: yum_result + + - name: Check dinginessentail with rpm + shell: rpm -q dinginessentail + register: rpm_result + + - name: Verify installation + assert: + that: + - "not yum_result.changed" + - "rpm_result.stdout.startswith('dinginessentail-1.1-1')" + + - name: Verify yum module outputs + assert: + that: + - "'msg' in yum_result" + - "'rc' in yum_result" + - "'results' in yum_result" + + - name: Remove dinginessentail + yum: + name: dinginessentail + state: absent + # ============================================================================ + - name: Install dinginessentail-1.0-1 from a file + yum: + name: "{{ repodir }}/dinginessentail-1.0-1.{{ ansible_architecture }}.rpm" + state: present + disable_gpg_check: true + register: yum_result + + - name: Check dinginessentail with rpm + shell: rpm -q dinginessentail + register: rpm_result + + - name: Verify installation + assert: + that: + - "yum_result.changed" + - "rpm_result.stdout.startswith('dinginessentail-1.0-1')" + + - name: Verify yum module outputs + assert: + that: + - "'msg' in yum_result" + - "'rc' in yum_result" + - "'results' in yum_result" + # ============================================================================ + - name: Install dinginessentail-1.0-1 from a file again + yum: + name: "{{ repodir }}/dinginessentail-1.0-1.{{ ansible_architecture }}.rpm" + state: present + disable_gpg_check: true + register: yum_result + + - name: Check dinginessentail with rpm + shell: rpm -q dinginessentail + register: rpm_result + + - name: Verify installation + assert: + that: + - "not yum_result.changed" + - "rpm_result.stdout.startswith('dinginessentail-1.0-1')" + + - name: Verify yum module outputs + assert: + that: + - "'msg' in yum_result" + - "'rc' in yum_result" + - "'results' in yum_result" + # ============================================================================ + - name: Install dinginessentail-1.0-2 from a file + yum: + name: "{{ repodir }}/dinginessentail-1.0-2.{{ ansible_architecture }}.rpm" + state: present + disable_gpg_check: true + register: yum_result + + - name: Check dinginessentail with rpm + shell: rpm -q dinginessentail + register: rpm_result + + - name: Verify installation + assert: + that: + - "yum_result.changed" + - "rpm_result.stdout.startswith('dinginessentail-1.0-2')" + + - name: Verify yum module outputs + assert: + that: + - "'msg' in yum_result" + - "'rc' in yum_result" + - "'results' in yum_result" + # ============================================================================ + - name: Install dinginessentail-1.0-2 from a file again + yum: + name: "{{ repodir }}/dinginessentail-1.0-2.{{ ansible_architecture }}.rpm" + state: present + disable_gpg_check: true + register: yum_result + + - name: Check dinginessentail with rpm + shell: rpm -q dinginessentail + register: rpm_result + + - name: Verify installation + assert: + that: + - "not yum_result.changed" + - "rpm_result.stdout.startswith('dinginessentail-1.0-2')" + + - name: Verify yum module outputs + assert: + that: + - "'msg' in yum_result" + - "'rc' in yum_result" + - "'results' in yum_result" + # ============================================================================ + - name: Try to downgrade dinginessentail without allow_downgrade being set + yum: + name: dinginessentail-1.0-1 + state: present + allow_downgrade: no + register: yum_result + + - name: Check dinginessentail with rpm + shell: rpm -q dinginessentail + register: rpm_result + + - name: Verify installation + assert: + that: + - "not yum_result.changed" + - "rpm_result.stdout.startswith('dinginessentail-1.0-2')" + + - name: Verify yum module outputs + assert: + that: + - "'msg' in yum_result" + - "'rc' in yum_result" + - "'results' in yum_result" + # ============================================================================ + - name: Update dinginessentail with update_only set + yum: + name: dinginessentail + state: latest + update_only: yes + register: yum_result + + - name: Check dinginessentail with rpm + shell: rpm -q dinginessentail + register: rpm_result + + - name: Verify installation + assert: + that: + - "yum_result.changed" + - "rpm_result.stdout.startswith('dinginessentail-1.1-1')" + + - name: Verify yum module outputs + assert: + that: + - "'msg' in yum_result" + - "'rc' in yum_result" + - "'results' in yum_result" + + - name: Remove dinginessentail + yum: + name: dinginessentail + state: absent + # ============================================================================ + - name: Try to update dinginessentail which is not installed, update_only is set + yum: + name: dinginessentail + state: latest + update_only: yes + register: yum_result + ignore_errors: yes + + - name: Check dinginessentail with rpm + shell: rpm -q dinginessentail + register: rpm_result + ignore_errors: yes + + - name: Verify installation + assert: + that: + - "rpm_result.rc == 1" + - "yum_result.rc == 0" + - "not yum_result.changed" + - "not yum_result is failed" + + - name: Verify yum module outputs + assert: + that: + - "'msg' in yum_result" + - "'rc' in yum_result" + - "'results' in yum_result" + # ============================================================================ + - name: Try to install incompatible arch + yum: + name: "{{ repodir_ppc64 }}/dinginessentail-1.0-1.ppc64.rpm" + state: present + register: yum_result + ignore_errors: yes + + - name: Check dinginessentail with rpm + shell: rpm -q dinginessentail + register: rpm_result + ignore_errors: yes + + - name: Verify installation + assert: + that: + - "rpm_result.rc == 1" + - "yum_result.rc == 1" + - "not yum_result.changed" + - "yum_result is failed" + + - name: Verify yum module outputs + assert: + that: + - "'msg' in yum_result" + - "'rc' in yum_result" + - "'results' in yum_result" + # ============================================================================ + - name: Make sure latest dinginessentail is installed + yum: + name: dinginessentail + state: latest + + - name: Downgrade dinginessentail using rpm file + yum: + name: "{{ repodir }}/dinginessentail-1.0-1.{{ ansible_architecture }}.rpm" + state: present + allow_downgrade: yes + disable_gpg_check: yes + register: yum_result + + - name: Check dinginessentail with rpm + shell: rpm -q dinginessentail + register: rpm_result + + - name: Verify installation + assert: + that: + - "yum_result.changed" + - "rpm_result.stdout.startswith('dinginessentail-1.0-1')" + + - name: Verify yum module outputs + assert: + that: + - "'msg' in yum_result" + - "'rc' in yum_result" + - "'results' in yum_result" + # ============================================================================ + - block: + - name: make sure dinginessentail is not installed + yum: + name: dinginessentail + state: absent + + - name: install dinginessentail both archs + yum: + name: "{{ pkgs }}" + state: present + disable_gpg_check: true + vars: + pkgs: + - "{{ repodir }}/dinginessentail-1.1-1.x86_64.rpm" + - "{{ repodir_i686 }}/dinginessentail-1.1-1.i686.rpm" + + - name: try to install lower version of dinginessentail from rpm file, without allow_downgrade, just one arch + yum: + name: "{{ repodir_i686 }}/dinginessentail-1.0-1.i686.rpm" + state: present + register: yum_result + + - name: check dinginessentail with rpm + shell: rpm -q dinginessentail + register: rpm_result + + - name: verify installation + assert: + that: + - "not yum_result.changed" + - "rpm_result.stdout_lines[0].startswith('dinginessentail-1.1-1')" + - "rpm_result.stdout_lines[1].startswith('dinginessentail-1.1-1')" + + - name: verify yum module outputs + assert: + that: + - "'msg' in yum_result" + - "'rc' in yum_result" + - "'results' in yum_result" + when: ansible_architecture == "x86_64" + # ============================================================================ + - block: + - name: make sure dinginessentail is not installed + yum: + name: dinginessentail + state: absent + + - name: install dinginessentail both archs + yum: + name: "{{ pkgs }}" + state: present + disable_gpg_check: true + vars: + pkgs: + - "{{ repodir }}/dinginessentail-1.0-1.x86_64.rpm" + - "{{ repodir_i686 }}/dinginessentail-1.0-1.i686.rpm" + + - name: Update both arch in one task using rpm files + yum: + name: "{{ repodir }}/dinginessentail-1.1-1.x86_64.rpm,{{ repodir_i686 }}/dinginessentail-1.1-1.i686.rpm" + state: present + disable_gpg_check: yes + register: yum_result + + - name: check dinginessentail with rpm + shell: rpm -q dinginessentail + register: rpm_result + + - name: verify installation + assert: + that: + - "yum_result.changed" + - "rpm_result.stdout_lines[0].startswith('dinginessentail-1.1-1')" + - "rpm_result.stdout_lines[1].startswith('dinginessentail-1.1-1')" + + - name: verify yum module outputs + assert: + that: + - "'msg' in yum_result" + - "'rc' in yum_result" + - "'results' in yum_result" + when: ansible_architecture == "x86_64" + # ============================================================================ + always: + - name: Clean up + yum: + name: dinginessentail + state: absent + +# FIXME: dnf currently doesn't support epoch as part of it's pkg_spec for +# finding install candidates +# https://bugzilla.redhat.com/show_bug.cgi?id=1619687 +- block: + - name: Install 1:dinginessentail-1.0-2 + yum: + name: "1:dinginessentail-1.0-2.{{ ansible_architecture }}" + state: present + disable_gpg_check: true + register: yum_result + + - name: Check dinginessentail with rpm + shell: rpm -q dinginessentail + register: rpm_result + + - name: Verify installation + assert: + that: + - "yum_result.changed" + - "rpm_result.stdout.startswith('dinginessentail-1.0-2')" + + - name: Verify yum module outputs + assert: + that: + - "'msg' in yum_result" + - "'rc' in yum_result" + - "'results' in yum_result" + always: + - name: Clean up + yum: + name: dinginessentail + state: absent + + when: ansible_pkg_mgr == 'yum' + +# DNF1 (Fedora < 26) had some issues: +# - did not accept architecture tag as valid component of a package spec unless +# installing a file (i.e. can't search the repo) +# - doesn't handle downgrade transactions via the API properly, marks it as a +# conflict +# +# NOTE: Both DNF1 and Fedora < 26 have long been EOL'd by their respective +# upstreams +- block: + # ============================================================================ + - name: Install dinginessentail-1.0-2 + yum: + name: "dinginessentail-1.0-2.{{ ansible_architecture }}" + state: present + disable_gpg_check: true + register: yum_result + + - name: Check dinginessentail with rpm + shell: rpm -q dinginessentail + register: rpm_result + + - name: Verify installation + assert: + that: + - "yum_result.changed" + - "rpm_result.stdout.startswith('dinginessentail-1.0-2')" + + - name: Verify yum module outputs + assert: + that: + - "'msg' in yum_result" + - "'rc' in yum_result" + - "'results' in yum_result" + + - name: Install dinginessentail-1.0-2 again + yum: + name: dinginessentail-1.0-2 + state: present + register: yum_result + + - name: Check dinginessentail with rpm + shell: rpm -q dinginessentail + register: rpm_result + + - name: Verify installation + assert: + that: + - "not yum_result.changed" + - "rpm_result.stdout.startswith('dinginessentail-1.0-2')" + + - name: Verify yum module outputs + assert: + that: + - "'msg' in yum_result" + - "'rc' in yum_result" + - "'results' in yum_result" + always: + - name: Clean up + yum: + name: dinginessentail + state: absent + when: not (ansible_distribution == "Fedora" and ansible_distribution_major_version|int < 26) + +# https://github.com/ansible/ansible/issues/47689 +- block: + - name: Install dinginessentail == 1.0 + yum: + name: "dinginessentail == 1.0" + state: present + register: yum_result + + - name: Check dinginessentail with rpm + shell: rpm -q dinginessentail + register: rpm_result + + - name: Verify installation + assert: + that: + - "yum_result.changed" + - "rpm_result.stdout.startswith('dinginessentail-1.0-1')" + + - name: Verify yum module outputs + assert: + that: + - "'msg' in yum_result" + - "'rc' in yum_result" + - "'results' in yum_result" + always: + - name: Clean up + yum: + name: dinginessentail + state: absent + + when: ansible_pkg_mgr == 'yum' + + +# https://github.com/ansible/ansible/pull/54603 +- block: + - name: Install dinginessentail < 1.1 + yum: + name: "dinginessentail < 1.1" + state: present + register: yum_result + + - name: Check dinginessentail with rpm + shell: rpm -q dinginessentail + register: rpm_result + + - name: Verify installation + assert: + that: + - "yum_result.changed" + - "rpm_result.stdout.startswith('dinginessentail-1.0')" + + - name: Install dinginessentail >= 1.1 + yum: + name: "dinginessentail >= 1.1" + state: present + register: yum_result + + - name: Check dinginessentail with rpm + shell: rpm -q dinginessentail + register: rpm_result + + - name: Verify installation + assert: + that: + - "yum_result.changed" + - "rpm_result.stdout.startswith('dinginessentail-1.1')" + + - name: Verify yum module outputs + assert: + that: + - "'msg' in yum_result" + - "'rc' in yum_result" + - "'results' in yum_result" + + always: + - name: Clean up + yum: + name: dinginessentail + state: absent + + when: ansible_pkg_mgr == 'yum' + +# https://github.com/ansible/ansible/issues/45250 +- block: + - name: Install dinginessentail-1.0, dinginessentail-olive-1.0, landsidescalping-1.0 + yum: + name: "dinginessentail-1.0,dinginessentail-olive-1.0,landsidescalping-1.0" + state: present + + - name: Upgrade dinginessentail* + yum: + name: dinginessentail* + state: latest + register: yum_result + + - name: Check dinginessentail with rpm + shell: rpm -q dinginessentail + register: rpm_result + + - name: Verify update of dinginessentail + assert: + that: + - "rpm_result.stdout.startswith('dinginessentail-1.1-1')" + + - name: Check dinginessentail-olive with rpm + shell: rpm -q dinginessentail-olive + register: rpm_result + + - name: Verify update of dinginessentail-olive + assert: + that: + - "rpm_result.stdout.startswith('dinginessentail-olive-1.1-1')" + + - name: Check landsidescalping with rpm + shell: rpm -q landsidescalping + register: rpm_result + + - name: Verify landsidescalping did NOT get updated + assert: + that: + - "rpm_result.stdout.startswith('landsidescalping-1.0-1')" + + - name: Verify yum module outputs + assert: + that: + - "yum_result is changed" + - "'msg' in yum_result" + - "'rc' in yum_result" + - "'results' in yum_result" + always: + - name: Clean up + yum: + name: dinginessentail,dinginessentail-olive,landsidescalping + state: absent + +- block: + - yum: + name: dinginessentail + state: present + + - yum: + list: dinginessentail* + register: list_out + + - set_fact: + passed: true + loop: "{{ list_out.results }}" + when: item.yumstate == 'installed' + + - name: Test that there is yumstate=installed in the result + assert: + that: + - passed is defined + always: + - name: Clean up + yum: + name: dinginessentail + state: absent diff --git a/test/integration/targets/yum/tasks/yum.yml b/test/integration/targets/yum/tasks/yum.yml new file mode 100644 index 0000000..511c577 --- /dev/null +++ b/test/integration/targets/yum/tasks/yum.yml @@ -0,0 +1,884 @@ +# Setup by setup_rpm_repo +- set_fact: + package1: dinginessentail + package2: dinginessentail-olive + +# UNINSTALL +- name: uninstall {{ package1 }} + yum: name={{ package1 }} state=removed + register: yum_result + +- name: check {{ package1 }} with rpm + shell: rpm -q {{ package1 }} + ignore_errors: True + register: rpm_result + +- name: verify uninstallation of {{ package1 }} + assert: + that: + - "yum_result is success" + - "rpm_result is failed" + +# UNINSTALL AGAIN +- name: uninstall {{ package1 }} again in check mode + yum: name={{ package1 }} state=removed + check_mode: true + register: yum_result + +- name: verify no change on re-uninstall in check mode + assert: + that: + - "not yum_result is changed" + +- name: uninstall {{ package1 }} again + yum: name={{ package1 }} state=removed + register: yum_result + +- name: verify no change on re-uninstall + assert: + that: + - "not yum_result is changed" + +# INSTALL +- name: install {{ package1 }} in check mode + yum: name={{ package1 }} state=present + check_mode: true + register: yum_result + +- name: verify installation of {{ package1 }} in check mode + assert: + that: + - "yum_result is changed" + +- name: install {{ package1 }} + yum: name={{ package1 }} state=present + register: yum_result + +- name: verify installation of {{ package1 }} + assert: + that: + - "yum_result is success" + - "yum_result is changed" + +- name: verify yum module outputs + assert: + that: + - "'changed' in yum_result" + - "'msg' in yum_result" + - "'results' in yum_result" + +- name: check {{ package1 }} with rpm + shell: rpm -q {{ package1 }} + +# INSTALL AGAIN +- name: install {{ package1 }} again in check mode + yum: name={{ package1 }} state=present + check_mode: true + register: yum_result +- name: verify no change on second install in check mode + assert: + that: + - "not yum_result is changed" + +- name: install {{ package1 }} again + yum: name={{ package1 }} state=present + register: yum_result +- name: verify no change on second install + assert: + that: + - "not yum_result is changed" + +- name: install {{ package1 }} again with empty string enablerepo + yum: name={{ package1 }} state=present enablerepo="" + register: yum_result +- name: verify no change on third install with empty string enablerepo + assert: + that: + - "yum_result is success" + - "not yum_result is changed" + +# This test case is unfortunately distro specific because we have to specify +# repo names which are not the same across Fedora/RHEL/CentOS for base/updates +- name: install {{ package1 }} again with missing repo enablerepo + yum: + name: '{{ package1 }}' + state: present + enablerepo: '{{ repos + ["thisrepodoesnotexist"] }}' + disablerepo: "*" + register: yum_result + when: ansible_distribution == 'CentOS' +- name: verify no change on fourth install with missing repo enablerepo (yum) + assert: + that: + - "yum_result is success" + - "yum_result is not changed" + when: ansible_distribution == 'CentOS' + +# This test case is unfortunately distro specific because we have to specify +# repo names which are not the same across Fedora/RHEL/CentOS for base/updates +- name: install repos again with disable all and enable select repo(s) + yum: + name: '{{ package1 }}' + state: present + enablerepo: '{{ repos }}' + disablerepo: "*" + register: yum_result + when: ansible_distribution == 'CentOS' +- name: verify no change on fourth install with missing repo enablerepo (yum) + assert: + that: + - "yum_result is success" + - "yum_result is not changed" + when: ansible_distribution == 'CentOS' + +- name: install {{ package1 }} again with only missing repo enablerepo + yum: + name: '{{ package1 }}' + state: present + enablerepo: "thisrepodoesnotexist" + ignore_errors: true + register: yum_result +- name: verify no change on fifth install with only missing repo enablerepo (yum) + assert: + that: + - "yum_result is not success" + when: ansible_pkg_mgr == 'yum' +- name: verify no change on fifth install with only missing repo enablerepo (dnf) + assert: + that: + - "yum_result is success" + when: ansible_pkg_mgr == 'dnf' + +# INSTALL AGAIN WITH LATEST +- name: install {{ package1 }} again with state latest in check mode + yum: name={{ package1 }} state=latest + check_mode: true + register: yum_result +- name: verify install {{ package1 }} again with state latest in check mode + assert: + that: + - "not yum_result is changed" + +- name: install {{ package1 }} again with state latest idempotence + yum: name={{ package1 }} state=latest + register: yum_result +- name: verify install {{ package1 }} again with state latest idempotence + assert: + that: + - "not yum_result is changed" + +# INSTALL WITH LATEST +- name: uninstall {{ package1 }} + yum: name={{ package1 }} state=removed + register: yum_result +- name: verify uninstall {{ package1 }} + assert: + that: + - "yum_result is successful" + +- name: copy yum.conf file in case it is missing + copy: + src: yum.conf + dest: /etc/yum.conf + force: False + register: yum_conf_copy + +- block: + - name: install {{ package1 }} with state latest in check mode with config file param + yum: name={{ package1 }} state=latest conf_file=/etc/yum.conf + check_mode: true + register: yum_result + - name: verify install {{ package1 }} with state latest in check mode with config file param + assert: + that: + - "yum_result is changed" + + always: + - name: remove tmp yum.conf file if we created it + file: + path: /etc/yum.conf + state: absent + when: yum_conf_copy is changed + +- name: install {{ package1 }} with state latest in check mode + yum: name={{ package1 }} state=latest + check_mode: true + register: yum_result +- name: verify install {{ package1 }} with state latest in check mode + assert: + that: + - "yum_result is changed" + +- name: install {{ package1 }} with state latest + yum: name={{ package1 }} state=latest + register: yum_result +- name: verify install {{ package1 }} with state latest + assert: + that: + - "yum_result is changed" + +- name: install {{ package1 }} with state latest idempotence + yum: name={{ package1 }} state=latest + register: yum_result +- name: verify install {{ package1 }} with state latest idempotence + assert: + that: + - "not yum_result is changed" + +- name: install {{ package1 }} with state latest idempotence with config file param + yum: name={{ package1 }} state=latest + register: yum_result +- name: verify install {{ package1 }} with state latest idempotence with config file param + assert: + that: + - "not yum_result is changed" + + +# Multiple packages +- name: uninstall {{ package1 }} and {{ package2 }} + yum: name={{ package1 }},{{ package2 }} state=removed + +- name: check {{ package1 }} with rpm + shell: rpm -q {{ package1 }} + ignore_errors: True + register: rpm_package1_result + +- name: check {{ package2 }} with rpm + shell: rpm -q {{ package2 }} + ignore_errors: True + register: rpm_package2_result + +- name: verify packages installed + assert: + that: + - "rpm_package1_result is failed" + - "rpm_package2_result is failed" + +- name: install {{ package1 }} and {{ package2 }} as comma separated + yum: name={{ package1 }},{{ package2 }} state=present + register: yum_result + +- name: verify packages installed + assert: + that: + - "yum_result is success" + - "yum_result is changed" + +- name: check {{ package1 }} with rpm + shell: rpm -q {{ package1 }} + +- name: check {{ package2 }} with rpm + shell: rpm -q {{ package2 }} + +- name: uninstall {{ package1 }} and {{ package2 }} + yum: name={{ package1 }},{{ package2 }} state=removed + register: yum_result + +- name: install {{ package1 }} and {{ package2 }} as list + yum: + name: + - '{{ package1 }}' + - '{{ package2 }}' + state: present + register: yum_result + +- name: verify packages installed + assert: + that: + - "yum_result is success" + - "yum_result is changed" + +- name: check {{ package1 }} with rpm + shell: rpm -q {{ package1 }} + +- name: check {{ package2 }} with rpm + shell: rpm -q {{ package2 }} + +- name: uninstall {{ package1 }} and {{ package2 }} + yum: name={{ package1 }},{{ package2 }} state=removed + register: yum_result + +- name: install {{ package1 }} and {{ package2 }} as comma separated with spaces + yum: + name: "{{ package1 }}, {{ package2 }}" + state: present + register: yum_result + +- name: verify packages installed + assert: + that: + - "yum_result is success" + - "yum_result is changed" + +- name: check {{ package1 }} with rpm + shell: rpm -q {{ package1 }} + +- name: check {{ package2 }} with rpm + shell: rpm -q {{ package2 }} + +- name: uninstall {{ package1 }} and {{ package2 }} + yum: name={{ package1 }},{{ package2 }} state=removed + +- name: install non-existent rpm + yum: + name: does-not-exist + register: non_existent_rpm + ignore_errors: True + +- name: check non-existent rpm install failed + assert: + that: + - non_existent_rpm is failed + +# Install in installroot='/' +- name: install {{ package1 }} + yum: name={{ package1 }} state=present installroot='/' + register: yum_result + +- name: verify installation of {{ package1 }} + assert: + that: + - "yum_result is success" + - "yum_result is changed" + +- name: verify yum module outputs + assert: + that: + - "'changed' in yum_result" + - "'msg' in yum_result" + - "'results' in yum_result" + +- name: check {{ package1 }} with rpm + shell: rpm -q {{ package1 }} --root=/ + +- name: uninstall {{ package1 }} + yum: + name: '{{ package1 }}' + installroot: '/' + state: removed + register: yum_result + +# Seems like some yum versions won't download a package from local file repository, continue to use sos for this test. +# https://stackoverflow.com/questions/58295660/yum-downloadonly-ignores-packages-in-local-repo +- name: Test download_only + yum: + name: sos + state: latest + download_only: true + register: yum_result + +- name: verify download of sos (part 1 -- yum "install" succeeded) + assert: + that: + - "yum_result is success" + - "yum_result is changed" + +- name: uninstall sos (noop) + yum: + name: sos + state: removed + register: yum_result + +- name: verify download of sos (part 2 -- nothing removed during uninstall) + assert: + that: + - "yum_result is success" + - "not yum_result is changed" + +- name: uninstall sos for downloadonly/downloaddir test + yum: + name: sos + state: absent + +- name: Test download_only/download_dir + yum: + name: sos + state: latest + download_only: true + download_dir: "/var/tmp/packages" + register: yum_result + +- name: verify yum output + assert: + that: + - "yum_result is success" + - "yum_result is changed" + +- command: "ls /var/tmp/packages" + register: ls_out + +- name: Verify specified download_dir was used + assert: + that: + - "'sos' in ls_out.stdout" + +- name: install group + yum: + name: "@Custom Group" + state: present + register: yum_result + +- name: verify installation of the group + assert: + that: + - "yum_result is success" + - "yum_result is changed" + +- name: verify yum module outputs + assert: + that: + - "'changed' in yum_result" + - "'msg' in yum_result" + - "'results' in yum_result" + +- name: install the group again + yum: + name: "@Custom Group" + state: present + register: yum_result + +- name: verify nothing changed + assert: + that: + - "yum_result is success" + - "not yum_result is changed" + +- name: verify yum module outputs + assert: + that: + - "'changed' in yum_result" + - "'msg' in yum_result" + - "'results' in yum_result" + +- name: install the group again but also with a package that is not yet installed + yum: + name: + - "@Custom Group" + - '{{ package2 }}' + state: present + register: yum_result + +- name: verify {{ package3 }} is installed + assert: + that: + - "yum_result is success" + - "yum_result is changed" + +- name: verify yum module outputs + assert: + that: + - "'changed' in yum_result" + - "'msg' in yum_result" + - "'results' in yum_result" + +- name: try to install the group again, with --check to check 'changed' + yum: + name: "@Custom Group" + state: present + check_mode: yes + register: yum_result + +- name: verify nothing changed + assert: + that: + - "not yum_result is changed" + +- name: verify yum module outputs + assert: + that: + - "'changed' in yum_result" + - "'msg' in yum_result" + - "'results' in yum_result" + +- name: try to install non existing group + yum: + name: "@non-existing-group" + state: present + register: yum_result + ignore_errors: True + +- name: verify installation of the non existing group failed + assert: + that: + - "yum_result is failed" + - "not yum_result is changed" + - "yum_result is failed" + +- name: verify yum module outputs + assert: + that: + - "'changed' in yum_result" + - "'msg' in yum_result" + - "'results' in yum_result" + +- name: try to install non existing file + yum: + name: /tmp/non-existing-1.0.0.fc26.noarch.rpm + state: present + register: yum_result + ignore_errors: yes + +- name: verify installation failed + assert: + that: + - "yum_result is failed" + - "not yum_result is changed" + +- name: verify yum module outputs + assert: + that: + - "'changed' in yum_result" + - "'msg' in yum_result" + +- name: try to install from non existing url + yum: + name: https://ci-files.testing.ansible.com/test/integration/targets/yum/non-existing-1.0.0.fc26.noarch.rpm + state: present + register: yum_result + ignore_errors: yes + +- name: verify installation failed + assert: + that: + - "yum_result is failed" + - "not yum_result is changed" + +- name: verify yum module outputs + assert: + that: + - "'changed' in yum_result" + - "'msg' in yum_result" + +- name: use latest to install httpd + yum: + name: httpd + state: latest + register: yum_result + +- name: verify httpd was installed + assert: + that: + - "'changed' in yum_result" + +- name: uninstall httpd + yum: + name: httpd + state: removed + +- name: update httpd only if it exists + yum: + name: httpd + state: latest + update_only: yes + register: yum_result + +- name: verify httpd not installed + assert: + that: + - "not yum_result is changed" + - "'Packages providing httpd not installed due to update_only specified' in yum_result.results" + +- name: try to install uncompatible arch rpm on non-ppc64le, should fail + yum: + name: https://ci-files.testing.ansible.com/test/integration/targets/yum/banner-1.3.4-3.el7.ppc64le.rpm + state: present + register: yum_result + ignore_errors: True + when: + - ansible_architecture not in ['ppc64le'] + +- name: verify that yum failed on non-ppc64le + assert: + that: + - "not yum_result is changed" + - "yum_result is failed" + when: + - ansible_architecture not in ['ppc64le'] + +- name: try to install uncompatible arch rpm on ppc64le, should fail + yum: + name: https://ci-files.testing.ansible.com/test/integration/targets/yum/tinyproxy-1.10.0-3.el7.x86_64.rpm + state: present + register: yum_result + ignore_errors: True + when: + - ansible_architecture in ['ppc64le'] + +- name: verify that yum failed on ppc64le + assert: + that: + - "not yum_result is changed" + - "yum_result is failed" + when: + - ansible_architecture in ['ppc64le'] + +# setup for testing installing an RPM from url + +- set_fact: + pkg_name: noarchfake + pkg_path: '{{ repodir }}/noarchfake-1.0-1.noarch.rpm' + +- name: cleanup + yum: + name: "{{ pkg_name }}" + state: absent + +# setup end + +- name: install a local noarch rpm from file + yum: + name: "{{ pkg_path }}" + state: present + disable_gpg_check: true + register: yum_result + +- name: verify installation + assert: + that: + - "yum_result is success" + - "yum_result is changed" + - "yum_result is not failed" + +- name: verify yum module outputs + assert: + that: + - "'changed' in yum_result" + - "'msg' in yum_result" + - "'results' in yum_result" + +- name: install the downloaded rpm again + yum: + name: "{{ pkg_path }}" + state: present + register: yum_result + +- name: verify installation + assert: + that: + - "yum_result is success" + - "not yum_result is changed" + - "yum_result is not failed" + +- name: verify yum module outputs + assert: + that: + - "'changed' in yum_result" + - "'msg' in yum_result" + - "'results' in yum_result" + +- name: clean up + yum: + name: "{{ pkg_name }}" + state: absent + +- name: install from url + yum: + name: "file://{{ pkg_path }}" + state: present + disable_gpg_check: true + register: yum_result + +- name: verify installation + assert: + that: + - "yum_result is success" + - "yum_result is changed" + - "yum_result is not failed" + +- name: verify yum module outputs + assert: + that: + - "'changed' in yum_result" + - "'msg' in yum_result" + - "'results' in yum_result" + +- name: Create a temp RPM file which does not contain nevra information + file: + name: "/tmp/non_existent_pkg.rpm" + state: touch + +- name: Try installing RPM file which does not contain nevra information + yum: + name: "/tmp/non_existent_pkg.rpm" + state: present + register: no_nevra_info_result + ignore_errors: yes + +- name: Verify RPM failed to install + assert: + that: + - "'changed' in no_nevra_info_result" + - "'msg' in no_nevra_info_result" + +- name: Delete a temp RPM file + file: + name: "/tmp/non_existent_pkg.rpm" + state: absent + +- name: get yum version + yum: + list: yum + register: yum_version + +- name: set yum_version of installed version + set_fact: + yum_version: "{%- if item.yumstate == 'installed' -%}{{ item.version }}{%- else -%}{{ yum_version }}{%- endif -%}" + with_items: "{{ yum_version.results }}" + +- name: Ensure double uninstall of wildcard globs works + block: + - name: "Install lohit-*-fonts" + yum: + name: "lohit-*-fonts" + state: present + + - name: "Remove lohit-*-fonts (1st time)" + yum: + name: "lohit-*-fonts" + state: absent + register: remove_lohit_fonts_1 + + - name: "Verify lohit-*-fonts (1st time)" + assert: + that: + - "remove_lohit_fonts_1 is changed" + - "'msg' in remove_lohit_fonts_1" + - "'results' in remove_lohit_fonts_1" + + - name: "Remove lohit-*-fonts (2nd time)" + yum: + name: "lohit-*-fonts" + state: absent + register: remove_lohit_fonts_2 + + - name: "Verify lohit-*-fonts (2nd time)" + assert: + that: + - "remove_lohit_fonts_2 is not changed" + - "'msg' in remove_lohit_fonts_2" + - "'results' in remove_lohit_fonts_2" + - "'lohit-*-fonts is not installed' in remove_lohit_fonts_2['results']" + +- block: + - name: uninstall {{ package2 }} + yum: name={{ package2 }} state=removed + + - name: check {{ package2 }} with rpm + shell: rpm -q {{ package2 }} + ignore_errors: True + register: rpm_package2_result + + - name: verify {{ package2 }} is uninstalled + assert: + that: + - "rpm_package2_result is failed" + + - name: exclude {{ package2 }} (yum backend) + lineinfile: + dest: /etc/yum.conf + regexp: (^exclude=)(.)* + line: "exclude={{ package2 }}*" + state: present + when: ansible_pkg_mgr == 'yum' + + - name: exclude {{ package2 }} (dnf backend) + lineinfile: + dest: /etc/dnf/dnf.conf + regexp: (^excludepkgs=)(.)* + line: "excludepkgs={{ package2 }}*" + state: present + when: ansible_pkg_mgr == 'dnf' + + # begin test case where disable_excludes is supported + - name: Try install {{ package2 }} without disable_excludes + yum: name={{ package2 }} state=latest + register: yum_package2_result + ignore_errors: True + + - name: verify {{ package2 }} did not install because it is in exclude list + assert: + that: + - "yum_package2_result is failed" + + - name: install {{ package2 }} with disable_excludes + yum: name={{ package2 }} state=latest disable_excludes=all + register: yum_package2_result_using_excludes + + - name: verify {{ package2 }} did install using disable_excludes=all + assert: + that: + - "yum_package2_result_using_excludes is success" + - "yum_package2_result_using_excludes is changed" + - "yum_package2_result_using_excludes is not failed" + + - name: remove exclude {{ package2 }} (cleanup yum.conf) + lineinfile: + dest: /etc/yum.conf + regexp: (^exclude={{ package2 }}*) + line: "exclude=" + state: present + when: ansible_pkg_mgr == 'yum' + + - name: remove exclude {{ package2 }} (cleanup dnf.conf) + lineinfile: + dest: /etc/dnf/dnf.conf + regexp: (^excludepkgs={{ package2 }}*) + line: "excludepkgs=" + state: present + when: ansible_pkg_mgr == 'dnf' + + # Fedora < 26 has a bug in dnf where package excludes in dnf.conf aren't + # actually honored and those releases are EOL'd so we have no expectation they + # will ever be fixed + when: not ((ansible_distribution == "Fedora") and (ansible_distribution_major_version|int < 26)) + +- name: Check that packages with Provides are handled correctly in state=absent + block: + - name: Install test packages + yum: + name: + - https://ci-files.testing.ansible.com/test/integration/targets/yum/test-package-that-provides-toaster-1.3.3.7-1.el7.noarch.rpm + - https://ci-files.testing.ansible.com/test/integration/targets/yum/toaster-1.2.3.4-1.el7.noarch.rpm + disable_gpg_check: true + register: install + + - name: Remove toaster + yum: + name: toaster + state: absent + register: remove + + - name: rpm -qa + command: rpm -qa + register: rpmqa + + - assert: + that: + - install is successful + - install is changed + - remove is successful + - remove is changed + - "'toaster-1.2.3.4' not in rpmqa.stdout" + - "'test-package-that-provides-toaster' in rpmqa.stdout" + always: + - name: Remove test packages + yum: + name: + - test-package-that-provides-toaster + - toaster + state: absent + +- yum: + list: "{{ package1 }}" + register: list_out + +- name: check that both yum and dnf return envra + assert: + that: + - '"envra" in list_out["results"][0]' + +- name: check that dnf returns nevra for backwards compat + assert: + that: + - '"nevra" in list_out["results"][0]' + when: ansible_pkg_mgr == 'dnf' diff --git a/test/integration/targets/yum/tasks/yum_group_remove.yml b/test/integration/targets/yum/tasks/yum_group_remove.yml new file mode 100644 index 0000000..22c6dcb --- /dev/null +++ b/test/integration/targets/yum/tasks/yum_group_remove.yml @@ -0,0 +1,152 @@ +- name: install a group to test and yum-utils + yum: + name: "{{ pkgs }}" + state: present + vars: + pkgs: + - "@Custom Group" + - yum-utils + when: ansible_pkg_mgr == "yum" + +- name: install a group to test and dnf-utils + yum: + name: "{{ pkgs }}" + state: present + vars: + pkgs: + - "@Custom Group" + - dnf-utils + when: ansible_pkg_mgr == "dnf" + +- name: check mode remove the group + yum: + name: "@Custom Group" + state: absent + check_mode: yes + register: yum_result + +- name: verify changed + assert: + that: + - "yum_result.changed" + +- name: verify yum module outputs + assert: + that: + - "'changed' in yum_result" + - "'results' in yum_result" + +- name: remove the group + yum: + name: "@Custom Group" + state: absent + register: yum_result + +- name: verify changed + assert: + that: + - "yum_result.rc == 0" + - "yum_result.changed" + +- name: verify yum module outputs + assert: + that: + - "'changed' in yum_result" + - "'msg' in yum_result" + - "'results' in yum_result" + +- name: remove the group again + yum: + name: "@Custom Group" + state: absent + register: yum_result + +- name: verify changed + assert: + that: + - "not yum_result.changed" + +- name: verify yum module outputs + assert: + that: + - "'changed' in yum_result" + - "'msg' in yum_result" + - "'results' in yum_result" + +- name: check mode remove the group again + yum: + name: "@Custom Group" + state: absent + check_mode: yes + register: yum_result + +- name: verify changed + assert: + that: + - "not yum_result.changed" + +- name: verify yum module outputs + assert: + that: + - "'changed' in yum_result" + - "'results' in yum_result" + +- name: install a group and a package to test + yum: + name: "@Custom Group,sos" + state: present + register: yum_output + +- name: check mode remove the group along with the package + yum: + name: "@Custom Group,sos" + state: absent + register: yum_result + check_mode: yes + +- name: verify changed + assert: + that: + - "yum_result.changed" + +- name: verify yum module outputs + assert: + that: + - "'changed' in yum_result" + - "'results' in yum_result" + +- name: remove the group along with the package + yum: + name: "@Custom Group,sos" + state: absent + register: yum_result + +- name: verify changed + assert: + that: + - "yum_result.changed" + +- name: verify yum module outputs + assert: + that: + - "'changed' in yum_result" + - "'msg' in yum_result" + - "'results' in yum_result" + +- name: check mode remove the group along with the package + yum: + name: "@Custom Group,sos" + state: absent + register: yum_result + check_mode: yes + +- name: verify not changed + assert: + that: + - "not yum_result.changed" + +- name: verify yum module outputs + assert: + that: + - "'changed' in yum_result" + - "'results' in yum_result" diff --git a/test/integration/targets/yum/tasks/yuminstallroot.yml b/test/integration/targets/yum/tasks/yuminstallroot.yml new file mode 100644 index 0000000..028e805 --- /dev/null +++ b/test/integration/targets/yum/tasks/yuminstallroot.yml @@ -0,0 +1,132 @@ +# make a installroot +- name: Create installroot + command: mktemp -d "{{ remote_tmp_dir }}/ansible.test.XXXXXX" + register: yumroot + +#- name: Populate directory +# file: +# path: "/{{ yumroot.stdout }}/etc/" +# state: directory +# mode: 0755 +# +#- name: Populate directory2 +# copy: +# content: "[main]\ndistropkgver={{ ansible_distribution_version }}\n" +# dest: "/{{ yumroot.stdout }}/etc/yum.conf" + +- name: Make a necessary directory + file: + path: "{{ yumroot.stdout }}/etc/yum/vars/" + state: directory + mode: 0755 + +- name: get yum releasever + command: "{{ ansible_python_interpreter }} -c 'import yum; yb = yum.YumBase(); print(yb.conf.yumvar[\"releasever\"])'" + register: releasever + ignore_errors: yes + +- name: Populate directory + copy: + content: "{{ releasever.stdout_lines[-1] }}\n" + dest: "/{{ yumroot.stdout }}/etc/yum/vars/releasever" + when: releasever is successful + +# This will drag in > 200 MB. +- name: attempt installroot + yum: name=zlib installroot="{{ yumroot.stdout }}/" disable_gpg_check=yes + register: yum_result + +- name: check sos with rpm in installroot + shell: rpm -q zlib --root="{{ yumroot.stdout }}/" + failed_when: False + register: rpm_result + +- name: verify installation of sos + assert: + that: + - "yum_result.rc == 0" + - "yum_result.changed" + - "rpm_result.rc == 0" + +- name: verify yum module outputs + assert: + that: + - "'changed' in yum_result" + - "'msg' in yum_result" + - "'rc' in yum_result" + - "'results' in yum_result" + +- name: cleanup installroot + file: + path: "{{ yumroot.stdout }}/" + state: absent + +# Test for releasever working correctly +# +# Bugfix: https://github.com/ansible/ansible/issues/67050 +# +# This test case is based on a reproducer originally reported on Reddit: +# https://www.reddit.com/r/ansible/comments/g2ps32/ansible_yum_module_throws_up_an_error_when/ +# +# NOTE: For the Ansible upstream CI we can only run this for RHEL7 because the +# containerized runtimes in shippable don't allow the nested mounting of +# buildah container volumes. +- name: perform yuminstallroot in a buildah mount with releasever + when: + - ansible_facts["distribution_major_version"] == "7" + - ansible_facts["distribution"] == "RedHat" + block: + - name: install required packages for buildah test + yum: + state: present + name: + - buildah + - name: create buildah container from scratch + command: "buildah --name yum_installroot_releasever_test from scratch" + - name: mount the buildah container + command: "buildah mount yum_installroot_releasever_test" + register: buildah_mount + - name: figure out yum value of $releasever + shell: python -c 'import yum; yb = yum.YumBase(); print(yb.conf.yumvar["releasever"])' | tail -1 + register: buildah_host_releasever + - name: test yum install of python using releasever + yum: + name: 'python' + state: present + installroot: "{{ buildah_mount.stdout }}" + releasever: "{{ buildah_host_releasever.stdout }}" + register: yum_result + - name: verify installation of python + assert: + that: + - "yum_result.rc == 0" + - "yum_result.changed" + - "rpm_result.rc == 0" + - name: remove python before another test + yum: + name: 'python' + state: absent + installroot: "{{ buildah_mount.stdout }}" + releasever: "{{ buildah_host_releasever.stdout }}" + - name: test yum install of python using releasever with latest + yum: + name: 'python' + state: latest + installroot: "{{ buildah_mount.stdout }}" + releasever: "{{ buildah_host_releasever.stdout }}" + register: yum_result + - name: verify installation of python + assert: + that: + - "yum_result.rc == 0" + - "yum_result.changed" + - "rpm_result.rc == 0" + always: + - name: remove buildah container + command: "buildah rm yum_installroot_releasever_test" + ignore_errors: yes + - name: remove buildah from CI system + yum: + state: absent + name: + - buildah |