I have the following problem:
I’m reading a simple json file which contains some names of my hosts.
The file looks like this:
{ “redundancynode”: “node4”, “service”: “dhcp”, “servicenode” “node1” }
Now i have a task to read the contents of that file:
vars:
file_content: "{{ lookup(‘file’, ‘/tmp/info’) }}
tasks:
name: Read from local file /tmp/info
debug:
msg: “{{ file_content }}”
The Output of Ansible for that file looks like this:
I have the following problem:
I'm reading a simple json file which contains some names of my hosts.
The file looks like this:
{ "redundancynode": "node4", "service": "dhcp", "servicenode" "node1" }
Now i have a task to read the contents of that file:
tasks:
- name: Read from local file /tmp/info
debug:
msg: "{{ file_content }}"
The Output of Ansible for that file looks like this:
ok: [127.0.0.1] => {
"msg": {
"redundancynode": "node4",
"service": "dhcp",
"servicenode": "node1"
}
}
I used set_fact to get the actual nodes for servicenode and redundancynode:
I tried this, but it just gives me error:
“The conditional check ‘inventory_hostname == redundancynode’ failed. The error was: error while evaluating conditional (inventory_hostname == redundancynode): ‘redundancynode’ is undefined”
It is also not possible to use jinja2 for that
when: inventory_hostname == {{ redundancynode }} or
I tried this, but it just gives me error:
"The conditional check 'inventory_hostname == redundancynode' failed. The error was: error while evaluating conditional
(inventory_hostname == redundancynode): 'redundancynode' is undefined"
You have to set this variable, otherwise your playbook doesn't work.