X-Git-Url: https://gerrit.fd.io/r/gitweb?p=csit.git;a=blobdiff_plain;f=resources%2Ftools%2Ftestbed-setup%2Fansible%2Froles%2Fcleanup%2Ftasks%2Fremove_package.yaml;fp=resources%2Ftools%2Ftestbed-setup%2Fansible%2Froles%2Fcleanup%2Ftasks%2Fremove_package.yaml;h=8f5ec8fefe1f11d8714988399ca6477b528cde65;hp=0000000000000000000000000000000000000000;hb=d01411c3c4af6c724a3800c621804ea979818d6d;hpb=50d21f72ff61d06641954c22a8bc13c2468388f9 diff --git a/resources/tools/testbed-setup/ansible/roles/cleanup/tasks/remove_package.yaml b/resources/tools/testbed-setup/ansible/roles/cleanup/tasks/remove_package.yaml new file mode 100644 index 0000000000..8f5ec8fefe --- /dev/null +++ b/resources/tools/testbed-setup/ansible/roles/cleanup/tasks/remove_package.yaml @@ -0,0 +1,31 @@ +--- +# file: roles/cleanup/tasks/remove_package.yaml + +- name: Remove package - Fix corrupted apt + shell: 'dpkg --configure -a' + when: > + ansible_distribution == 'Ubuntu' + tags: remove-package + +- name: Remove package - Check if {{ package }} is installed + shell: > + "dpkg-query -W -f='${Status}' {{ package }} | grep 'install ok installed'" + register: package_is_installed + failed_when: no + changed_when: no + when: > + ansible_distribution == 'Ubuntu' + tags: remove-package + +- name: Remove package - {{ package }} + apt: + name: '{{ package }}' + force: yes + purge: yes + state: absent + when: > + package is defined and + package != '' and + package_is_installed.rc == 0 and + ansible_distribution|lower == 'ubuntu' + tags: remove-package