How to get just the version of the software when using ansible_facts.packages[“zabbix-agent”]


I’m having an issue with using the package_facts module in Ansible. Basically, I just want to get the version of zabbix-agent installed as I need to do some stuff depending on which version is installed.

Now I got this in a playbook task:

Which spits out something like this:

I want to get the value of that “Version”: “3.2.11” so that I can store that in a variable and use that later. I’ve seen that post using yum and doing some json query but that won’t work for me.


For some reason (probably because of more versions of the same package might be installed), the value of the package dictionary is a list. A simple solution is to take the first element

To take into the account the possibility of more versions installed, use map filter

Below is the equivalent with json_query filter

Leave a Reply