-
Notifications
You must be signed in to change notification settings - Fork 3
/
hosts.j2
42 lines (39 loc) · 2.4 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
# {{ ansible_managed }}
{% if hosts_hostname is defined and hosts_hostname.hostname is defined and hosts_hostname.alias_loopback is defined and hosts_hostname.domain is defined and hosts_hostname.ipv6 is defined %}
{% if hosts_hostname.alias_loopback %}
127.0.0.1 {{ hosts_hostname.hostname }}.{{ hosts_hostname.domain }} {{ hosts_hostname.hostname }}{% if hosts_hostname.alias is defined %}{% for alias in hosts_hostname.alias %} {{ alias }}{% endfor %}{% endif %} localhost localhost.localdomain localhost4 localhost4.localdomain4
{% endif %}
{% if hosts_hostname is defined and not hosts_hostname.alias_loopback %}
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
{% endif %}
{% if hosts_hostname.ipv6 %}
{% if hosts_hostname.alias_loopback %}
::1 {{ hosts_hostname.hostname }}.{{ hosts_hostname.domain }} {{ hosts_hostname.hostname }}{% if hosts_hostname.alias is defined %}{% for alias in hosts_hostname.alias %} {{ alias }}{% endfor %}{% endif %} localhost localhost.localdomain localhost6 localhost6.localdomain6
{% endif %}
{% if not hosts_hostname.alias_loopback %}
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
{% endif %}
{% endif %}
{% if hosts_hostname.add_ips is defined and hosts_hostname.add_ips | length > 0 %}
{% for ip in hosts_hostname.add_ips %}
{% set space = 18 - ip | length %}
{{ ip }}{% for i in range(1, space,1) %} {% endfor %}{{ hosts_hostname.hostname }}.{{ hosts_hostname.domain }} {{ hosts_hostname.hostname }}{% if hosts_hostname.alias is defined %}{% for alias in hosts_hostname.alias %} {{ alias }}{% endfor %}{% endif %}
{% endfor %}
{% endif %}
{% else %}
{# Handle localhost loopback entry when hosts_hostname is undefined #}
{% if hosts_add_hosts is defined %}
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
{% endif %}
{% endif %}
{% if hosts_add_hosts is defined and hosts_add_hosts | length > 0 %}
{% for host in hosts_add_hosts %}
{% if host.hostname is defined and host.domain is defined and host.ip_addr is defined %}
{% if host.comment is defined %}
# {{ host.comment }}
{% endif %}
{% set space = 18 - host.ip_addr | length %}
{{ host.ip_addr }}{% for i in range(1, space,1) %} {% endfor %}{{ host.hostname }}.{{ host.domain }} {{ host.hostname }}{% if host.alias is defined %}{% for alias in host.alias %} {{ alias }}{% endfor %}{% endif %}
{% endif %}
{% endfor %}
{% endif %}