Answer the question
In order to leave comments, you need to log in
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 %}]
[{% 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 questionAsk a Question
731 491 924 answers to any question