是否等同于查找,但在目标主机而不是本地执行



在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文档所说:

查找出现在本地计算机上,而不是在远程计算机上。

如果属性文件位于远程目标主机中,该怎么办?我无法使用Indubly_vars,因为我的属性文件具有Java属性文件格式。

正如您所观察到的,lookup是本地的。我使用的一种可能的解决方案可能在所有情况下都无法使用,就是在本地获取它,然后致电查找。在尝试此操作之前,请确保您阅读有关提取模块的信息:

- 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 }}

小心:这只是解决方法,而不是解决方案。

最新更新