So I am writing an ansible playbook which uninstalls some OS packages (in this case, all RedHat ABRT packages) and then checks if they were uninstalled. Uninstallation is not the problem (it works fine), but I need to verify if the packages were really uninstalled and then do some other stuff depending on that.
This is on RedHat 6.9 machine, and I am using Ansible 2.6.
- name: list installed ABRT packages
yum:
list: abrt*
register: abrt_packages
when: ansible_os_family == "RedHat"
- name: get package info
set_fact:
packages_installed: "{{abrt_packages|json_query(jsonquery)}}"
vars:
jsonquery: "results[?yumstate=='installed']"
- debug:
var: packages_installed
When running the ansible code above, I get no output - meaning, there are no packages with "yumstate": "installed" (despite the fact that they are actually installed):
user1@server1: [~]$ rpm -qa | grep abrt
abrt-python-2.0.8-43.el6.x86_64
abrt-addon-ccpp-2.0.8-43.el6.x86_64
abrt-addon-kerneloops-2.0.8-43.el6.x86_64
abrt-cli-2.0.8-43.el6.x86_64
abrt-libs-2.0.8-43.el6.x86_64
abrt-addon-python-2.0.8-43.el6.x86_64
abrt-2.0.8-43.el6.x86_64
abrt-tui-2.0.8-43.el6.x86_64
Yum also shows them as installed.
If I modify the jsonquery to:
jsonquery: "results"
then I get this:
ok: [server1] => {
"packages_installed": [
{
"arch": "x86_64",
"envra": "0:abrt-addon-ccpp-2.0.8-43.el6.x86_64",
"epoch": "0",
"name": "abrt-addon-ccpp",
"release": "43.el6",
"repo": "Repo1yum",
"version": "2.0.8",
"yumstate": "available"
},
{
"arch": "x86_64",
"envra": "0:abrt-addon-kerneloops-2.0.8-43.el6.x86_64",
"epoch": "0",
"name": "abrt-addon-kerneloops",
"release": "43.el6",
"repo": "Repo1yum",
"version": "2.0.8",
"yumstate": "available"
},
etc.
So, despite the fact that the ABRT packages are actually installed, their "yumstate" is "available" (instead of "installed"). Is this a bug in Ansible yum module or I am doing something wrong? How should I check if the ABRT packages (or any other package) are installed or not?