Linux – Where does ansible package module search for given package name

ansiblecloudlinux

I am new to ansible and trying to copy and install jdk on remote machine. I would like to use rpm install only considering I have all different flavours of clients.(RHEL, Centos, Ubuntu etc). Below is my playbook

    - hosts: all_clients
      remote_user: root
      tasks:
       - name: copy jdk rpm on client machine usr/tmp
         copy:
             src: ./RPM/jdk8u73x64.rpm
             dest: /usr/tmp/jdk8u73x64.rpm

       - name: start installation of jdk
         package:
             name: /usr/tmp/jdk8u73x64.rpm
             #name: jdk8u73x64.rpm
             state: latest
             #use: rpm

But I am getting below error.

TASK [setup] *******************************************************************
ok: [10.219.161.98]

TASK [copy jdk rpm on client machine usr/tmp] **********************************
ok: [10.219.161.98]

TASK [start installation of jdk] ***********************************************
fatal: [10.219.161.98]: FAILED! => {"changed": false, "failed": true, "msg": "No Package matching 'jdk8u73x64.rpm' found available, installed or updated", "rc": 0, "results": []}

NO MORE HOSTS LEFT *************************************************************
        to retry, use: --limit @test2.retry

PLAY RECAP *********************************************************************
10.219.161.98              : ok=2    changed=0    unreachable=0    failed=1

Ansible package module description doesn't say much about where does it search for package on client machine. Can someone please help me to make it work?

Best Answer

First, locations are generally resolved from the location of the playbook.

Secondly, package isn't designed for installing a local file, but rather for fetching from the remote repositories.

Thirdly, the reason package behaves like so is because it doesn't really make sense for an OS-independent layer to be fed an OS-dependent file; by definition, an .rpm is only able to be installed on a system with rpm, and not one that instead uses apt, or pacman, or portage, or whatever.

You will want to use the yum module for installing the rpm on your rpm-based machines. If, as you say, you're supporting Ubuntu machines as well, you'll need to filter those out using a conditional and add a separate rule for installing an equivalent .deb on them.

However, if all you're trying to do is install Java, that should be available in the repos already, and you can avoid all this copying around of files.