Having an inventory of installed software available at hand is an important asset management function. Using this information, we can determine what software is installed on the system, what software needs to be patched or updated and what software needs to be removed. By making use of the yum module available with Ansible we could easily extract this information about our inventory and store it appropriately for future use. In this article, we will share an Ansible playbook that will consist of three tasks. The first task will list all packages currently installed on the system. The second task will list the installed and available versions of a single software package. The third tasks will display the installed and available versions of more than one package.

Given below is the Ansible playbook:

- name: Demonstrate yum list
hosts: all
gather_facts: no
become: yes
become_method: sudo

- name: list all installed packages
yum: list=installed
register: out_all
- debug: var=out_all

- name: list only one package
yum: list=git
register: out_one
- debug: var=out_one

- name: list some packages
yum: list={{ item }}
- git
- tar
- curl
register: out_some
- debug: var=out_some


  • Explanation
    Under the hosts section, we’ve indicated that we’d like to execute this playbook on all hosts available in the inventory. You may modify it appropriately as per your requirement.
  • To provide a speed boost while executing the playbook we set gather_facts to no as gathering facts could take a while if there are a large number of target hosts.
  • We’ve indicated that we would like to execute the tasks that follow using superuser privileges via using become and become_method keywords.
  • Next, we have the first task. This will list all the packages installed on the system via list=installed.
  • We then store the resulting output in a variable using the register keyword and print the result to the screen using the debug module.
  • In the second task, we gather the package information (installed and available) for the git package only.
  • In the third and final task, we employ the yum module to list information about three packages git, tar, and curl.
  • We’ve used the loop mechanism with_items available with Ansible to iterate through the package name for which we wish to obtain the information for.


The output:
Since we’ve used the debug module to print the results of the execution of the tasks, the output provided by Ansible will be in JSON format. You may redirect this output to a text file or a database as appropriate but preferably you may want to feed the resulting output into a tool which could process JSON data and store it in a manageable fashion.

Given below is a snippet from the output displayed by the execution of the second task:

ok: [linuxnix] => {
"out_one": {
"changed": false,
"failed": false,
"results": [
"arch": "x86_64",
"envra": "0:git-1.7.1-4.el6_7.1.x86_64",
"epoch": "0",
"name": "git",
"release": "4.el6_7.1",
"repo": "installed",
"version": "1.7.1",
"yumstate": "installed"

The list action of the yum module provides the following useful information about the module:

  • The software architecture of the package
  • The full name of the package RPM
  • The name of the package
  • The release version of the package
  • The repository from which the package was installed
  • The version of the package
  • The state of the package i.e. whether the package has been installed on the system or if its available for installation



In this article, we shared an Ansible playbook which you could you to obtain information about software installed on your systems. We hope that you’ve found this article and the Ansible playbook useful and we look forward to your feedback and suggestions.

The following two tabs change content below.

Sahil Suri

He started his career in IT in 2011 as a system administrator. He has since worked with HP-UX, Solaris and Linux operating systems along with exposure to high availability and virtualization solutions. He has a keen interest in shell, Python and Perl scripting and is learning the ropes on AWS cloud, DevOps tools, and methodologies. He enjoys sharing the knowledge he's gained over the years with the rest of the community.