I want to install some RPM packages using Ansible and the installed rpm package manager. yum is not installed.

Using command module with rpm -i {{package}} causes the task to fail if the package is already installed. I'm searching for an idiomatic way to install the packages like yum or apt modules does it.

  • RPM is an additional, auxiliary package manager in AIX. The primary one is installp filesets. Jul 4, 2020 at 3:18

4 Answers 4


Install yum, plus yum-utils, and use the yum module. Not installed by default on AIX, but can be done.

Requirements include the yum and rpm Python modules. I'm unclear on which package provides the rpm bindings, something has to for yum to work. Possibly from the rpm fileset, but unfortunately I do not have an AIX box to test with.

  • And if I write "not yum" and "yum is not installed" you think this is a good awnser?
    – Michael
    Jul 5, 2020 at 5:28
  • Ansible has written their idempotent rpm modules entirely with yum. The yum module can be provided an .rpm file or URL. Dependency hell will be avoided as it will resolve transaction requirements for you. A module with proper error handling is better than swallowing errors. Jul 5, 2020 at 11:00
  • I absolutely know this. But this specific question here has reasons. And this solution doesn't answer this specific question. In other scenarios I already use yum.
    – Michael
    Jul 6, 2020 at 11:27
  • Care to elaborate on the reasons why yum won't work? yum is the idempotent module to upgrade rpms. (If you don't write your own alternative module.) Documentation on how to install yum on AIX exists, even if it isn't available by default. Jul 7, 2020 at 15:02

Use rpm -U.

From the manual:

rpm {-U|--upgrade} [install-options] PACKAGE_FILE ...

This upgrades or installs the package currently installed to a newer version. This is the same as install, except all other version(s) of the package are removed after the new package is installed.

  • The apt_rpm module might be worth a try, but I don't know if it can install directly from rpm files and I don't have a VM handy to test it. Jul 3, 2020 at 9:36
  • AFAIK --upgrade will always upgrade. I'm searching a way that performs the action only if it is needed - like other modules do. (the idiomatic Ansible way to do it)
    – Michael
    Jul 3, 2020 at 10:12
- name: check if the filebeat exist
    cmd: rpm -q filebeat
  ignore_errors: True
  register: filebeat_check

- name: transfer filebeat package to remote host
    src: filebeat.rpm
    dest: /tmp/filebeat.rpm
  when: filebeat_check.rc != 0

- name: install filebeat
    cmd: rpm -i /tmp/filebeat.rpm
  when: filebeat_check.rc != 0
  • Not a bad approach, but it can't update a package that is already installed. Jul 3, 2020 at 9:55
  • Write the entire process to a script, and then use Ansible for batch execution. Is this possible? Jul 3, 2020 at 10:05
  • I thought about something similar. But I think about using some checksum - verify it and install the rpm file only if the checksums differ. But actually I don't know if this is possible using rpm.
    – Michael
    Jul 3, 2020 at 10:14
  • You can write your own Ansible module upgrading rpm packages without yum if you like. Jul 7, 2020 at 14:42

I think this matches my problem the best so far:

- name: Verify package MD5
  shell: |
    package_md5=$(rpm -qp --queryformat='%{FILEMD5S}' '{{ item }}')
    package_name=$(rpm -qp --queryformat='%{NAME}' '{{ item }}')
    installed_md5=$(rpm -q --queryformat='%{FILEMD5S}' "$package_name")
    [ "$installed_md5" = "$package_md5" ]
  ignore_errors: true
  register: verify_result
  changed_when: no
  failed_when: no

- name: Install package
  shell: rpm -U '{{ item }}'
  when: verify_result.rc != 0

item is the path to a rpm file.

The first task gets the MD5 checksum and the name of the package from the rpm file and compares the checksum with the installed package with the same package name. If the checksum doesn't match (and only then), the second task will install the rpm package.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .