在我的情况下,我将我的Ansible代码安装在/ansible/playbook/
下的Docker容器中。在此目录下,您将看到roles
,inventories
我想安装另一个包含一些RPM文件的目录。
在Ansible中我有此代码:
---
- 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
问题在于默认搜索路径中都不存在Zookeeper:
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
如何在此列表中添加额外的搜索路径:
/ansible/rpms/zookeeper-3.4.13-1.x86_64.rpm//
我不想在Ansible代码中使用硬码绝对路径(如果可行)。我想提供类似: ANSIBLE_EXTRA_SEARCH_PATH
的东西。
我该怎么做?
ps:我无法在已经安装的/ansible/playbook
内部的RPM目录中创建一个符号链接,因为Docker会看到它且链接不好(无法读取它,因为目标目录,包含RPM文件的目标目录不是部分docker容器文件系统。)
一个选项是
- 将rpm放入 any_path 中
- 链接 any_path to/ansible/playbook/rpms
- 使用 src:rpms/zookeeper-3.4.13-1.x86_64.rpm
您可以使用带有路径列表的查找和first_found
查询:
- 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']
更多信息,请访问https://docs.ansible.com/ansible/latest/user_guide/playbooks_conditionals.html#selecting-filesing-files--files-and-templates----templates-on-on-on-on-niables