Skip to content

Commit a8329b8

Browse files
committed
define etc_hosts_extra_hosts
1 parent 32325fd commit a8329b8

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
lines changed

ansible/roles/etc_hosts/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
Hosts in the `etc_hosts` groups have `/etc/hosts` created with entries of the format `IP_address canonical_hostname [alias]`.
44

5-
By default, an entry is created for each host in this group, using `ansible_host` as the IP_address and `inventory_hostname` as the canonical hostname. This may need overriding for multi-homed hosts.
5+
By default, an entry is created for each host in this group, using `ansible_host` as the IP_address and `inventory_hostname` as the canonical hostname. This may need overriding for multi-homed hosts or hosts with multiple aliases.
66

77
# Variables
88

99
- `etc_hosts_template`: Template file to use. Default is the in-role template.
10-
- `etc_hosts_hosts`: Hosts to create an entry for in `/etc/hosts`. Default is hosts in the group `etc_hosts`. NB: this is different from the hosts on which `/etc/hosts` is created, which is always the hosts in the `etc_hosts` group. This allows additional hosts to be added to `/etc/hosts` by defining them in inventory and referencing them in this variable.
1110
- `etc_hosts_hostvars`: A list of variable names, used (in the order supplied) to create the entry for each host. Default is `['ansible_host', 'inventory_hostname']`
11+
- `etc_hosts_extra_hosts`: String (possibly multi-line) defining additional hosts to add to `/etc/hosts`. Default is empty string.

ansible/roles/etc_hosts/defaults/main.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ etc_hosts_hosts: "{{ groups['etc_hosts'] }}"
33
etc_hosts_hostvars:
44
- ansible_host
55
- inventory_hostname
6+
etc_hosts_extra_hosts: ''
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
22
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
33

4-
{% for inventory_hostname in etc_hosts_hosts | sort -%}
4+
{% for inventory_hostname in groups['etc_hosts'] | sort -%}
55
{{ hostvars[inventory_hostname] | json_query('[' + ( etc_hosts_hostvars | join(', ') ) + ']' ) | join(' ')}}
66
{% endfor %}
7+
{% if etc_hosts_extra_hosts != '' %}
8+
{{ etc_hosts_extra_hosts }}
9+
{% endif %}

0 commit comments

Comments
 (0)