From 12ae3acd6e38ff8d64ec5bd8815573855f0e90da Mon Sep 17 00:00:00 2001 From: Kevin Carter Date: Thu, 10 May 2018 13:39:24 -0500 Subject: [PATCH] Add resolved to the networkd setup If the new variable systemd_resolved is defined, resolved will be setup within the environment. This will configure the global configuration file and restart the service. A test has been added to ensure this code path is exercised on every commit. It should be noted that suse does not have a resolved package so this functionality is disabled when a suse system is encountered. This should be revised as soon as suse has resolved available. Change-Id: I85278719bc5b7158244fd44c65d4366935555780 Signed-off-by: Kevin Carter --- defaults/main.yml | 12 ++++++++++++ handlers/main.yml | 11 +++++++++++ tasks/main.yml | 14 ++++++++++++++ templates/systemd-resolved.conf.j2 | 4 ++++ tests/test.yml | 7 ++++--- vars/redhat-7.yml | 3 +++ vars/suse-42.yml | 2 ++ vars/ubuntu-16.04.yml | 2 ++ 8 files changed, 52 insertions(+), 3 deletions(-) create mode 100644 templates/systemd-resolved.conf.j2 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"