-
Notifications
You must be signed in to change notification settings - Fork 10
/
hosts.j2
73 lines (68 loc) · 4.79 KB
/
hosts.j2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# {{ ansible_managed }}
# The following lines are desirable for IPv4 capable hosts
{% if hosts_hostname_loopback %}
127.0.0.1 {{ inventory_hostname | lower }} {{ inventory_hostname_short | lower }}
{% endif %}
127.0.0.1 localhost.localdomain localhost
127.0.0.1 localhost4.localdomain4 localhost4
{{ hosts_ipv4_address }} {{ inventory_hostname | lower }} {{ inventory_hostname_short | lower }}
{% if ansible_lo.ipv6 is defined and hosts_ipv6 %}
# The following lines are desirable for IPv6 capable hosts
{% if hosts_hostname_loopback %}
::1 {{ inventory_hostname | lower }} {{ inventory_hostname_short | lower }}
{% endif %}
::1 localhost.localdomain localhost
::1 localhost6.localdomain6 localhost6
::1 ip6-localhost ip6-loopback
{% if hostvars[inventory_hostname]['ansible_default_ipv6']['address'] is defined %}
{{ hostvars[inventory_hostname]['ansible_default_ipv6']['address'] }} {{ inventory_hostname | lower }} {{ inventory_hostname_short | lower }}
{% endif %}
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts
{% endif %}
{% if hosts_inventory_to_hosts %}
# The following lines are generated from the ansible inventory
{% for host in groups['all'] %}
{% if hostvars[host]['ansible_interfaces'] is defined %}
{% for interface in hostvars[host]['ansible_interfaces'] %}
{% if interface | regex_search('^((?!' + hosts_exludes_interfaces | join('|') + '*).)*$') %}
{% if hostvars[host]['ansible_' + interface]['ipv4']['address'] | ansible.netcommon.ipaddr('private') and hosts_all_private %}
{{ hostvars[host]['ansible_' + interface]['ipv4']['address'] }} {{ hostvars[host]['ansible_hostname'] }} {{ host }}{{ " " if hostvars[host]['hosts_aliases'] is defined }}{% if hostvars[host]['hosts_aliases'] is defined %}{% for alias in hostvars[host]['hosts_aliases'] %}{{ alias }}{{ " " if not loop.last }}{% endfor %}{% endif %}{{ '\n' -}}
{% elif hostvars[host]['ansible_' + interface]['ipv4']['address'] | ansible.netcommon.ipaddr('public') and hosts_all_public %}
{{ hostvars[host]['ansible_' + interface]['ipv4']['address'] }} {{ hostvars[host]['ansible_hostname'] }} {{ host }}{{ " " if hostvars[host]['hosts_aliases'] is defined }}{% if hostvars[host]['hosts_aliases'] is defined %}{% for alias in hostvars[host]['hosts_aliases'] %}{{ alias }}{{ " " if not loop.last }}{% endfor %}{% endif %}{{ '\n' -}}
{% elif not hosts_all_private and not hosts_all_public %}
{{ hostvars[host]['ansible_default_ipv4']['address'] }} {{ hostvars[host]['ansible_hostname'] }} {{ host }}{{ " " if hostvars[host]['hosts_aliases'] is defined }}{% if hostvars[host]['hosts_aliases'] is defined %}{% for alias in hostvars[host]['hosts_aliases'] %}{{ alias }}{{ " " if not loop.last }}{% endfor %}{% endif %}{{ '\n' -}}
{% endif %}
{% endif %}
{% endfor %}
{% endif %}
{% endfor %}
{% if hosts_ipv6 %}
{% for host in groups['all'] %}
{% if hostvars[host]['ansible_interfaces'] is defined %}
{% for interface in hostvars[host]['ansible_interfaces'] %}
{% if interface | regex_search('^((?!' + hosts_exludes_interfaces | join('|') + '*).)*$') %}
{% if hostvars[host]['ansible_' + interface]['ipv6']['address'] | ansible.netcommon.ipaddr('private') and hosts_all_private %}
{{ hostvars[host]['ansible_' + interface]['ipv6']['address'] }} {{ hostvars[host]['ansible_hostname'] }} {{ host }} {% set aliases=[] %}{% if hostvars[host]['hosts_aliases'] is defined %}{% for alias in hostvars[host]['hosts_aliases'] %}{% if alias != hostvars[host]['internel_ansible_host'] %}{{ aliases.append(alias) }}{% endif %}{% endfor %}{% endif %}
{% elif hostvars[host]['ansible_' + interface]['ipv6']['address'] | ansible.netcommon.ipaddr('public') and hosts_all_public %}
{{ hostvars[host]['ansible_' + interface]['ipv6']['address'] }} {{ hostvars[host]['ansible_hostname'] }} {{ host }} {% set aliases=[] %}{% if hostvars[host]['hosts_aliases'] is defined %}{% for alias in hostvars[host]['hosts_aliases'] %}{% if alias != hostvars[host]['internel_ansible_host'] %}{{ aliases.append(alias) }}{% endif %}{% endfor %}{% endif %}
{% elif not hosts_all_private and not hosts_all_public %}
{{ hostvars[host]['ansible_default_ipv6']['address'] }} {{ hostvars[host]['ansible_hostname'] }} {{ host }} {% set aliases=[] %}{% if hostvars[host]['hosts_aliases'] is defined %}{% for alias in hostvars[host]['hosts_aliases'] %}{% if alias != hostvars[host]['internel_ansible_host'] %}{{ aliases.append(alias) }}{% endif %}{% endfor %}{% endif %}
{% endif %}
{% endif %}
{% endfor %}
{% endif %}
{% endfor %}
{% endif %}
{% endif %}
{% if hosts_dns_hostname is defined %}
# The following lines are generated by ansible with hosts_dns_hostname variable
{% for item in hosts_dns_hostname %}
{{ item.address }} {{ item.hostname }}{% if item.aliases is defined %}{% for alias in item.aliases %} {{ alias }}{% endfor %}{% endif %}
{% if not loop.last %}
{% endif %}
{% endfor %}
{% endif %}