Reputation: 41
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
Upvotes: 3
Views: 31407
Reputation: 106
I think the best solution for this is as follows:
- name: Find all rpm files in /tmp folder
find:
paths: "/tmp"
patterns: "*.rpm"
register: rpm_files
- name: Setting rpm_list
set_fact:
rpm_list: "{{ rpm_files.files | map(attribute='path') | list}}"
- name: installing the rpm files
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.
Upvotes: 8
Reputation: 43
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:
Upvotes: 0
Reputation: 679
try this:
- name: Installed the rpm files
shell: yum localinstall *.rpm -y
args:
chdir: /tmp/rpm_dir
ignore the warning.
Upvotes: 1
Reputation: 23771
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 }}"
Upvotes: 6