Reputation: 1
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?
Upvotes: 0
Views: 1277
Reputation: 68179
Neither list nor name parameter of yum says that wildcards can be used. Quoting description of parameter list:
Package name to run the equivalent of
yum list package
against. In addition to listing packages, use can also list the following: installed, updates, available and repos.
To list installed packages use
jsonquery: "results.packages_installed[?yumstate=='installed'].name"
Packages in the data results.packages_installed at server1, you posted, are available. Then
- set_fact:
packages_available: "{{ abrt_packages|json_query(jsonquery) }}"
vars:
jsonquery: "results.packages_installed[?yumstate=='available'].name"
- debug:
var: packages_available
gives (abridged):
"packages_available": [
"abrt-addon-ccpp",
"abrt-addon-kerneloops"
]
Upvotes: 1