Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Install multiple local rpms using Ansible

Tags:

ansible

yum

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

like image 539
agordgongrant Avatar asked Sep 20 '25 15:09

agordgongrant


2 Answers

I think the best solution for this is as follows:

- name: Find all rpm files in /tmp folder
  ansible.builtin.find:
    paths: "/tmp"
    patterns: "*.rpm"
  register: rpm_files

- name: Setting rpm_list
  ansible.builtin.set_fact:
    rpm_list: "{{ rpm_files.files | map(attribute='path') | list}}"

- name: installing the rpm files
  ansible.builtin.yum:
    name: "{{ rpm_list }}"
    state: present

Looping through the files might cause Yum Lock issues. So this is better and efficient as we don't have to loop through all the files, instead we are passing a list of file paths to the yum module.

like image 134
Pavan Srinivas Avatar answered Sep 22 '25 20:09

Pavan Srinivas


Can you try this(I didn't test it):

- 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 }}"
like image 42
Arbab Nazar Avatar answered Sep 22 '25 19:09

Arbab Nazar