Allow removal of entries in /etc/hosts
diff --git a/linux/network/host.sls b/linux/network/host.sls
index 6749350..02796eb 100644
--- a/linux/network/host.sls
+++ b/linux/network/host.sls
@@ -5,6 +5,8 @@
{%- if host.names is defined %}
+{%- if host.get('enabled', True) %}
+
linux_host_{{ name }}:
host.present:
- ip: {{ host.address }}
@@ -13,11 +15,11 @@
{%- if host.address in grains.ipv4 and host.names|length > 1 %}
{%- if host.names.1 in host.names.0 %}
-{%- set before = host.names.1 + " " + host.names.0 %}
-{%- set after = host.names.0 + " " + host.names.1 %}
+ {%- set before = host.names.1 + " " + host.names.0 %}
+ {%- set after = host.names.0 + " " + host.names.1 %}
{%- elif host.names.0 in host.names.1 %}
-{%- set before = host.names.0 + " " + host.names.1 %}
-{%- set after = host.names.1 + " " + host.names.0 %}
+ {%- set before = host.names.0 + " " + host.names.1 %}
+ {%- set after = host.names.1 + " " + host.names.0 %}
{%- endif %}
linux_host_{{ name }}_order_fix:
@@ -33,6 +35,15 @@
{%- endif %}
+{%- else %}
+
+linux_host_{{ name }}_absent:
+ host.absent:
+ - ip: {{ host.address }}
+ - names: {{ host.names }}
+
+{%- endif %}
+
{%- endif %}
{%- endfor %}
diff --git a/tests/pillar/network.sls b/tests/pillar/network.sls
index a8dfee6..a93df81 100644
--- a/tests/pillar/network.sls
+++ b/tests/pillar/network.sls
@@ -22,4 +22,16 @@
enabled: true
type: vlan
use_interfaces:
- - interface: ${linux:interface:eth0}
+ - interface: ${linux:interface:eth0}
+ host:
+ localhost:
+ address: 127.0.1.1
+ names:
+ - localhost.localdomain
+ - localhost
+ removed:
+ enabled: false
+ address: 127.0.1.6
+ names:
+ - removed.domain
+ - removed