feat: Separate network/wifi/dhcp into separate yaml; disable dhcp

- "disable dhcp" -- erasing /etc/config/dhcp will / should also
prevent odhcpcd from starting.

For: issue #6
This commit is contained in:
2026-04-26 18:02:47 -04:00
parent 728a897fec
commit 26ef6cdc33
4 changed files with 103 additions and 86 deletions

View File

@@ -1,88 +1,8 @@
- name: Setup network devices
uci:
command: section
config: network
type: device
find_by:
name: "{{ item.name }}"
value:
type: "{{ item.type }}"
ports: "{{ item.ports }}"
stp: "{{ item.stp | default() }}"
loop: "{{ network['device'] }}"
- name: Setup dhcp
ansible.builtin.import_tasks: setup_dhcp.yml
- name: Setup network interfaces
uci:
command: section
config: network
type: interface
name: "{{ item.key }}"
value:
device: "{{ item.device }}"
proto: "{{ item.proto }}"
ifname: "{{ item.ifname | default() }}"
loop: "{{ network['interface'] }}"
- name: Setup network
ansible.builtin.import_tasks: setup_network.yml
- name: commit changes
uci:
command: commit
key: network
notify: restart network
- name: Tear down the default wifi-iface(s)
uci:
config: wireless
command: absent
section: "{{ item }}"
loop:
- default_radio0
- default_radio1
- name: Setup wireless devices (radios)
uci:
command: section
config: wireless
type: wifi-device
find_by:
path: "{{ item.path }}"
name: "{{ item.name }}"
value:
type: "mac80211" # they'd BETTER be.
band: "{{ item.band | default(wifi_device[item.template].band) | default() }}"
channel: "{{ item.channel | default(wifi_device[item.template].channel) }}"
country: "{{ item.country | default(wifi_device[item.template].country) }}"
disabled: "{{ item.disabled | default(wifi_device[item.template].disabled) }}"
hwmode: "{{ item.hwmode | default(wifi_device[item.template].hwmode) | default() }}"
htmode: "{{ item.htmode | default(wifi_device[item.template].htmode) }}"
log_level: "{{ item.log_level | default(wifi_device[item.template].log_level) | default() }}"
loop: "{{ wireless['wifi_device'] }}"
- name: Setup wireless ifaces (VIFs)
uci:
command: section
config: wireless
type: wifi-iface
name: "{{ item.ifname | default(wifi_iface[item.template].ifname) | default('') }}"
value:
ifname: "{{ item.ifname | default(wifi_iface[item.template].ifname) | default('') if not item.force_ifnameless | default(false) }}"
mode: "{{ item.mode | default(wifi_iface[item.template].mode) }}"
device: "{{ item.device | default(wifi_iface[item.template].device) }}"
network: "{{ item.network | default(wifi_iface[item.template].network) }}"
ssid: "{{ item.ssid | default(wifi_iface[item.template].ssid) | default() }}"
bss_transition: "{{ item.bss_transition | default(wifi_iface[item.template].bss_transition) | default() }}"
ieee80211k: "{{ item.ieee80211k | default(wifi_iface[item.template].ieee80211k) | default() }}"
ieee80211r: "{{ item.ieee80211r | default(wifi_iface[item.template].ieee80211r) | default() }}"
ieee80211v: "{{ item.ieee80211v | default(wifi_iface[item.template].ieee80211v) | default() }}"
mesh_id: "{{ item.mesh_id | default(wifi_iface[item.template].mesh_id) | default() }}"
encryption: "{{ item.encryption | default(wifi_iface[item.template].encryption) }}"
key: "{{ item.key | default(wifi_iface[item.template].key) }}"
disabled: "{{ item.disabled | default(wifi_iface[item.template].disabled) | default(0) }}"
skip_inactivity_poll: "{{ item.skip_inactivity_poll | default(wifi_iface[item.template].skip_inactivity_poll) | default() }}"
disassoc_low_ack: "{{ item.disassoc_low_ack | default(wifi_iface[item.template].disassoc_low_ack) | default() }}"
loop: "{{ wireless['wifi_iface'] }}"
- name: commit changes
uci:
command: commit
key: wireless
notify: reload wifi
- name: Setup wireless
ansible.builtin.import_tasks: setup_wireless.yml

View File

@@ -0,0 +1,8 @@
---
- name: Totally eliminate DHCP configuration
copy:
content: ''
dest: "/etc/config/dhcp"
notify: # https://selivan.github.io/2017/01/15/ansible-multiple-handlers-subtlety.html
- reload odhcpd
- reload dnsmasq

View File

@@ -0,0 +1,31 @@
---
- name: Setup network devices
uci:
command: section
config: network
type: device
find_by:
name: "{{ item.name }}"
value:
type: "{{ item.type }}"
ports: "{{ item.ports }}"
stp: "{{ item.stp | default() }}"
loop: "{{ network['device'] }}"
- name: Setup network interfaces
uci:
command: section
config: network
type: interface
name: "{{ item.key }}"
value:
device: "{{ item.device }}"
proto: "{{ item.proto }}"
ifname: "{{ item.ifname | default() }}"
loop: "{{ network['interface'] }}"
- name: commit changes
uci:
command: commit
key: network
notify: restart network

View File

@@ -0,0 +1,58 @@
---
- name: Tear down the default wifi-iface(s)
uci:
config: wireless
command: absent
section: "{{ item }}"
loop:
- default_radio0
- default_radio1
- name: Setup wireless devices (radios)
uci:
command: section
config: wireless
type: wifi-device
find_by:
path: "{{ item.path }}"
name: "{{ item.name }}"
value:
type: "mac80211" # they'd BETTER be.
band: "{{ item.band | default(wifi_device[item.template].band) | default() }}"
channel: "{{ item.channel | default(wifi_device[item.template].channel) }}"
country: "{{ item.country | default(wifi_device[item.template].country) }}"
disabled: "{{ item.disabled | default(wifi_device[item.template].disabled) }}"
hwmode: "{{ item.hwmode | default(wifi_device[item.template].hwmode) | default() }}"
htmode: "{{ item.htmode | default(wifi_device[item.template].htmode) }}"
log_level: "{{ item.log_level | default(wifi_device[item.template].log_level) | default() }}"
loop: "{{ wireless['wifi_device'] }}"
- name: Setup wireless ifaces (VIFs)
uci:
command: section
config: wireless
type: wifi-iface
name: "{{ item.ifname | default(wifi_iface[item.template].ifname) | default('') }}"
value:
ifname: "{{ item.ifname | default(wifi_iface[item.template].ifname) | default('') if not item.force_ifnameless | default(false) }}"
mode: "{{ item.mode | default(wifi_iface[item.template].mode) }}"
device: "{{ item.device | default(wifi_iface[item.template].device) }}"
network: "{{ item.network | default(wifi_iface[item.template].network) }}"
ssid: "{{ item.ssid | default(wifi_iface[item.template].ssid) | default() }}"
bss_transition: "{{ item.bss_transition | default(wifi_iface[item.template].bss_transition) | default() }}"
ieee80211k: "{{ item.ieee80211k | default(wifi_iface[item.template].ieee80211k) | default() }}"
ieee80211r: "{{ item.ieee80211r | default(wifi_iface[item.template].ieee80211r) | default() }}"
ieee80211v: "{{ item.ieee80211v | default(wifi_iface[item.template].ieee80211v) | default() }}"
mesh_id: "{{ item.mesh_id | default(wifi_iface[item.template].mesh_id) | default() }}"
encryption: "{{ item.encryption | default(wifi_iface[item.template].encryption) }}"
key: "{{ item.key | default(wifi_iface[item.template].key) }}"
disabled: "{{ item.disabled | default(wifi_iface[item.template].disabled) | default(0) }}"
skip_inactivity_poll: "{{ item.skip_inactivity_poll | default(wifi_iface[item.template].skip_inactivity_poll) | default() }}"
disassoc_low_ack: "{{ item.disassoc_low_ack | default(wifi_iface[item.template].disassoc_low_ack) | default() }}"
loop: "{{ wireless['wifi_iface'] }}"
- name: commit changes
uci:
command: commit
key: wireless
notify: reload wifi