Initial commit

This commit is contained in:
2024-10-30 01:50:38 +01:00
commit 587ca23374
147 changed files with 7521 additions and 0 deletions

View File

@@ -0,0 +1,42 @@
---
# Set state status for network device
- name: Set state status for network device {{ item.id | default('@device[-1]') }}
ansible.builtin.set_fact:
network_device_state: "{{ item.state | default('present') }}"
# Delete network device
- name: Delete network device {{ item.id }}
when: "'absent' in network_device_state"
uci:
command: "absent"
config: "network"
section: "{{ item.id }}"
type: "device"
# 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"
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:
name: "{{ item.name | default(omit) }}"
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) }}"

View File

@@ -0,0 +1,11 @@
---
# Configure globals settings
- name: Configure globals settings
uci:
command: "set"
config: "network"
section: "globals"
type: "globals"
value:
ula_prefix: "{{ network_globals.network_ula_prefix | default(omit) }}"
packet_steering: "{{ network_globals.network_packet_steering | default(omit) }}"

View File

@@ -0,0 +1,50 @@
---
# Set state status for network interface
- name: Set state status for network interface {{ item.id }}
ansible.builtin.set_fact:
network_interface_state: "{{ item.state | default('present') }}"
# Delete network interface
- name: Delete network interface {{ item.id }}
when: "'absent' in network_interface_state"
uci:
command: "absent"
config: "network"
section: "{{ item.id }}"
type: "interface"
# Create and configure network interface
- name: Create and configure network interface
when: "'present' in network_interface_state"
block:
# Create network interface
- name: Create network interface {{ item.id }}
uci:
command: "add"
config: "network"
section: "{{ item.id }}"
type: "interface"
# Configure network interface
- name: Configure network interface {{ item.id }}
uci:
command: "set"
config: "network"
section: "{{ item.id }}"
type: "interface"
value:
device: "{{ item.device | default(omit) }}"
proto: "{{ item.proto | default(omit) }}"
auto: "{{ item.auto | default(omit) }}"
force_link: "{{ item.force_link | default(omit) }}"
ipaddr: "{{ item.ipaddr | default(omit) }}"
netmask: "{{ item.netmask | default(omit) }}"
gateway: "{{ item.gateway | default(omit) }}"
peerdns: "{{ item.peerdns | default(omit) }}"
dns: "{{ item.dns | default([]) | join(' ') }}"
username: "{{ item.username | default(omit) }}"
password: "{{ item.password | default(omit) }}"
mtu: "{{ item.mtu | default(omit) }}"
ipv6: "{{ item.ipv6 | default(omit) }}"
delegate: "{{ item.delegate | default(omit) }}"
ip6assign: "{{ item.ip6assign | default(omit) }}"

View File

@@ -0,0 +1,43 @@
---
# Configure globals section
- name: Configure globals section
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 device section
- name: Configure device section
ansible.builtin.include_tasks: device.yml
loop: "{{ network_devices | default([]) }}"
# Configure interface section
- name: Configure interface section
ansible.builtin.include_tasks: interface.yml
loop: "{{ network_interfaces | default([]) }}"
# Configure rule section
- name: Configure rule section
ansible.builtin.include_tasks: rule.yml
loop: "{{ network_rules | default([]) }}"
# Configure route section
- name: Configure route section
ansible.builtin.include_tasks: route.yml
loop: "{{ network_routes | default([]) }}"
# Apply changes and reload network service
- name: Apply changes and reload network
uci:
command: commit
notify: Reload network

View File

@@ -0,0 +1,44 @@
---
# Set state status for network route
- name: Set state status for network route {{ item.id | default('@route[-1]') }}
ansible.builtin.set_fact:
network_route_state: "{{ item.state | default('present') }}"
# Delete network route
- name: Delete network route {{ item.id }}
when: "'absent' in network_route_state"
uci:
command: "absent"
config: "network"
section: "{{ item.id }}"
type: "route"
# Create and configure network route
- name: Create and configure network route
when: "'present' in network_route_state"
block:
# Create network route
- name: Create network route {{ item.id | default('@route[-1]') }}
uci:
command: "add"
config: "network"
section: "{{ item.id | default('@route[-1]') }}"
type: "route"
# Configure network route
- name: Configure network route {{ item.id | default('@route[-1]') }}
uci:
command: "set"
config: "network"
section: "{{ item.id | default('@route[-1]') }}"
type: "route"
value:
interface: "{{ item.interface | default(omit) }}"
target: "{{ item.target | default(omit) }}"
netmask: "{{ item.netmask | default(omit) }}"
gateway: "{{ item.gateway | default(omit) }}"
table: "{{ item.table | default(omit) }}"
source: "{{ item.source | default(omit) }}"
type: "{{ item.type | default(omit) }}"
proto: "{{ item.proto | default(omit) }}"
disabled: "{{ item.disabled | default(omit) }}"

View File

@@ -0,0 +1,46 @@
---
# Set state status for network rule
- name: Set state status for network rule {{ item.id | default('@rule[-1]') }}
ansible.builtin.set_fact:
network_rule_state: "{{ item.state | default('present') }}"
# Delete network rule
- name: Delete network rule {{ item.id }}
when: "'absent' in network_rule_state"
uci:
command: "absent"
config: "network"
section: "{{ item.id }}"
type: "rule"
# Create and configure network rule
- name: Create and configure network rule
when: "'present' in network_rule_state"
block:
# Create network rule
- name: Create network rule {{ item.id | default('@rule[-1]') }}
uci:
command: "add"
config: "network"
section: "{{ item.id | default('@rule[-1]') }}"
type: "rule"
# Configure network rule
- name: Configure network rule {{ item.id | default('@rule[-1]') }}
uci:
command: "set"
config: "network"
section: "{{ item.id | default('@rule[-1]') }}"
type: "rule"
value:
mark: "{{ item.mark | default(omit) }}"
in: "{{ item.in | default(omit) }}"
out: "{{ item.out | default(omit) }}"
src: "{{ item.src | default(omit) }}"
dest: "{{ item.dest | default(omit) }}"
invert: "{{ item.invert | default(omit) }}"
priority: "{{ item.priority | default(omit) }}"
lookup: "{{ item.lookup | default(omit) }}"
goto: "{{ item.goto | default([]) | join(' ') }}"
action: "{{ item.action | default(omit) }}"
disabled: "{{ item.disabled | default(omit) }}"

View File

@@ -0,0 +1,40 @@
---
# 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,40 @@
---
# 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) }}"