On Friday, 23 February 2018 13.28.32 CET David Fazeli wrote:
> Please explain to me how can I fix this problem? i have this file 
> defaults/main.yml
> 
> ---
> node1:
>  ip: 1.1.1.1
> 
> node2:
>  ip: 2.2.2.2
> 
> node3:
>  ip: 3.3.3.3 
> 
> 
> Now, I want in template file ip.j2 by for loop access the IPs of each 
> server and save in address variable
> 
> Like this:
> 
> address= 1.1.1.1,2.2.2.2,3.3.3.3
> 
> 
> I tried this code:
> 
> address={% for x in {{nubmer_nodes}} %}

You are already in template mode so you can't use {{ }}
address={% for x in nubmer_nodes %}

You have not shown your nubmer_nodes, but to make it work it need to be [1, 2, 
3] for it to work.


> {{node[x].ip}}

This try to look up a likt named node, you need
{{ vars['node' ~ x }}


> {% if loop.last %},{% endif %}

This will only print , at the end, you are missing a not.
And to suppress the newline in the previous line you also need a - added

{%- if not loop.last %},{% endif %}


-- 
Kai Stian Olstad

-- 
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 ansible-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/4861333.f4AaPEDd7g%40x1.
For more options, visit https://groups.google.com/d/optout.

Reply via email to