Add posibility to edit head of resolv.conf
Queries take long time as the dns entry that resolve the query is
added at the end of the resolv.conf. This fix helps to add dns entry
to head of the file rather than the base.
Related-PROD: PROD-36892
Change-Id: I506e6d3b27c14d810d37a7ec13f98f143ef7694e
diff --git a/README.rst b/README.rst
index 1d9cb23..8bacc8e 100644
--- a/README.rst
+++ b/README.rst
@@ -2237,7 +2237,8 @@
- node2.domain.com
- service2.domain.com
-Set up ``resolvconf's basic resolver info``, e.g. nameservers, search/domain and options:
+Set up ``resolvconf's basic resolver info``, e.g. nameservers, search/domain and options.
+Parameter ``update_head`` will move changes to the top of resolv.conf if set to ``True``:
.. code-block:: yaml
@@ -2248,6 +2249,7 @@
- 8.8.4.4
- 8.8.8.8
domain: my.example.com
+ update_head: False
search:
- my.example.com
- example.com
diff --git a/linux/files/resolvconf_head b/linux/files/resolvconf_head
new file mode 100644
index 0000000..6ea9fba
--- /dev/null
+++ b/linux/files/resolvconf_head
@@ -0,0 +1,14 @@
+{%- from "linux/map.jinja" import network with context -%}
+# Managed by Salt
+{%- 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/resolv.sls b/linux/network/resolv.sls
index bac6ebf..056fe9e 100644
--- a/linux/network/resolv.sls
+++ b/linux/network/resolv.sls
@@ -17,17 +17,24 @@
- unless: test -L /etc/resolv.conf
{%- if network.resolv is defined %}
+ {%- if network.resolv.update_head is defined and network.resolv.update_head == True %}
+/etc/resolvconf/resolv.conf.d/head:
+ file.managed:
+ - source: salt://linux/files/resolvconf_head
+ - mode: 644
+ - template: jinja
+ {%- else %}
+
/etc/resolvconf/resolv.conf.d/base:
file.managed:
- source: salt://linux/files/resolvconf_base
- mode: 644
- template: jinja
+ {%- endif %}
run_update_scripts:
cmd.run:
- name: /sbin/resolvconf -u
- - onchanges:
- - file: /etc/resolvconf/resolv.conf.d/base
{%- endif %}
{%- endif %}