On 9/8/20 1:13 PM, [email protected] wrote:
> Hello guys,
> 
> 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:
> 
> 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:
> 
> - set_fact: redundancynode="{{output.msg.redundancynode}}"
> 
> - set_fact: servicenode="{{ output.msg.servicenode }}"
> 
> debggung for example redundancynode gives me as expected the following output:
> 
> ok: [127.0.0.1] => {
>     "msg": "node4"
> }
> 
> Now,  I want to use the content of "redundancy node", which is "node4" in 
> another task as condition:
> when: inventory_hostname == "redundanynode"
> 
> But this does not work. It just skips the task for all nodes.
> 
> (BTW: node4 does exist in my inventory file of course)
> 
> What am I missing? Im searching  for a solution since hours.

1. you have a typo in the when statement
2. putting the variable name in "" makes it a literal string, so it evaluates 
to redundanynode

Regards
        Racke

> 
> Thank you advance!
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to
> [email protected] 
> <mailto:[email protected]>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/c66990f7-be94-40c5-a4fe-346c76ec8655n%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/c66990f7-be94-40c5-a4fe-346c76ec8655n%40googlegroups.com?utm_medium=email&utm_source=footer>.


-- 
Ecommerce and Linux consulting + Perl and web application programming.
Debian and Sympa administration. Provisioning with Ansible.

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/49645b74-b101-f8e8-08f0-9191d425e881%40linuxia.de.

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to