diff --git a/defaults/main.yml b/defaults/main.yml index 2ba12d5..1f74fb4 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -16,6 +16,7 @@ common_locales_default: common_ntp: True common_resolvconf: True +common_resolvconf_remove_resolvconf: True common_resolvconf_hnfqdn: true common_resolvconf_nameservers: [] common_resolvconf_domain: "" diff --git a/tasks/resolvconf.yml b/tasks/resolvconf.yml index 4802515..4d50d1e 100644 --- a/tasks/resolvconf.yml +++ b/tasks/resolvconf.yml @@ -1,12 +1,13 @@ --- +- name: resolvconf - remove + apt: name=resolvconf state=absent + when: common_resolvconf_remove_resolvconf -- name: resolvconf - install - apt: name=resolvconf state=present - -- name: resolvconf - tail file - template: dest=/etc/resolvconf/resolv.conf.d/tail src=resolvconf_tail.j2 owner=root group=root mode=0644 - when: common_resolvconf_nameservers - notify: restart resolvconf - -- name: resolvconf - start and enable - service: name=resolvconf state=started enabled=yes +- name: /etc/resolv.conf + template: + dest: /etc/resolv.conf + src: resolv.conf.j2 + owner: root + group: root + mode: 0644 + when: common_resolvconf_remove_resolvconf diff --git a/templates/resolv.conf.j2 b/templates/resolv.conf.j2 new file mode 100644 index 0000000..86eebe9 --- /dev/null +++ b/templates/resolv.conf.j2 @@ -0,0 +1,14 @@ +# {{ ansible_managed }} + +{% if common_resolvconf_domain -%} +domain {{ common_resolvconf_domain }} +{% endif %} +{% if ansible_local is defined and ansible_local.hardwarenode.hnfqdn and common_resolvconf_hnfqdn -%} +nameserver {{ lookup('dig', ansible_local.hardwarenode.hnfqdn ) }} +{% endif %} +{% for nameserver in common_resolvconf_nameservers -%} +nameserver {{ nameserver }} +{% endfor %} +{% if common_resolvconf_search -%} +search {% for name in common_resolvconf_search %}{{ name }} {% endfor %} +{% endif %} diff --git a/templates/resolvconf_tail.j2 b/templates/resolvconf_tail.j2 deleted file mode 100644 index e2ec761..0000000 --- a/templates/resolvconf_tail.j2 +++ /dev/null @@ -1,17 +0,0 @@ -# {{ ansible_managed }} - -{% if common_resolvconf_domain %} -domain {{ common_resolvconf_domain }} -{% endif %} - -{% if ansible_local is defined and ansible_local.hardwarenode.hnfqdn and common_resolvconf_hnfqdn %} -nameserver {{ lookup('dig', ansible_local.hardwarenode.hnfqdn ) }} -{% else %} -{% for n in common_resolvconf_nameservers %} -nameserver {{ n }} -{% endfor %} -{% endif %} - -{% if common_resolvconf_search %} -search {% for s in common_resolvconf_search %}{{ s }} {% endfor %} -{% endif %}