Kaynağa Gözat

Remove excess records from /etc/hosts

Before adding new records to /etc/hosts, remove all hostnames
that are managed by the model but have different addresses
than provided in the model.

Change-Id: Idf5a30429497c33027e6ba973e684ba0443a1edf
tags/mcp0.5
Dennis Dmitriev 8 yıl önce
ebeveyn
işleme
279521e7d5
1 değiştirilmiş dosya ile 21 ekleme ve 0 silme
  1. +21
    -0
      linux/network/host.sls

+ 21
- 0
linux/network/host.sls Dosyayı Görüntüle

@@ -15,10 +15,31 @@ linux_hosts:

{%- if host.names is defined %}

{%- set clearers = [] %}
{%- for etc_addr, etc_names in salt.hosts.list_hosts().iteritems() %}
{%- set names_to_clear = [] %}
{%- for host_name in host.names %}
{%- if (host.address != etc_addr) and host_name in etc_names %}
{%- do names_to_clear.append(host_name) %}
{%- endif %}
{%- endfor %}
{%- if names_to_clear != [] %}
{%- set clearer = "linux_host_" + name + "_" + etc_addr + "_clear" %}
{%- do clearers.append(clearer) %}

{{ clearer }}:
host.absent:
- ip: {{ etc_addr }}
- names: {{ names_to_clear }}

{%- endif %}
{%- endfor %}

linux_host_{{ name }}:
host.present:
- ip: {{ host.address }}
- names: {{ host.names }}
- require: {{ clearers }}

{%- if host.address in grains.ipv4 and host.names|length > 1 %}


Yükleniyor…
İptal
Kaydet