Преглед изворни кода

Make possible to install a local DNS cache and configure nameservers in resolv.conf

Emmanuel Bouthenot пре 10 година
родитељ
комит
79c68010f7

+ 2 - 0
roles/common/defaults/main.yml

@@ -37,6 +37,8 @@ ssh_port: 22
 ssh_ecdsa_key: True
 ssh_usedns: True
 
+with_dnscache: False
+
 with_ovh: False
 
 sysfs_disk_settings: False

+ 15 - 0
roles/common/tasks/dns.yml

@@ -0,0 +1,15 @@
+- name: Remove bind9 (not a suitable dnscache) packages
+  apt: pkg={{ item }} state=absent purge=yes
+  with_items:
+    - bind9
+  when: with_dnscache
+
+- name: Install unbound (dnscache) packages
+  apt: pkg={{ item }} state=installed update_cache=yes
+  with_items:
+    - unbound
+  when: with_dnscache
+
+- name: Install resolv.conf
+  template: src=dns/resolv.conf.j2 dest=/etc/resolv.conf owner=root group=root mode=0644
+  when: with_dnscache or nameservers is defined

+ 1 - 0
roles/common/tasks/main.yml

@@ -1,4 +1,5 @@
 - include: base.yml
+- include: dns.yml
 - include: firewall.yml
 - include: ovh.yml
 - include: security.yml

+ 12 - 0
roles/common/templates/dns/resolv.conf.j2

@@ -0,0 +1,12 @@
+{% if ansible_prolog -%}
+{% from 'templates/ansible/prolog.j2' import prolog with context %}
+{{ prolog() }}
+{% endif -%}
+{% if with_dnscache %}
+nameserver 127.0.0.1
+{% endif %}
+{% if nameservers is defined %}
+{% for nameserver in nameservers %}
+nameserver {{ nameserver }}
+{% endfor %}
+{% endif %}