Héc*_*tor 6 properties-file ansible
在 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 }}
Run Code Online (Sandbox Code Playgroud)
但是,正如Ansible 文档所述:
查找发生在本地计算机上,而不是远程计算机上。
如果属性文件位于远程目标主机,我该怎么办?我无法使用 include_vars,因为我的属性文件具有 Java 属性文件格式。
正如您所观察到的,lookup是本地的。我使用的一种可能的解决方案可能不适用于所有情况,即在本地获取它然后调用查找。在尝试此操作之前,请确保您阅读了有关fetch 模块的内容:
- 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 }}
Run Code Online (Sandbox Code Playgroud)
注意:这只是一种解决方法,而不是解决方案。
| 归档时间: |
|
| 查看次数: |
2313 次 |
| 最近记录: |