From 30f2fb0635918b866d34dd912340c4961e2a60e6 Mon Sep 17 00:00:00 2001 From: "noussair.hamrit" Date: Thu, 29 Oct 2026 11:48:46 +0100 Subject: [PATCH] fix(private_routing): add DNS nameservers to Netplan/networkd route config --- roles/private_routing/defaults/main.yml | 3 +++ roles/private_routing/tasks/main.yml | 20 +++++++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/roles/private_routing/defaults/main.yml b/roles/private_routing/defaults/main.yml index 6584722..b87816e 100644 --- a/roles/private_routing/defaults/main.yml +++ b/roles/private_routing/defaults/main.yml @@ -2,3 +2,6 @@ private_routing_interface: enp7s0 private_routing_gateway: 10.0.0.1 private_routing_metric: 100 +private_routing_nameservers: + - 1.1.1.1 + - 9.9.9.9 \ No newline at end of file diff --git a/roles/private_routing/tasks/main.yml b/roles/private_routing/tasks/main.yml index fde1b38..2e67b05 100644 --- a/roles/private_routing/tasks/main.yml +++ b/roles/private_routing/tasks/main.yml @@ -23,6 +23,7 @@ No Netplan configuration or active systemd-networkd interface found for {{ private_routing_interface }}; refusing to change network configuration. +# ---- Netplan path ---- - name: Install Netplan route drop-in ansible.builtin.copy: dest: /etc/netplan/99-private-vpn-default-route.yaml @@ -32,9 +33,11 @@ ethernets: {{ private_routing_interface }}: routes: - - to: 0.0.0.0/0 + - to: default via: {{ private_routing_gateway }} metric: {{ private_routing_metric }} + nameservers: + addresses: {{ private_routing_nameservers | to_json }} owner: root group: root mode: "0600" @@ -46,6 +49,7 @@ changed_when: false when: private_routing_netplan_files.matched | default(0) > 0 +# ---- systemd-networkd path ---- - name: Install systemd-networkd route drop-in ansible.builtin.copy: dest: "/etc/systemd/network/90-{{ private_routing_interface }}-private-vpn-route.network" @@ -53,6 +57,11 @@ [Match] Name={{ private_routing_interface }} + [Network] + {% for ns in private_routing_nameservers %} + DNS={{ ns }} + {% endfor %} + [Route] Destination=0.0.0.0/0 Gateway={{ private_routing_gateway }} @@ -68,8 +77,17 @@ state: restarted when: private_routing_netplan_files.matched | default(0) == 0 +# ---- Verification (both paths) ---- - name: Verify selected route to internet ansible.builtin.command: ip -4 route get 8.8.8.8 register: private_route_get changed_when: false failed_when: private_routing_gateway not in private_route_get.stdout or private_routing_interface not in private_route_get.stdout + +- name: Verify DNS resolution through the gateway + ansible.builtin.command: getent hosts archive.ubuntu.com + register: private_dns_check + changed_when: false + retries: 5 + delay: 3 + until: private_dns_check.rc == 0 \ No newline at end of file