K
K
Konstantin Rudenkov2015-11-10 20:17:24
Ansible
Konstantin Rudenkov, 2015-11-10 20:17:24

How to output a list of host addresses in a group to ansible variable?

Hello.
How can I output a list of host addresses in a group into a formatted variable?
As an example: there is a type variable:
cluster_addresses=["ip1", "ip2", ... , "ipN"]
addresses are in facts. But here I do not understand what construction to create such a variable.
UPD: This is the code

[{% for host in groups['elasticsearch'] %} "{{ hostvars[host]['ansible_eth0']['ipv4']['address']}}", {% endfor %}]

But I have not yet figured out how to remove the last comma
UPD2 [SOLUTION]
[{% for host in groups['elasticsearch'] %}"{{ hostvars[host]['ansible_eth0']['ipv4']['address']}}"{% if not loop.last %}, {% endif %}{% endfor %}]

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question