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
Ansible yum install rpm on remote server - Stack Overflow
Really having a hard time with trying to install a rpm package that is on a server via ansible. my script is · --- - hosts: "{{ hostlist | default('all') }}" vars: remote_path: "{{ remotepath | default('/usr/local/bin') }}" rpm_package: "{{ package }}" task: - name: install rpm package yum: ... More on stackoverflow.com
🌐 stackoverflow.com
Yum module's state=present with URL/path of RPM won't update a package (behavior change)
ISSUE TYPE Bug Report COMPONENT NAME yum ANSIBLE VERSION ansible 2.1.2.0 (stable-2.1 fc3efdb057) last updated 2016/08/25 08:46:54 (GMT +1000) lib/ansible/modules/core: (detached HEAD edbd108b15) la... More on github.com
🌐 github.com
5
August 25, 2016
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.
🌐
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.
🌐
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.
🌐
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.
Find elsewhere
🌐
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
🌐
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 ...
🌐
GitHub
github.com › ansible › ansible-modules-core › issues › 4529
Yum module's state=present with URL/path of RPM won't update a package (behavior change) · Issue #4529 · ansible/ansible-modules-core
August 25, 2016 - ensure bash older than bash-4.1.2-40.el6.x86_64.rpm is installed on target system ... ansible <host args> -m yum -a 'state=present name=http://mirror.centos.org/centos/6/os/x86_64/Packages/bash-4.1.2-40.el6.x86_64.rpm'
Author   rohanpm
🌐
Ansible
docs.ansible.com › ansible › 9 › collections › ansible › builtin › yum_module.html
ansible.builtin.yum module – Manages packages with the yum package manager — Ansible Community Documentation
December 3, 2024 - 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 ...
🌐
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.
🌐
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 ...
🌐
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?

🌐
GitHub
github.com › ansible › ansible › issues › 338
localinstall for yum package? · Issue #338 · ansible/ansible
May 8, 2012 - Is support for localinstall for the yum package anywhere in the roadmap? Would love to be able to send over specific rpm's to install - can copy the file over and shell out, but it'd be super pleasant to have all the goods such that it doesn't even copy over the file if the version hasn't changed.
Author   nybble73
🌐
Red Hat
access.redhat.com › discussions › 4220211
Using ansible to install previously downloaded patches.
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
=> {"changed": false, "failed": true, "msg": "No Package file matching '/home/LibreOffice_4.4.1.2_Linux_x86-64_rpm/RPMS/*.rpm' found on system", "rc": 0, "results": []} ... Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message ... Look into using with_fileglob for looping over a list of local files. ... -- You received this message because you are subscribed to the Google Groups "Ansible Development" group.
🌐
Ansible
docs.ansible.com › ansible › latest › collections › ansible › builtin › yum_module.html
ansible.builtin.yum module — Ansible Community Documentation
This redirect is part of ansible-core and included in all Ansible installations. In most cases, you can use the short module name yum even without specifying the collections keyword.