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
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.
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 }}"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With