From d6a1876fe80e33fd99469c31e28173973a485af6 Mon Sep 17 00:00:00 2001 From: dogeystamp Date: Sun, 27 Aug 2023 14:50:34 -0400 Subject: [PATCH] roles/networking: fix dns issues --- roles/networking/connection/defaults/main.yml | 3 +++ roles/networking/connection/tasks/main.yml | 19 +++++++++++++++++-- .../connection/templates/dns_servers.conf.j2 | 2 ++ .../connection/templates/nodns.network.j2 | 5 +++++ 4 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 roles/networking/connection/templates/dns_servers.conf.j2 create mode 100644 roles/networking/connection/templates/nodns.network.j2 diff --git a/roles/networking/connection/defaults/main.yml b/roles/networking/connection/defaults/main.yml index a60d6ac..4400efc 100644 --- a/roles/networking/connection/defaults/main.yml +++ b/roles/networking/connection/defaults/main.yml @@ -9,3 +9,6 @@ subnet_prefix: /24 local_subnet: 192.168.0.0/24 # router IP address gateway: 192.168.0.1 + +# Can be the server itself if it has a nameserver +nameserver: "{{ hostvars[groups['nameserver'][0]]['local_ip'] }}" diff --git a/roles/networking/connection/tasks/main.yml b/roles/networking/connection/tasks/main.yml index 5e05c4c..6be14cd 100644 --- a/roles/networking/connection/tasks/main.yml +++ b/roles/networking/connection/tasks/main.yml @@ -38,9 +38,24 @@ job: "/root/rmconn.sh" state: present +- name: Disable DHCP DNS + template: + src: nodns.network.j2 + dest: /etc/systemd/network/50-nodns.network + +- name: Create resolved configuration directory + file: + path: /etc/systemd/resolved.conf.d + state: directory + +- name: Set DNS + template: + src: dns_servers.conf.j2 + dest: /etc/systemd/resolved.conf.d/50-dns_servers.conf + - name: Create NetworkManager connection community.general.nmcli: - dns4: "{{ local_ip }}" + dns4: "{{ nameserver }}" dns4_ignore_auto: yes ip4: "{{ local_ip }}{{ subnet_prefix }}" gw4: "{{ gateway }}" @@ -57,7 +72,7 @@ - name: Attempt to reconnect wait_for_connection: timeout: 240 - when: nmcli_conf.changed + when: nmcli_conf.changed or rmconn.changed - name: Remove rmconn task at every minute cron: diff --git a/roles/networking/connection/templates/dns_servers.conf.j2 b/roles/networking/connection/templates/dns_servers.conf.j2 new file mode 100644 index 0000000..e38060b --- /dev/null +++ b/roles/networking/connection/templates/dns_servers.conf.j2 @@ -0,0 +1,2 @@ +[Resolve] +DNS={{ nameserver }} diff --git a/roles/networking/connection/templates/nodns.network.j2 b/roles/networking/connection/templates/nodns.network.j2 new file mode 100644 index 0000000..45ff8a3 --- /dev/null +++ b/roles/networking/connection/templates/nodns.network.j2 @@ -0,0 +1,5 @@ +[Match] +Name=* + +[DHCP] +UseDNS=false