Rozdělení do skupin DSA a swconfig, úprava role network

This commit is contained in:
2024-11-01 03:32:26 +01:00
parent 587ca23374
commit cde297bd2e
18 changed files with 201 additions and 268 deletions

View File

@@ -1,36 +1,35 @@
device_bridge_port: "{{ ansible_facts.openwrt_interfaces.mgmnt.device | regex_search('eth[0-9]+|wan') }}"
device_2g_radio: "{{ (ansible_facts.openwrt_wireless | dict2items | selectattr('value.config.band', 'equalto', '2g') | map(attribute='key') | first) | default('none') }}"
device_5g_radio: "{{ (ansible_facts.openwrt_wireless | dict2items | selectattr('value.config.band', 'equalto', '5g') | map(attribute='key') | first) | default('none') }}"
network_devices:
- id: "@device[1]"
name: "br-vlan129"
- name: "br-vlan129"
state: "present"
type: "bridge"
ports: ["{{ device_bridge_port }}.129"]
- id: "@device[2]"
name: "br-vlan137"
- name: "br-vlan137"
state: "present"
type: "bridge"
ports: ["{{ device_bridge_port }}.137"]
- id: "@device[3]"
name: "br-vlan145"
- name: "br-vlan145"
state: "present"
type: "bridge"
ports: ["{{ device_bridge_port }}.145"]
- id: "@device[4]"
name: "br-free"
- name: "br-free"
state: "present"
type: "bridge"
ports: ["{{ device_bridge_port }}.152"]
- id: "@device[5]"
name: "br-oldaurora"
- name: "br-oldaurora"
state: "present"
type: "bridge"
ports: ["{{ device_bridge_port }}.128"]
network_interfaces:
- id: "mgmnt"
proto: "static"
device: "{{ device_bridge_port }}.99"
ipaddr: "{{ device_ip_address }}/24"
gateway: "{{ device_ip_address | regex_replace('\\.[0-9]+$', '.1') }}"
dns: ["{{ device_ip_address | regex_replace('\\.[0-9]+$', '.1') }}"]
- id: "hoste_wifi"
proto: "none"
device: "br-vlan129"

1
group_vars/dsa.yml Normal file
View File

@@ -0,0 +1 @@
device_bridge_port: "{{ network_devices_append[0].name }}"

1
group_vars/swconfig.yml Normal file
View File

@@ -0,0 +1 @@
device_bridge_port: "{{ ansible_facts.openwrt_interfaces.mgmnt.device | regex_search('eth[0-9]+') }}"

View File

@@ -1,24 +1,6 @@
device_ip_address: "10.11.99.4"
device_hostname: "ap-outdoor"
# network_switch_vlans:
# - id: "@switch_vlan[1]"
# vlan: "128"
# ports: "0t 1t 2 3t 4 5"
# description: "hoste"
# - id: "@switch_vlan[2]"
# vlan: "136"
# ports: "0t 1t"
# description: "studenti"
# - id: "@switch_vlan[3]"
# vlan: "144"
# ports: "0t 1t 3t"
# description: "ucitele"
# - id: "@switch_vlan[4]"
# vlan: "152"
# ports: "0t 1t"
# description: "free"
# wireless_devices:
# - id: ""
# channel: "6"

View File

@@ -1,52 +1,36 @@
device_ip_address: "10.11.99.2"
device_hostname: ""
device_hostname: "ap-pokoj"
network_dsa_switch_vlans:
- id: "@switch_vlan[1]"
vlan: "128"
ports: "0t 6t 1 2 3 4"
description: "hoste"
- id: "@switch_vlan[2]"
vlan: "129"
ports: "0t 6t"
description: "hoste_wifi"
- id: "@switch_vlan[3]"
vlan: "136"
ports: "0t 6t"
description: "studenti_lan"
- id: "@switch_vlan[4]"
vlan: "137"
ports: "0t 6t"
description: "studenti_wifi"
- id: "@switch_vlan[5]"
vlan: "144"
ports: "0t 6t"
description: "ucitele_lan"
- id: "@switch_vlan[6]"
vlan: "145"
ports: "0t 6t"
description: "ucitele_wifi"
- id: "@switch_vlan[7]"
vlan: "152"
ports: "0t 6t"
description: "free_wifi"
# network_switch_vlans:
# - id: "@switch_vlan[1]"
# vlan: "128"
# ports: "0t 1t 2 3t 4 5"
# description: "hoste"
# - id: "@switch_vlan[2]"
# vlan: "136"
# ports: "0t 1t"
# description: "studenti"
# - id: "@switch_vlan[3]"
# vlan: "144"
# ports: "0t 1t 3t"
# description: "ucitele"
# - id: "@switch_vlan[4]"
# vlan: "152"
# ports: "0t 1t"
# description: "free"
network_devices_append:
- name: "br0"
state: "present"
type: "bridge"
ports: ["wan", "lan1", "lan2", "lan3"]
network_bridge_vlan_filtering:
- vlan: "99"
device: "{{ device_bridge_port }}"
ports: ["wan:t"]
- vlan: "128"
device: "{{ device_bridge_port }}"
ports: ["wan:t", "lan1", "lan2:t"]
- vlan: "129"
device: "{{ device_bridge_port }}"
ports: ["wan:t", "lan2:t"]
- vlan: "136"
device: "{{ device_bridge_port }}"
ports: ["wan:t", "lan2:t"]
- vlan: "137"
device: "{{ device_bridge_port }}"
ports: ["wan:t", "lan2:t"]
- vlan: "144"
device: "{{ device_bridge_port }}"
ports: ["wan:t", "lan2:t"]
- vlan: "145"
device: "{{ device_bridge_port }}"
ports: ["wan:t", "lan2:t"]
- vlan: "152"
device: "{{ device_bridge_port }}"
ports: ["wan:t", "lan2:t"]
# wireless_devices:
# - id: ""

View File

@@ -1,39 +1,28 @@
device_ip_address: "10.11.99.3"
device_hostname: "ap-predsin"
network_swconfig_switch_vlans:
- id: "@switch_vlan[1]"
vlan: "128"
network_swconfig:
- vlan: "128"
ports: "0t 1t 2"
description: "hoste_lan"
- id: "@switch_vlan[2]"
vlan: "129"
- vlan: "129"
ports: "0t 1t"
description: "hoste_wifi"
- id: "@switch_vlan[3]"
vlan: "136"
- vlan: "136"
ports: "0t 1t"
description: "studenti_lan"
- id: "@switch_vlan[4]"
vlan: "137"
- vlan: "137"
ports: "0t 1t"
description: "studenti_wifi"
- id: "@switch_vlan[5]"
vlan: "144"
- vlan: "144"
ports: "0t 1t"
description: "ucitele_lan"
- id: "@switch_vlan[6]"
vlan: "145"
- vlan: "145"
ports: "0t 1t"
description: "ucitele_wifi"
- id: "@switch_vlan[7]"
vlan: "152"
- vlan: "152"
ports: "0t 1t"
description: "free_wifi"
- id: "@switch_vlan[8]"
vlan: "199"
ports: "0t 1t"
description: "oldAurora"
wireless_devices:
- id: "{{ device_2g_radio }}"

View File

@@ -1,40 +1,33 @@
device_ip_address: "10.11.99.6"
device_hostname: "ap-vila-dole"
network_swconfig_switch_vlans:
- id: "@switch_vlan[1]"
vlan: "128"
network_swconfig:
- vlan: "128"
ports: "0t 6t 1 2 3 4"
description: "hoste"
- id: "@switch_vlan[2]"
vlan: "129"
- vlan: "129"
ports: "0t 6t"
description: "hoste_wifi"
- id: "@switch_vlan[3]"
vlan: "136"
- vlan: "136"
ports: "0t 6t"
description: "studenti_lan"
- id: "@switch_vlan[4]"
vlan: "137"
- vlan: "137"
ports: "0t 6t"
description: "studenti_wifi"
- id: "@switch_vlan[5]"
vlan: "144"
- vlan: "144"
ports: "0t 6t"
description: "ucitele_lan"
- id: "@switch_vlan[6]"
vlan: "145"
- vlan: "145"
ports: "0t 6t"
description: "ucitele_wifi"
- id: "@switch_vlan[7]"
vlan: "152"
- vlan: "152"
ports: "0t 6t"
description: "free_wifi"
wireless_devices:
- id: "{{ device_2g_radio }}"
channel: "13"
txpower: "4"
txpower: "8"
# wireless_interfaces_override:
# - ssid: "aurora"

View File

@@ -1,44 +1,36 @@
device_ip_address: "10.11.99.5"
device_hostname: "ap-vila-nahore"
network_swconfig_switch_vlans:
- id: "@switch_vlan[0]"
vlan: "99"
network_swconfig:
- vlan: "99"
ports: "0t 6t 2t"
description: "mgmnt"
- id: "@switch_vlan[1]"
vlan: "128"
- vlan: "128"
ports: "0t 6t 1 2t 3 4"
description: "hoste"
- id: "@switch_vlan[2]"
vlan: "129"
- vlan: "129"
ports: "0t 6t 2t"
description: "hoste_wifi"
- id: "@switch_vlan[3]"
vlan: "136"
- vlan: "136"
ports: "0t 6t 2t"
description: "studenti_lan"
- id: "@switch_vlan[4]"
vlan: "137"
- vlan: "137"
ports: "0t 6t 2t"
description: "studenti_wifi"
- id: "@switch_vlan[5]"
vlan: "144"
- vlan: "144"
ports: "0t 6t 2t"
description: "ucitele_lan"
- id: "@switch_vlan[6]"
vlan: "145"
- vlan: "145"
ports: "0t 6t 2t"
description: "ucitele_wifi"
- id: "@switch_vlan[7]"
vlan: "152"
- vlan: "152"
ports: "0t 6t 2t"
description: "free_wifi"
wireless_devices:
- id: "{{ device_2g_radio }}"
channel: "8"
txpower: "4"
txpower: "8"
# wireless_interfaces_override:
# - ssid: "aurora"

View File

@@ -5,9 +5,13 @@ openwrt:
accessPoints:
vars:
ansible_scp_extra_args: "-O"
children:
dsa:
hosts:
ap_107c61992bd8:
ansible_host: "10.11.99.2"
swconfig:
hosts:
# ap_c47154394838:
# ansible_host: "10.11.99.2"
ap_b04e26bbc7e3:
ansible_host: "10.11.99.3"
ap_0c806307e88a:

View File

@@ -1,5 +1,6 @@
---
# Reload network service using nohup
# Reload network service
- name: Reload network
nohup:
command: /etc/init.d/network restart
ansible.builtin.service:
name: network
state: reloaded

View File

@@ -1,42 +1,33 @@
---
# Set state status for network device
- name: Set state status for network device {{ item.id | default('@device[-1]') }}
- name: Set state status for network device {{ item.name }}
ansible.builtin.set_fact:
network_device_state: "{{ item.state | default('present') }}"
# Delete network device
- name: Delete network device {{ item.id }}
- name: Delete network device {{ item.name }}
when: "'absent' in network_device_state"
uci:
command: "absent"
config: "network"
section: "{{ item.id }}"
type: "device"
find:
name: "{{ item.name | mandatory }}"
# Create and configure network device
- name: Create and configure network device
when: "'present' in network_device_state"
block:
# Create network device
- name: Create network device {{ item.id | default('@device[-1]') }}
uci:
command: "add"
command: "section"
config: "network"
section: "{{ item.id | default('@device[-1]') }}"
type: "device"
# Configure network device
- name: Configure network device {{ item.id | default('@device[-1]') }}
uci:
command: "set"
config: "network"
section: "{{ item.id | default('@device[-1]') }}"
type: "device"
value:
find:
name: "{{ item.name | default(omit) }}"
value:
type: "{{ item.type | default(omit) }}"
ports: "{{ item.ports | default([]) | join(' ') }}"
stp: "{{ item.stp | default(omit) }}"
vlan: "{{ item.vlan | default(omit) }}"
igmp_snooping: "{{ item.igmp_snooping | default(omit) }}"
ipv6: "{{ item.ipv6 | default(omit) }}"
replace: "yes"

View File

@@ -4,22 +4,22 @@
when: network_globals is defined
ansible.builtin.include_tasks: globals.yml
# Configure swconfig switch vlan section
- name: Configure swconfig switch vlan section
ansible.builtin.include_tasks: switch_swconfig.yml
when: network_swconfig_switch_vlans is defined
loop: "{{ network_swconfig_switch_vlans | default([]) }}"
# Configure dsa switch vlan section
- name: Configure dsa switch vlan section
ansible.builtin.include_tasks: switch_dsa.yml
when: network_dsa_switch_vlans is defined
loop: "{{ network_dsa_switch_vlans | default([]) }}"
# Configure swconfig vlan section
- name: Configure swconfig vlan section
ansible.builtin.include_tasks: swconfig.yml
when: network_swconfig is defined
loop: "{{ network_swconfig | default([]) }}"
# Configure device section
- name: Configure device section
ansible.builtin.include_tasks: device.yml
loop: "{{ network_devices | default([]) }}"
loop: "{{ network_devices | default([]) + network_devices_append | default([]) }}"
# Configure dsa switch vlan section
- name: Configure dsa switch vlan section
ansible.builtin.include_tasks: vlan_filtering.yml
when: network_bridge_vlan_filtering is defined
loop: "{{ network_bridge_vlan_filtering | default([]) }}"
# Configure interface section
- name: Configure interface section
@@ -40,4 +40,16 @@
- name: Apply changes and reload network
uci:
command: commit
notify: Reload network
# Reload network service
- name: Reload network
nohup:
command: /etc/init.d/network restart
# Update device ip address
- name: Update device ip address
set_fact:
ansible_host: "{{ device_ip_address }}"
when: device_ip_address is defined
- name: Wait target connection to become reachable/usable
ansible.builtin.wait_for_connection:
timeout: 30

View File

@@ -0,0 +1,31 @@
---
# Set state status for switch vlan
- name: Set state status for switch vlan {{ item.vlan }}
ansible.builtin.set_fact:
switch_vlan_state: "{{ item.state | default('present') }}"
# Delete switch vlan
- name: Delete switch vlan {{ item.vlan }}
when: "'absent' in switch_vlan_state"
uci:
command: "absent"
config: "network"
type: "switch_vlan"
find:
vlan: "{{ item.vlan | mandatory }}"
# Create and configure switch vlan
- name: Create and configure switch vlan
when: "'present' in switch_vlan_state"
uci:
command: "section"
config: "network"
type: "switch_vlan"
find:
vlan: "{{ item.vlan | mandatory }}"
value:
device: "{{ item.device | default('switch0') }}"
vid: "{{ item.vid | default(item.vlan | default(omit)) }}"
ports: "{{ item.ports | default([]) }}"
description: "{{ item.description | default(omit) }}"
replace: "yes"

View File

@@ -1,40 +0,0 @@
---
# Set state status for switch vlan
- name: Set state status for switch vlan {{ item.id | default('@switch_vlan[-1]') }}
ansible.builtin.set_fact:
switch_vlan_state: "{{ item.state | default('present') }}"
# Delete switch vlan
- name: Delete switch vlan {{ item.id }}
when: "'absent' in switch_vlan_state"
uci:
command: "absent"
config: "network"
section: "{{ item.id }}"
type: "switch_vlan"
# Create and configure switch vlan
- name: Create and configure switch vlan
when: "'present' in switch_vlan_state"
block:
# Create switch vlan
- name: Create switch vlan {{ item.id | default('@switch_vlan[-1]') }}
uci:
command: "add"
config: "network"
section: "{{ item.id | default('@switch_vlan[-1]') }}"
type: "switch_vlan"
# Configure switch vlan
- name: Configure switch vlan {{ item.id | default('@switch_vlan[-1]') }}
uci:
command: "set"
config: "network"
section: "{{ item.id | default('@switch_vlan[-1]') }}"
type: "switch_vlan"
value:
device: "{{ item.device | default('switch0') }}"
vlan: "{{ item.vlan | mandatory }}"
vid: "{{ item.vid | default(item.vlan | default(omit)) }}"
ports: "{{ item.ports | default([]) }}"
description: "{{ item.description | default(omit) }}"

View File

@@ -1,40 +0,0 @@
---
# Set state status for switch vlan
- name: Set state status for switch vlan {{ item.id | default('@switch_vlan[-1]') }}
ansible.builtin.set_fact:
switch_vlan_state: "{{ item.state | default('present') }}"
# Delete switch vlan
- name: Delete switch vlan {{ item.id }}
when: "'absent' in switch_vlan_state"
uci:
command: "absent"
config: "network"
section: "{{ item.id }}"
type: "switch_vlan"
# Create and configure switch vlan
- name: Create and configure switch vlan
when: "'present' in switch_vlan_state"
block:
# Create switch vlan
- name: Create switch vlan {{ item.id | default('@switch_vlan[-1]') }}
uci:
command: "add"
config: "network"
section: "{{ item.id | default('@switch_vlan[-1]') }}"
type: "switch_vlan"
# Configure switch vlan
- name: Configure switch vlan {{ item.id | default('@switch_vlan[-1]') }}
uci:
command: "set"
config: "network"
section: "{{ item.id | default('@switch_vlan[-1]') }}"
type: "switch_vlan"
value:
device: "{{ item.device | default('switch0') }}"
vlan: "{{ item.vlan | mandatory }}"
vid: "{{ item.vid | default(item.vlan | default(omit)) }}"
ports: "{{ item.ports | default([]) }}"
description: "{{ item.description | default(omit) }}"

View File

@@ -0,0 +1,29 @@
---
# Set state status for vlan filtering
- name: Set state status for switch vlan {{ item.vlan }}
ansible.builtin.set_fact:
switch_vlan_state: "{{ item.state | default('present') }}"
# Delete vlan filtering
- name: Delete switch vlan {{ item.vlan }}
when: "'absent' in switch_vlan_state"
uci:
command: "absent"
config: "network"
type: "bridge-vlan"
find:
vlan: "{{ item.vlan | mandatory }}"
# Create and configure vlan filtering
- name: Create and configure switch vlan
when: "'present' in switch_vlan_state"
uci:
command: "section"
config: "network"
type: "bridge-vlan"
find:
vlan: "{{ item.vlan | mandatory }}"
value:
device: "{{ item.device | mandatory }}"
ports: "{{ item.ports | default([]) }}"
replace: "yes"

View File

@@ -18,6 +18,10 @@
opkg:
name: prometheus-node-exporter-lua
state: present
- name: Install prometheus-node-exporter-lua-hostapd_stations
opkg:
name: prometheus-node-exporter-lua-hostapd_stations
state: present
- name: Configure prometheus-node-exporter-lua
uci:
command: section
@@ -28,7 +32,7 @@
listen_interface: mgmnt
listen_port: 9100
autocommit: true
# - name: Reboot device
# ansible.builtin.command:
# cmd: "reboot"
# changed_when: false
- name: Reboot device
ansible.builtin.command:
cmd: "reboot"
changed_when: false