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.

Gerald Schneider
  • 23,274
  • 8
  • 57
  • 89
Michael
  • 345
  • 6
  • 19

4 Answers4

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.

John Mahowald
  • 32,050
  • 2
  • 19
  • 34
  • And if I write "not yum" and "yum is not installed" you think this is a good awnser? – Michael Jul 05 '20 at 05: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 05 '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 06 '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 07 '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.

Gerald Schneider
  • 23,274
  • 8
  • 57
  • 89
  • The [apt_rpm module](https://docs.ansible.com/ansible/latest/modules/apt_rpm_module.html) 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 03 '20 at 09: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 03 '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
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.

Michael
  • 345
  • 6
  • 19