Parameter purge_hosts will enforce whole /etc/hosts file, removing entries that are not defined in model except defaults for both IPv4 and IPv6 localhost and hostname + fqdn. It's good to use this option if you want to ensure /etc/hosts is always in a clean state however it's not enabled by default for safety. Change-Id: Ieb219b2dd494d5a66ecc52a2ec00dd5157ee2b7atags/mcp0.5
@@ -514,12 +514,25 @@ Linux with proxy | |||
Linux with hosts | |||
Parameter purge_hosts will enforce whole /etc/hosts file, removing entries | |||
that are not defined in model except defaults for both IPv4 and IPv6 localhost | |||
and hostname + fqdn. | |||
It's good to use this option if you want to ensure /etc/hosts is always in a | |||
clean state however it's not enabled by default for safety. | |||
.. code-block:: yaml | |||
linux: | |||
network: | |||
... | |||
purge_hosts: true | |||
host: | |||
# No need to define this one if purge_hosts is true | |||
hostname: | |||
address: 127.0.1.1 | |||
names: | |||
- ${linux:network:fqdn} | |||
- ${linux:network:hostname} | |||
node1: | |||
address: 192.168.10.200 | |||
names: | |||
@@ -531,6 +544,7 @@ Linux with hosts | |||
- node2.domain.com | |||
- service2.domain.com | |||
Setup resolv.conf, nameservers, domain and search domains | |||
.. code-block:: yaml |
@@ -0,0 +1,33 @@ | |||
{#- | |||
vim: syntax=jinja | |||
-#} | |||
{%- from "linux/map.jinja" import network with context -%} | |||
# hosts(1) file managed by salt-minion(1) | |||
# DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN | |||
{%- set hosts = { | |||
'127.0.0.1': [ | |||
'localhost' | |||
], | |||
'127.0.1.1': [ | |||
network.fqdn|default(grains.fqdn), | |||
network.hostname|default(grains.nodename) | |||
], | |||
'::1': [ | |||
'localhost', | |||
'ip6-localhost', | |||
'ip6-loopback' | |||
], | |||
'ff02::1': [ | |||
'ip6-allnodes' | |||
], | |||
'ff02::2': [ | |||
'ip6-allrouters' | |||
], | |||
} -%} | |||
{%- for name, host in network.host.iteritems() -%} | |||
{%- do hosts.update({host.address: host.names}) -%} | |||
{%- endfor %} | |||
{% for address, entries in hosts|dictsort %} | |||
{{ address }} {{ entries|join(' ') }} | |||
{%- endfor %} |
@@ -1,6 +1,16 @@ | |||
{%- from "linux/map.jinja" import network with context %} | |||
{%- if network.enabled %} | |||
{%- if network.get('purge_hosts', false) %} | |||
linux_hosts: | |||
file.managed: | |||
- name: /etc/hosts | |||
- source: salt://linux/files/hosts | |||
- template: jinja | |||
{%- else %} | |||
{%- for name, host in network.host.iteritems() %} | |||
{%- if host.names is defined %} | |||
@@ -38,3 +48,5 @@ linux_host_{{ name }}_order_fix: | |||
{%- endfor %} | |||
{%- endif %} | |||
{%- endif %} |
@@ -1,7 +1,7 @@ | |||
{%- from "linux/map.jinja" import network with context %} | |||
include: | |||
- linux.network.hostname | |||
{%- if network.host|length > 0 %} | |||
{%- if network.host|length > 0 or network.get('purge_hosts', True) %} | |||
- linux.network.host | |||
{%- endif %} | |||
{%- if network.resolv is defined %} |