1

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?

  • First, it's worth noting that ansible 2.0 is relatively new, and (frankly, in my opinion) still so broken that it can't be honestly called stable. It might be stable by 2.1, but at the moment it's a disaster. If I were you I'd be using ansible 1.9. Second, there's no `rpm` provider, but there **is** a `yum` provider. You may want to use that. If that doesn't work, you can use the `yum` module, or you can switch to a `file:///` URI. – Parthian Shot Mar 16 '16 at 14:02
  • I mention the newness of ansible 2.0, not just because I think it's unwise to use generally (at this point, anyway), but also because the `package` module is new in ansible 2.0. Which means that, if some aspect of how it's implemented is currently undocumented, that may well mean that aspect is subject to change, since extremely new modules are more likely to be under active development. – Parthian Shot Mar 16 '16 at 14:07
  • Go with the `yum` module. It can use local rpm files. There is an example in the [documentation](http://docs.ansible.com/ansible/yum_module.html). I see some problems with the package module in general. as distros sometimes name packages different. So using the package module alone does not necessary make your play run on any distribution. – Henrik Pingel Mar 16 '16 at 14:40
  • Will yum module work with all the flavor of linux? (Ubuntu, SLES, RHEL etc)? I want to make same playbook work with each client. – Ashif Nataliya Mar 16 '16 at 18:10
  • No, of course not. Ubuntu for example is a deb based distribution and you will not be able to install an rpm package on a debian based distribution anyways. So you will need to work with conditionals like this anyways: `when: ansible_os_family == "RedHat"` – Henrik Pingel Mar 17 '16 at 08:13

1 Answers1

2

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.

Xiong Chiamiov
  • 2,874
  • 2
  • 26
  • 30