[network] Enable resolvconf service
When resolv.conf contained "search" keyword with no arguments
host/nslookup/dig utilities failed to parse it correctly.
This happens on systems with disabled resolvconf service and
gateway defined on any interface.
Change-Id: I6b95d038562eb457a856bba6104b7dbf9cc97d52
Closes-Bug: PROD-25927
diff --git a/README.rst b/README.rst
index 4efa5e2..9655d5e 100644
--- a/README.rst
+++ b/README.rst
@@ -1829,7 +1829,7 @@
- node2.domain.com
- service2.domain.com
-Set up ``resolv.conf``, nameservers, domain and search domains:
+Set up ``resolvconf's basic resolver info``, e.g. nameservers, search/domain and options:
.. code-block:: yaml
@@ -1837,16 +1837,16 @@
network:
resolv:
dns:
- - 8.8.4.4
- - 8.8.8.8
+ - 8.8.4.4
+ - 8.8.8.8
domain: my.example.com
search:
- - my.example.com
- - example.com
+ - my.example.com
+ - example.com
options:
- - ndots: 5
- - timeout: 2
- - attempts: 2
+ - ndots:5
+ - timeout:2
+ - attempts:2
Set up custom TX queue length for tap interfaces:
diff --git a/linux/files/resolv.conf b/linux/files/resolv.conf
deleted file mode 100644
index 43fb75d..0000000
--- a/linux/files/resolv.conf
+++ /dev/null
@@ -1,16 +0,0 @@
-{%- from "linux/map.jinja" import network with context %}# Dynamic resolv.conf(5) file for glibc resolver(3) generated by salt-minion(1)
-# DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
-{% if network.resolv.get('search', False) -%}
-search {{ network.resolv.search|join(' ') }}
-{%- endif %}
-{% if network.resolv.get('domain', False) -%}
-domain {{ network.resolv.domain }}
-{%- endif %}
-{%- for nameserver in network.resolv.dns %}
-nameserver {{ nameserver }}
-{%- endfor %}
-{%- if network.resolv.get('options', False) %}
-{%- for option in network.resolv.options %}
-options {{ option }}
-{%- endfor %}
-{%- endif %}
diff --git a/linux/files/resolvconf_base b/linux/files/resolvconf_base
new file mode 100644
index 0000000..0ecd1a1
--- /dev/null
+++ b/linux/files/resolvconf_base
@@ -0,0 +1,13 @@
+{%- from "linux/map.jinja" import network with context -%}
+{%- if network.resolv.domain is defined %}
+domain {{ network.resolv.domain }}
+{%- endif %}
+{%- if network.resolv.search is defined %}
+search {{ network.resolv.search|join(' ') }}
+{%- endif %}
+{%- for ns in network.resolv.dns|d([]) %}
+nameserver {{ ns }}
+{%- endfor %}
+{%- for opt in network.resolv.options|d([]) %}
+options {{ opt }}
+{%- endfor %}
diff --git a/linux/network/init.sls b/linux/network/init.sls
index 448fbff..0c0f140 100644
--- a/linux/network/init.sls
+++ b/linux/network/init.sls
@@ -6,9 +6,7 @@
{%- if network.host|length > 0 or network.get('purge_hosts', True) %}
- linux.network.host
{%- endif %}
-{%- if network.resolv is defined %}
- linux.network.resolv
-{%- endif %}
{%- if network.dpdk is defined %}
- linux.network.dpdk
{%- endif %}
diff --git a/linux/network/interface.sls b/linux/network/interface.sls
index db6cd9f..4794a51 100644
--- a/linux/network/interface.sls
+++ b/linux/network/interface.sls
@@ -326,12 +326,11 @@
network.system:
- enabled: {{ interface.enabled }}
- hostname: {{ network.fqdn }}
- {%- if interface.gateway is defined %}
- gateway: {{ interface.gateway }}
- gatewaydev: {{ interface_name }}
- {%- endif %}
- nozeroconf: True
- nisdomain: {{ system.domain }}
+ - search: {{ system.domain }}
- require_reboot: True
{%- endif %}
diff --git a/linux/network/resolv.sls b/linux/network/resolv.sls
index caecee3..965ed2f 100644
--- a/linux/network/resolv.sls
+++ b/linux/network/resolv.sls
@@ -1,18 +1,28 @@
{%- from "linux/map.jinja" import network with context %}
-{%- if network.enabled %}
-/etc/resolv.conf:
- file.managed:
- - source: salt://linux/files/resolv.conf
- - mode: 644
- - template: jinja
- - follow_symlinks: false
- - require:
- - service: resolvconf_service
+{%- if network.enabled and grains.get('virtual_subtype', None) not in ['Docker', 'LXC'] %}
+resolvconf:
+ pkg.installed
resolvconf_service:
- service.dead:
- - name: resolvconf
- - enable: false
+ service.running:
+ - name: resolvconf
+ - enable: true
+ - require:
+ - pkg: resolvconf
+ {%- if network.resolv is defined %}
+/etc/resolvconf/resolv.conf.d/base:
+ file.managed:
+ - source: salt://linux/files/resolvconf_base
+ - mode: 644
+ - template: jinja
+
+run_update_scripts:
+ cmd.run:
+ - name: /sbin/resolvconf -u
+ - onchanges:
+ - file: /etc/resolvconf/resolv.conf.d/base
+
+ {%- endif %}
{%- endif %}