在 Ansible 中,当我需要从 Java 属性文件 ( .properties
) 读取属性时,我会执行以下操作:
- name: Read properties
set_fact:
myProp1: {{ lookup('ini', 'myProp1 type=properties file=/path/to/file.properties }}
myProp2: {{ lookup('ini', 'myProp2 type=properties file=/path/to/file.properties }}
但是,如 Ansible documentation说:
Lookups occur on the local computer, not on the remote computer.
如果属性文件位于远程目标主机中,我该怎么做? 我不能使用 include_vars,因为我的属性文件具有 Java 属性文件格式。
最佳答案
正如您所观察到的,lookup
是本地的。我使用的一种可能的解决方案可能不适用于所有情况是在本地获取它然后调用查找。请务必阅读 fetch module在尝试之前:
- fetch:
src: /path/to/file.properties
dest: /tmp/file.properties
flat: yes
- name: Read properties
set_fact:
myProp1: {{ lookup('ini', 'myProp1 type=properties file=/tmp/file.properties }}
myProp2: {{ lookup('ini', 'myProp2 type=properties file=/tmp/file.properties }}
注意 : 这只是一种解决方法,而不是解决方案。
关于ansible - 是否有等效于查找但在目标主机而不是本地执行的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41400162/