1

In my case I am mounting my Ansible code inside a Docker container under /ansible/playbook/. Under this directory you will see the roles, inventories

I would like to mount another directory that contains some RPM files.

In Ansible I have this code:

---
- name: copy ZooKeeper rpm file
  copy:
    src: zookeeper-3.4.13-1.x86_64.rpm
    dest: /tmp

- name: install ZooKeeper rpm package
  yum:
    name: /tmp/zookeeper-3.4.13-1.x86_64.rpm
    state: present

The problem is that ZooKeeper does not exist in any of the default search paths:

Could not find or access 'zookeeper-3.4.13-1.x86_64.rpm'
Searched in:
    /ansible/playbook/roles/kafka/files/zookeeper-3.4.13-1.x86_64.rpm
    /ansible/playbook/roles/kafka/zookeeper-3.4.13-1.x86_64.rpm
    /ansible/playbook/roles/kafka/tasks/files/zookeeper-3.4.13-1.x86_64.rpm
    /ansible/playbook/roles/kafka/tasks/zookeeper-3.4.13-1.x86_64.rpm
    /ansible/playbook/files/zookeeper-3.4.13-1.x86_64.rpm
    /ansible/playbook/zookeeper-3.4.13-1.x86_64.rpm

How can I add extra search paths to this list for example:

    /ansible/rpms/zookeeper-3.4.13-1.x86_64.rpm//

I don't want to hardcode absolute paths (if this works) in the Ansible code. I would like to provide something like: ANSIBLE_EXTRA_SEARCH_PATH.

How can I do this?

PS: I cannot create a symlink to my RPM directory inside the already mounted /ansible/playbook because Docker will see it and a bad link (not being able to read it, because the target directory, the one containing the RPM files is not part of the Docker container file system.)

Gabriel Petrovay
  • 20,476
  • 22
  • 97
  • 168

2 Answers2

2

An option would be to

  • put the rpm in any_path
  • link any_path to /ansible/playbook/rpms
  • use src: rpms/zookeeper-3.4.13-1.x86_64.rpm
Vladimir Botka
  • 58,131
  • 4
  • 32
  • 63
  • Actually this will not work because: 1. you cannot create hard links to directories (or at least I did not find a way to do it). 2. Soft links are not properly visible inside Docker container because the original linked directory (`any_path`) is not visible inside the container. – Gabriel Petrovay Feb 17 '19 at 20:31
0

You could use a lookup with a list of paths and the first_found query:

- name: install ZooKeeper rpm package
  yum:
    name: "{{ item }}/zookeeper-3.4.13-1.x86_64.rpm"
    state: present
  loop: "{{ query('first_found', { 'paths': mypaths}) }}"
  vars:
    mypaths: ['/tmp', '/opt/other_location/somedir/', '/rpms']

More information at https://docs.ansible.com/ansible/latest/user_guide/playbooks_conditionals.html#selecting-files-and-templates-based-on-variables

Bruce Becker
  • 335
  • 1
  • 6
  • 23