cleanup: separate network config into a role

Note that this also drops the package setup at the beginning of the
original wireless-setup.yml.

We no longer need to specify -e @default_vars.yml since it is included
in the role.
This commit is contained in:
Martin Kennedy 2022-08-06 21:42:30 -04:00
parent d139c423cb
commit ad80c3d464
4 changed files with 76 additions and 82 deletions

View File

@ -0,0 +1,2 @@
dependencies:
- role: gekmihesg.openwrt

View File

@ -0,0 +1,73 @@
- 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
- name: Setup wireless devices (radios)
uci:
command: section
config: wireless
type: wifi-device
find_by:
path: "{{ item.path }}"
value:
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) }}"
loop: "{{ wireless['wifi_device'] }}"
- name: Setup wireless ifaces (VIFs)
uci:
command: section
config: wireless
type: wifi-iface
find:
ifname: "{{ item.ifname | default(wifi_iface[item.template].ifname) | default('') }}"
value:
ifname: "{{ item.ifname | default(wifi_iface[item.template].ifname) | default('') }}"
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() }}"
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

View File

@ -1,84 +1,3 @@
- hosts: openwrt
roles:
- gekmihesg.openwrt
tasks:
- name: Install the right packages
opkg:
name: "{{ item.name }}"
state: "{{ item.state }}"
loop: "{{ packages | default([]) }}"
- 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
- name: Setup wireless devices (radios)
uci:
command: section
config: wireless
type: wifi-device
find_by:
path: "{{ item.path }}"
value:
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) }}"
loop: "{{ wireless['wifi_device'] }}"
- name: Setup wireless ifaces (VIFs)
uci:
command: section
config: wireless
type: wifi-iface
find:
ifname: "{{ item.ifname | default(wifi_iface[item.template].ifname) | default('') }}"
value:
ifname: "{{ item.ifname | default(wifi_iface[item.template].ifname) | default('') }}"
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() }}"
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
- netconfig