Install multiple local rpms using Ansible

Viewed 23791

I have to install dozen of rpms located in a specific directory using ansible. Right now I'm using the syntax like:

- name: install uploaded rpms
  command: rpm -ivh /tmp/*.rpm

I want to do it using yum module, but don't know, how to tell it to install all rpms in a directory (not to specify name of each file).

Any suggestions?

Thanks in advance

4 Answers

try this:

- name: Installed the rpm files
  shell: yum localinstall *.rpm -y
  args:
    chdir: /tmp/rpm_dir

ignore the warning.

As https://stackoverflow.com/a/45708676/11887927 commented and I tested. In most cases, it succeeded but adding retries to the task will help ensure the dependencies problems since we're using find module and it returns the results one by one. Here is the example of the revised:

- name: Finding RPM files
  find:
    paths: "/tmp"
    patterns: "*.rpm"
  register: rpm_result

- name: Install RPM
  yum:
    name: "{{ item.path }}"
    state: present
  with_items: "{{ rpm_result.files }}"
  retries: 5
  register: result
  until: result.rc == 0

The issue happened when there are 6 RPMs.

References:

  1. https://docs.ansible.com/ansible/latest/user_guide/playbooks_loops.html#retrying-a-task-until-a-condition-is-met
  2. https://stackoverflow.com/a/44135131/11887927
Related