Switch network management to systemd-networkd and iwd
This commit is contained in:
26
ansible/roles/common/files/20-ethernet.network
Normal file
26
ansible/roles/common/files/20-ethernet.network
Normal file
@@ -0,0 +1,26 @@
|
||||
[Match]
|
||||
# Matching with "Type=ether" causes issues with containers because it also matches virtual Ethernet interfaces (veth*).
|
||||
# See https://bugs.archlinux.org/task/70892
|
||||
# Instead match by globbing the network interface name.
|
||||
Name=en*
|
||||
Name=eth*
|
||||
|
||||
[Link]
|
||||
RequiredForOnline=routable
|
||||
|
||||
[Network]
|
||||
DHCP=yes
|
||||
MulticastDNS=yes
|
||||
|
||||
# systemd-networkd does not set per-interface-type default route metrics
|
||||
# https://github.com/systemd/systemd/issues/17698
|
||||
# Explicitly set route metric, so that Ethernet is preferred over Wi-Fi and Wi-Fi is preferred over mobile broadband.
|
||||
# Use values from NetworkManager. From nm_device_get_route_metric_default in
|
||||
# https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/blob/main/src/core/devices/nm-device.c
|
||||
[DHCPv4]
|
||||
UseDNS=no
|
||||
RouteMetric=100
|
||||
|
||||
[IPv6AcceptRA]
|
||||
UseDNS=no
|
||||
RouteMetric=100
|
||||
@@ -1,6 +1,11 @@
|
||||
---
|
||||
# Handlers for the 'common' role
|
||||
|
||||
- name: Restart systemd-networkd
|
||||
ansible.builtin.service:
|
||||
name: systemd-networkd
|
||||
state: restarted
|
||||
|
||||
- name: Restart sshd
|
||||
ansible.builtin.service:
|
||||
name: sshd
|
||||
|
||||
@@ -6,27 +6,34 @@
|
||||
name: "{{ common_hostname }}"
|
||||
tags: [ 'common', 'hostname' ]
|
||||
|
||||
- name: Configure WiFi connection '{{ common_wifi_connection_name }}'
|
||||
become: true
|
||||
ansible.builtin.command:
|
||||
cmd: >
|
||||
nmcli dev wifi connect "{{ common_wifi_ssid }}"
|
||||
password "{{ common_wifi_password }}"
|
||||
name "{{ common_wifi_connection_name }}"
|
||||
args:
|
||||
creates: "/etc/NetworkManager/system-connections/{{ common_wifi_connection_name }}.nmconnection"
|
||||
ignore_errors: true
|
||||
- name: Ensure systemd-networkd is enabled and running
|
||||
ansible.builtin.service:
|
||||
name: systemd-networkd
|
||||
enabled: yes
|
||||
state: started
|
||||
tags: [ 'common', 'network' ]
|
||||
|
||||
- name: Ensure iwd is enabled and running
|
||||
ansible.builtin.service:
|
||||
name: iwd
|
||||
enabled: yes
|
||||
state: started
|
||||
tags: [ 'common', 'network', 'wifi' ]
|
||||
|
||||
- name: Configure ethernet connection '{{ common_ethernet_con_name }}' with static IP, gateway, and DNS
|
||||
become: true
|
||||
ansible.builtin.command:
|
||||
cmd: >
|
||||
nmcli con add type ethernet ifname {{ common_ethernet_ifname }} con-name "{{ common_ethernet_con_name }}" ipv4.method manual ipv4.addresses {{ common_ethernet_ipv4_address }} ipv4.gateway {{ common_ethernet_ipv4_gateway }} ipv4.dns "{{ common_ethernet_ipv4_dns }}"
|
||||
args:
|
||||
creates: "/etc/NetworkManager/system-connections/{{ common_ethernet_con_name }}.nmconnection"
|
||||
ignore_errors: true
|
||||
- name: Deploy ethernet network configuration
|
||||
ansible.builtin.copy:
|
||||
src: files/20-ethernet.network
|
||||
dest: /etc/systemd/network/20-ethernet.network
|
||||
owner: root
|
||||
group: root
|
||||
mode: '0644'
|
||||
notify: Restart systemd-networkd
|
||||
tags: [ 'common', 'network', 'ethernet' ]
|
||||
|
||||
- name: Configure WiFi (requires manual interaction or pre-seeded iwd config)
|
||||
debug:
|
||||
msg: "WiFi configuration via Ansible for iwd is complex. Ensure /var/lib/iwd/ contains correct .psk files."
|
||||
tags: [ 'common', 'network', 'wifi' ]
|
||||
- name: Ensure user '{{ common_user_name }}' exists with specified password
|
||||
ansible.builtin.user:
|
||||
name: "{{ common_user_name }}"
|
||||
|
||||
Reference in New Issue
Block a user