How to flatten host vars into a string.

48 views
Skip to first unread message

Alainkr

unread,
Sep 15, 2014, 6:54:35 AM9/15/14
to ansible...@googlegroups.com
Hello,

I'm trying to build a String based on host vars from a group.

I see how to loop thru host in a group 
{% for host in groups['app_servers'] %}
   {{ hostvars[host]['my_cool_var'] }}
{% endfor %}
But not how to flatten this into a string to get :
my_cool_val1, my_cool_val2,...,my_cool_vallast
Thanks for you help

Alain

Serge van Ginderachter

unread,
Sep 15, 2014, 7:12:44 AM9/15/14
to ansible...@googlegroups.com
something like

{% for cmd in tester_commands_root_extra %}{{ cmd }}{% if not loop.last %}, {% endif %}{% endfor %}

--
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-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/8d20763f-d6c7-4383-b11c-ce06e5391999%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Alainkr

unread,
Sep 15, 2014, 8:09:34 AM9/15/14
to ansible...@googlegroups.com
Super. Thanks for your quick reply. Exactly what I needed

Alain

Brian Coca

unread,
Sep 15, 2014, 8:58:39 PM9/15/14
to ansible...@googlegroups.com
several ways, with a for loop:

{% for host in groups['app_servers'] %}{{
hostvars[host]['my_cool_var'] }}{% if not loop.last %},{% endi f%}{%
endfor %}
Reply all
Reply to author
Forward
0 new messages