Last active
August 29, 2015 13:55
-
-
Save agile/8744475 to your computer and use it in GitHub Desktop.
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
# {{ansible_managed}} | |
127.0.0.1 localhost.localdomain localhost | |
::1 localhost6.localdomain6 localhost6 | |
{% for item in groups['all'] %} | |
{% set ip = next(ip for ip in hostvars[item]['ansible_all_ipv4_addresses'] if ip.find("10.") == 0, hostvars[item]['ansible_default_ipv4']) %} | |
{% if ip %} | |
{{ ip }} {{ item }} | |
{% endif %} | |
{% endfor %} |
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
>>> hostvars = { 'fred': { 'ansible_all_ipv4_addresses': ["10.123.123.123", "184.123.123.123"] } } | |
>>> item = 'fred' | |
>>> next((ip for ip in hostvars[item]['ansible_all_ipv4_addresses'] if ip.find("10.") == 0), None) | |
'10.123.123.123' |
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
fatal: [somehost] => {'msg': "file: /some/path/templates/hosts.j2, line number: 5, error: expected token ',', got 'for'", 'failed': True} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment