Rozdělení do skupin DSA a swconfig, úprava role network
This commit is contained in:
@@ -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
|
||||
@@ -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"
|
||||
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) }}"
|
||||
uci:
|
||||
command: "section"
|
||||
config: "network"
|
||||
type: "device"
|
||||
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"
|
||||
@@ -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
|
||||
31
roles/network/tasks/swconfig.yml
Normal file
31
roles/network/tasks/swconfig.yml
Normal 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"
|
||||
@@ -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) }}"
|
||||
@@ -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) }}"
|
||||
29
roles/network/tasks/vlan_filtering.yml
Normal file
29
roles/network/tasks/vlan_filtering.yml
Normal 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"
|
||||
Reference in New Issue
Block a user