Ansible yum module already provides a solution for this problem. The path to the local rpm file on the server can be passed to the name parameter.

From the Ansible yum module documentation:

You can also pass a url or a local path to a rpm file. To operate on several packages this can accept a comma separated list of packages or (as of 2.0) a list of packages.

The proper steps to do this would be something like this:

- name: Copy rpm file to server
  copy:
     src: package.rpm
     dest: /tmp/package.rpm

- name: Install package.
  yum:
     name: /tmp/package.rpm
     state: present
Answer from Henrik Pingel on serverfault.com
Discussions

rhel - Transfer RPMs file with Ansible and localinstall them - Unix & Linux Stack Exchange
I am having the following yaml ansible-playbook and want to transfer the rpms and then localinstall them on the remote machine. Until the transfer file step its working fine however on the installation part i am taking the following error: "Failure talking to yum: near \"gskcrypt64\": syntax ... More on unix.stackexchange.com
🌐 unix.stackexchange.com
June 28, 2019
redhat - If I have a local rpm in my ansible-playbook can I do yum install in one step? - Stack Overflow
- copy: src=files/sshpass-1.05...-9.1.i686.rpm state=present ... AFAIK this it not supported out of the box. If you utterly need this, you can write action plugin yum as a wrapper of the module to accomplish this. You can start with unarchive as an example (it can copy local file before processing). – Konstantin Suvorov Commented Jul 29, 2016 at 9:43 ... No, there is no simple way around coping the package to the remote host before installing. Ansible yum module ... More on stackoverflow.com
🌐 stackoverflow.com
Install multiple rpm file at once on ansible
Seems like a dns issue at this point, curl is literally telling you it cannot resolve mirrorlist.centos.org. More on reddit.com
🌐 r/ansible
11
4
August 9, 2021
Deploying an RPM file via Playbook

Take a look at the yum module examples. There's one where you use the url to the rpm as the package name. http://docs.ansible.com/ansible/latest/yum_module.html

More on reddit.com
🌐 r/ansible
2
6
May 3, 2023
People also ask

What are the prerequisites for using yum localinstall in Ansible?
Ensure the RPM is available on the managed node and the necessary dependencies for the RPM are also present or resolvable.
🌐
linuxbuz.com
linuxbuz.com › devops › ansible-yum-localinstall
Ansible yum localinstall: A Guide to Install Local RPMs
Can Ansible resolve dependencies for RPMs?
Yes, if the yum module is used, it can resolve dependencies from configured repositories during installation.
🌐
linuxbuz.com
linuxbuz.com › devops › ansible-yum-localinstall
Ansible yum localinstall: A Guide to Install Local RPMs
How can I verify if the RPM is installed successfully via Ansible?
You can use the state: present option in the yum module to ensure the package is installed.
🌐
linuxbuz.com
linuxbuz.com › devops › ansible-yum-localinstall
Ansible yum localinstall: A Guide to Install Local RPMs
🌐
LinuxBuz
linuxbuz.com › devops › ansible-yum-localinstall
Ansible yum localinstall: A Guide to Install Local RPMs
July 11, 2025 - The yum localinstall feature allows you to install RPM packages stored locally on your server. In this guide, we will explain how to use Ansible’s yum module with the localinstall feature to install RPM packages from local files.
Top answer
1 of 1
2

Foreword

You should never use loop or with_item with the yum module unless you have an extremely particular situation because (quoting the doc)

When used with a loop: each package will be processed individually, it is much more efficient to pass the list directly to the name option.

And do yourself a favor: adopt the modern full yaml syntax for calling modules. It's easier to read and linters (e.g. yamllint) will catch more errors earlier.

My example is following those two rules.

Core answer

None of your above tries are sending the actual list of files to the yum module with the absolute path for each element. This info is quite easy to retreive from your copy task if you register the result. You can then filter the data (with e.g. json_query) to get only the relevant info.

The below playbook should give you the keys to do the job

---
- name: Copy and install rpms
  hosts: all

  vars:
    RPM: 
      - gskcrypt64-8.0.50.86.linux.ppcle.rpm 
      - gskssl64-8.0.50.86.linux.ppcle.rpm 
      - TIVsm-API64.ppc64le.rpm 
      - TIVsm-BA.ppc64le.rpm

  tasks:

    - name: "Transfer Files"
      copy:
        src: "/root/ansible_playbooks/{{ item }}"
        dest: /root/
      loop: "{{ RPM }}"
      register: copied

    - name: "Install RPMs from local copied files"
      yum:
        name: "{{ copied | json_query('results[?!failed].dest[]') }}"

Notes

  • The ?!failed filter in the query is only here to filter out results with an error if you ever decide to ignore errors on the copy task. You can remove it if you wish (i.e. json_query('results[].dest'))
  • loop: "{{ RPM }}" is strictly equivalent to with_items: "{{ RPM }}". loop is a newer syntax and was introduced in ansible 2.5. Both syntax are valid. See ansible loops documentation for more details.
🌐
Linux Today
linuxtoday.com › home › blog
Ansible yum localinstall: A Guide to Install Local RPMs | Linux Today
November 12, 2024 - Ansible simplifies package management on Linux systems, especially when using the yum module. In this guide, we will explain how to use Ansible’s yum module with the localinstall feature to install RPM packages from local files.
🌐
DevtoDevOps
devtodevops.com › blog › ansible-yum-localinstall
Master Ansible yum localinstall: Ultimate Guide
June 3, 2025 - How to use the Ansible yum localinstall command to automate the installation of the local RPM package directly from your filesystem for offline deployment.
🌐
Google Groups
groups.google.com › g › ansible-project › c › Lxiuys4CIZI
Install rpm from control machine to ansible managed hosts
- name: copy mod_jk rpm to server copy: src=files/mod_jk-1.2.40-5.el6.x86_64.rpm dest=/home/user/mod_jk-1.2.40-5.el6.x86_64.rpm owner=user group=azureuser mode=755 when: ansible_os_family == 'RedHat' - name: Install mod_jk local rpm in server yum: name=/home/user/mod_jk-1.2.40-5.el6.x86_64.rpm state=present when: ansible_os_family == 'RedHat' Is there a way to directly install from control machine without copying it
Find elsewhere
🌐
Medium
medium.com › geekculture › installing-rpms-without-internet-access-using-ansible-a3ae81d68560
Installing RPMs without Internet Access using Ansible
September 7, 2022 - yum install --downloadonly --downloaddir=<directory> <package>dnf install --downloadonly --downloadir=<directory> <package> Now if you utilize the download argument then all the required dependencies will not display.
🌐
DevtoDevOps
devtodevops.com › blog › ansible-yum-install-rpm
Ansible Yum Install RPM: Master Package Management
June 3, 2025 - How to use the Ansible yum localinstall command to automate the installation of the local RPM package directly from your filesystem for offline deployment.
🌐
OneUptime
oneuptime.com › home › blog › how to use ansible to install packages from local .rpm files
How to Use Ansible to Install Packages from Local .rpm Files
February 21, 2026 - The dnf module accepts a local file path or URL as the package name: # Install an RPM file that is already on the remote host - name: Install custom application from RPM ansible.builtin.dnf: name: /tmp/myapp-2.5.0-1.el9.x86_64.rpm state: present disable_gpg_check: yes
🌐
Google Groups
groups.google.com › g › ansible-project › c › vqov_eiuWYE
Can I do yum localinstall with the yum module?
It's the same as yum localinstall in that the rpm needs to be present on the remote system. If you have it on the local system, do a copy task first to copy it remotely then use the yum module to install it. -Toshio · > -- > You received this message because you are subscribed to the Google ...
🌐
Reddit
reddit.com › r/ansible › install multiple rpm file at once on ansible
r/ansible on Reddit: Install multiple rpm file at once on ansible
August 9, 2021 -

So, I want to install some rpm package where it has dependencies between each other. I didnt use loop because it will not work. So, I create below task:

- name: Find rpm files and register the result
  find:
    paths: /tmp/docker
    patterns: "*.rpm"
  register: rpm_files

- set_fact:
    rpm_list: "{{ rpm_files.files | map(attribute='path') | list}}"
- debug:
    var: rpm_list

- name: Install rpm files using rpm_list
  yum:
    name: "{{ rpm_list }}"
    state: present

But the result is not as I expected, because it seems still looking from internet:

TASK [docker : Find rpm files and register the result] *****************************************************************************************************************************************************
ok: [10.54.54.22]

TASK [docker : set_fact] ***********************************************************************************************************************************************************************************
ok: [10.54.54.22]

TASK [docker : debug] **************************************************************************************************************************************************************************************
ok: [10.54.54.22] => {
    "rpm_list": [
        "/tmp/docker/docker-scan-plugin-0.8.0-3.el8.x86_64.rpm",
        "/tmp/docker/fuse3-3.2.1-12.el8.x86_64.rpm",
        "/tmp/docker/fuse3-libs-3.2.1-12.el8.x86_64.rpm",
        "/tmp/docker/fuse-common-3.2.1-12.el8.x86_64.rpm",
        "/tmp/docker/fuse-overlayfs-1.6-1.module_el8.5.0+870+f792de72.x86_64.rpm",
        "/tmp/docker/libcgroup-0.41-19.el8.x86_64.rpm",
        "/tmp/docker/libslirp-4.4.0-1.module_el8.5.0+870+f792de72.x86_64.rpm",
        "/tmp/docker/python3-dnf-plugins-core-4.0.21-1.el8.noarch.rpm",
        "/tmp/docker/slirp4netns-1.1.8-1.module_el8.5.0+733+9bb5dffa.x86_64.rpm",
        "/tmp/docker/tar-1.30-5.el8.x86_64.rpm",
        "/tmp/docker/dnf-plugins-core-4.0.21-1.el8.noarch.rpm",
        "/tmp/docker/yum-utils-4.0.21-1.el8.noarch.rpm",
        "/tmp/docker/container-selinux-2.164.1-1.module_el8.5.0+870+f792de72.noarch.rpm",
        "/tmp/docker/containerd.io-1.4.9-3.1.el8.x86_64.rpm",
        "/tmp/docker/docker-ce-20.10.7-3.el8.x86_64.rpm",
        "/tmp/docker/docker-ce-cli-20.10.7-3.el8.x86_64.rpm",
        "/tmp/docker/docker-ce-rootless-extras-20.10.7-3.el8.x86_64.rpm"
    ]
}

TASK [docker : Install rpm files using rpm_list] ***********************************************************************************************************************************************************
fatal: [10.54.54.22]: FAILED! => {"changed": false, "msg": "Failed to download packages: Curl error (6): Couldn't resolve host name for http://mirrorlist.centos.org/?release=8-stream&arch=x86_64&repo=BaseOS&infra=stock [Could not resolve host: mirrorlist.centos.org]", "results": []}

PLAY RECAP *************************************************************************************************************************************************************************************************
10.54.54.22                : ok=6    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0

Did something wrong on my rpm_list variable?

🌐
Reddit
reddit.com › r/ansible › deploying an rpm file via playbook
r/ansible on Reddit: Deploying an RPM file via Playbook
May 3, 2023 -

So I'm rather new to Ansible, I've worked in Puppet previously. I'm working on a Playbook for basic setup of all my Linux instances and one of the tasks is to download and install the IUS repos. Can you use the rpm -Uvh command in the task? Or is there another better way to do that.

🌐
GeeksforGeeks
geeksforgeeks.org › devops › install-rpm-package-in-linux-using-ansible
How to Install rpm Package in Linux Using Ansible ? - GeeksforGeeks
July 23, 2025 - --- - name: Install RPM package using Ansible hosts: localhost become: yes tasks: - name: Install RPM using Yum yum: name: "rpm" state: present
🌐
GitHub
github.com › oneuptime › blog › tree › master › posts › 2026-02-21-how-to-use-ansible-to-install-packages-from-local-rpm-files
blog/posts/2026-02-21-how-to-use-ansible-to-install-packages-from-local-rpm-files at master · OneUptime/blog
# Install RPM directly from URL (dnf downloads it) - name: Install EPEL release from URL ansible.builtin.dnf: name: https://dl.fedoraproject.org/pub/epel/epel-release-latest-9.noarch.rpm state: present disable_gpg_check: yes · The direct URL approach is simpler but less robust. There is no caching, no checksum verification, and the download happens each time Ansible checks the package state. Unlike dpkg on Debian, the dnf module with a local RPM file automatically resolves dependencies from configured repositories.
Author   OneUptime
🌐
Red Hat
access.redhat.com › discussions › 4220211
Red Hat Customer Portal - Access to 24x7 support and knowledge
June 17, 2019 - How do I install those packages from a playbook, without knowing those package names? ... --- - hosts: a.test.system strategy: free become_user: root become: yes become_method: sudo tasks: - name: run yum update from previously downloaded files. yum: name: "{{ item }}" state: present with_fileglob: - "{{/timp2/*.rpm}}" This seems good according to yml syntax, but isnt working as expected. ... playbooks]$ ansible-playbook -K yumupdatelocal.yml BECOME password: PLAY [test.system] ******************************************************************************************* TASK [Gathering Facts] ********************************************************************************************** ok: [test.system] TASK [run yum update from previously downloaded files.] ************************************************************* fatal: [test.system]: FAILED!
🌐
Google Groups
groups.google.com › g › ansible-devel › c › l07-3ZwwieE
Install multiple rpms from local filesysyem with yum module
I am trying to install Libreoffice using ansible yum module · Downloaded from https://downloadarchive.documentfoundation.org/libreoffice/old/4.4.1.2/rpm/x86_64/LibreOffice_4.4.1.2_Linux_x86-64_rpm.tar.gz · Extracted and all libreoffice rpms kept at /home//LibreOffice_4.4.1.2_Linux_x86-64_rpm/RPMS/ - yum: name: "/home/LibreOffice_4.4.1.2_Linux_x86-64_rpm/RPMS/*.rpm" state: present · above task failing with error · fatal: [localhost]: FAILED!
🌐
Ansible
docs.ansible.com › ansible › 2.9 › modules › yum_module.html
yum – Manages packages with the yum package manager — Ansible Documentation
However, if one of the packages ... epel-release) then that package needs to be installed in a separate task. This mimics yum’s command line behaviour. Yum itself has two types of groups. “Package groups” are specified in the rpm itself while “environment groups” are ...