From f9d173e6ec78c6f0cf0e83811953233c024c96e5 Mon Sep 17 00:00:00 2001 From: Michael Schmitz Date: Sat, 12 Oct 2024 17:45:50 +0200 Subject: [PATCH] [#188257134] Add additional logic for resolved with backwards compability --- defaults/main.yml | 4 ++-- tasks/main.yml | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/defaults/main.yml b/defaults/main.yml index e9ff6c7..0022f2f 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -16,8 +16,8 @@ _consul: metadata: key1: "value" key2: "value" - use_dnsmasq_forwarding: true - allow_dnsmasq_restart: true + use_resolved_forwarding: true + allow_resolved_restart: true cluster: provider: "aws" tag_key: "consul" diff --git a/tasks/main.yml b/tasks/main.yml index 5cdad49..f9b9af9 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -124,6 +124,28 @@ state: restarted when: dnsmasq_consul is changed and _consul.allow_dnsmasq_restart | default(true) +- name: Systemd-resolved forwarding + when: _consul.use_resolved_forwarding | default(false) + block: + - name: Configure systemd-resolved + community.general.ini_file: + path: /etc/systemd/resolved.conf.d/consul.conf + section: "Resolve" + option: "{{ item.key }}" + value: "{{ item.value }}" + state: present + mode: '0644' + loop: + - { key: DNS, value: "127.0.0.1:{{ _consul.dns_port | default(8600) }}" } + - { key: Domains, value: "~{{ _consul.domain }}" } + register: systemd_resolved_consul + + - name: Restart systemd-resolved if config changed to enable consul queries + ansible.builtin.systemd: + name: systemd-resolved + state: restarted + when: systemd_resolved_consul is changed and _consul.allow_resolved_restart | default(true) + - name: Set oom score for consul client in systemd ansible.builtin.lineinfile: dest: "/etc/systemd/system/{{ _consul.service_name }}.service"