Install rpm from control machine to ansible managed hosts

I tried to install rpm in ansible control machine to target machines using playbook

  • name: Install local rpm in server
    yum: pkg=files/mod_jk-1.2.40-5.el6.x86_64.rpm state=present
    when: ansible_os_family == ‘RedHat’

I got error :
failed: [xyz.cloudapp.net] => {“changed”: false, “failed”: true, “rc”: 0, “results”: }
msg: No Package file matching ‘files/mod_jk-1.2.40-5.el6.x86_64.rpm’ found on system

When I copied the same file in server and installed as local installation it works.

  • 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

no, currently the yum module only operates with files already on the
remote machine.

Thanks !

I’m installing packages from the control machine, but it’s a bit of work (so it probably won’t be worth it for just a few packages), and I’m still figuring out the details.

Basically, I create a local yum repository, then temporarily run an HTTP server on the control machine (maybe with Ansible 2.0 I can reliably start and kill it as part of the playbook, but right now it’s a manual process); for example using “python -m SimpleHTTPServer 8000”

I set the host to the control server using the SSH_CLIENT environment variable (if there’s a better way to access that, I’d like to know):

`
yum_local_host: “{{ (ansible_connection is defined and ansible_connection == ‘local’) | ternary(‘localhost’, ansible_env.SSH_CLIENT.split()[0]) }}”
yum_local_port: 8000
yum_repo_base: “http://{{ yum_local_host }}:{{ yum_local_port }}”

`

Then I use templates to set up the repositories on the remote side. Currently I’m looking at using a custom yum.conf so that it doesn’t interfere with the normal configuration.

If anyone wants more details, or has suggestions for how to improve this setup, let me know.

Is this still the case in ansible 2.2? The module document is not really clear.