Created
March 23, 2017 09:21
-
-
Save kustodian/385f70fa7b55a01ccd8aff2f59bd4108 to your computer and use it in GitHub Desktop.
Ansible - Use template lookup in a role to generate a list of IP addresses from a hostgroup
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% if myhostgroup != '' %} | |
{% for host in groups[myhostgroup] %} | |
- {{ hostvars[host]["ansible_default_ipv4"]["address"] }} | |
{% endfor %} | |
{% endif %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
- hosts: myhosts | |
vars: | |
hostgroup_ips: '{{ lookup("template", "hostgroup_ips.j2") | from_yaml }}' | |
tasks: | |
- debug: | |
var: '{{ hostgroup_ips|join(",") }}' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment