diff --git a/defaults/main.yml b/defaults/main.yml index 56a23c0..f433645 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -107,3 +107,15 @@ systemd_netdevs: [] # ConfigureWithoutCarrier: true systemd_networks: [] + +# The systemd resolved service can be setup using th following configuration. +# The generator is a Key=Value pair hash and will set whatever directives it's +# instructed to. For more information on all of the possible configuration see +# https://www.freedesktop.org/software/systemd/man/resolved.conf.html + +# systemd_resolved: +# DNS: "10.127.83.1" +# FallbackDNS: "208.67.222.222 8.8.8.8" +# Cache: yes + +systemd_resolved: {} diff --git a/handlers/main.yml b/handlers/main.yml index b335cfa..a1efaec 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -23,5 +23,16 @@ tags: - systemd-networkd +- name: Restart systemd-resolved + systemd: + name: "systemd-resolved" + daemon_reload: yes + state: restarted + when: + - systemd_resolved_available | bool + tags: + - systemd-networkd + - systemd-resolved + - name: Update initramfs command: "{{ systemd_networkd_update_initramfs }}" diff --git a/tasks/main.yml b/tasks/main.yml index 32fd86b..0e62387 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -73,6 +73,20 @@ tags: - systemd-networkd +- name: Create systemd-resolved config + template: + src: "systemd-resolved.conf.j2" + dest: "/etc/systemd/resolved.conf" + owner: "root" + group: "root" + mode: "0644" + when: + - systemd_resolved + notify: + - Restart systemd-resolved + tags: + - systemd-resolved + - name: Run interface cleanup script command: "/usr/local/bin/interface-cleanup" failed_when: false diff --git a/templates/systemd-resolved.conf.j2 b/templates/systemd-resolved.conf.j2 new file mode 100644 index 0000000..db61c02 --- /dev/null +++ b/templates/systemd-resolved.conf.j2 @@ -0,0 +1,4 @@ +[Resolve] +{% for key, value in systemd_resolved.items() %} +{{ key }}={{ value }} +{% endfor %} diff --git a/tests/test.yml b/tests/test.yml index 544b2e2..11dd47a 100644 --- a/tests/test.yml +++ b/tests/test.yml @@ -27,10 +27,11 @@ pause: seconds: 15 vars: - systemd_networkd_distro_packages: - yum: - - systemd-networkd systemd_run_networkd: yes + systemd_resolved: + DNS: "208.67.222.222" + FallbackDNS: "8.8.8.8" + Cache: yes systemd_netdevs: - NetDev: Name: dummy0 diff --git a/vars/redhat-7.yml b/vars/redhat-7.yml index 637de9d..8aa24c6 100644 --- a/vars/redhat-7.yml +++ b/vars/redhat-7.yml @@ -15,5 +15,8 @@ systemd_networkd_distro_packages: - systemd-networkd + - systemd-resolved + +systemd_resolved_available: true systemd_networkd_update_initramfs: "dracut -f" diff --git a/vars/suse-42.yml b/vars/suse-42.yml index 474d5ca..c449654 100644 --- a/vars/suse-42.yml +++ b/vars/suse-42.yml @@ -13,4 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. +systemd_resolved_available: false + systemd_networkd_update_initramfs: "dracut -f" diff --git a/vars/ubuntu-16.04.yml b/vars/ubuntu-16.04.yml index 1648a41..653cb4e 100644 --- a/vars/ubuntu-16.04.yml +++ b/vars/ubuntu-16.04.yml @@ -13,4 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. +systemd_resolved_available: true + systemd_networkd_update_initramfs: "/usr/sbin/update-initramfs -u"