Reputation: 26084
In Ansible, when I need to read properties from a Java properties file (.properties
), I do something like:
- 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 }}
But, as Ansible documentation says:
Lookups occur on the local computer, not on the remote computer.
How can I do it if the properties file is located in remote target host? I can't use include_vars, since my properties file has Java properties file format.
Upvotes: 6
Views: 2550
Reputation: 52423
As you observed, lookup
is local. One possible solution is I used which may not work in all situations is to fetch it locally and then call lookup. Make sure you read about fetch module before attempting this:
- 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 }}
CAUTION: This is just a workaround, not a solution.
Upvotes: 3