0

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.

1
  • RPM is an additional, auxiliary package manager in AIX. The primary one is installp filesets. – John Mahowald Jul 4 '20 at 3:18
1

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.

4
  • And if I write "not yum" and "yum is not installed" you think this is a good awnser? – Michael Jul 5 '20 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. – John Mahowald Jul 5 '20 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 '20 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. – John Mahowald Jul 7 '20 at 15:02
0

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.

2
  • 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. – Gerald Schneider Jul 3 '20 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 '20 at 10:12
0
- name: check if the filebeat exist
  shell:
    cmd: rpm -q filebeat
  ignore_errors: True
  register: filebeat_check

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

- name: install filebeat
  shell:
    cmd: rpm -i /tmp/filebeat.rpm
  when: filebeat_check.rc != 0
4
  • Not a bad approach, but it can't update a package that is already installed. – Gerald Schneider Jul 3 '20 at 9:55
  • Write the entire process to a script, and then use Ansible for batch execution. Is this possible? – loveshell Guo Jul 3 '20 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 '20 at 10:14
  • You can write your own Ansible module upgrading rpm packages without yum if you like. – John Mahowald Jul 7 '20 at 14:42
0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.