Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement vlan UUID handling #108

Merged
merged 7 commits into from
Dec 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 21 additions & 36 deletions tasks/vlans.yml
Original file line number Diff line number Diff line change
@@ -1,39 +1,24 @@
---
# example:
# opn_vlans:
# - tag: 110
# uuid: ... # uuid definition is optional but recommended
# vlan_parent_interface: lagg1
# settings:
# - key: descr
# value: 110_USR
# - tag: 220
# vlan_parent_interface: lagg2
# settings:
# - key: descr
# value: 220_SRV
#
# if uuid is not defined, the tag is used to generate a uuid

- name: vlans - create vlans
delegate_to: localhost
community.general.xml:
path: "{{ local_config_path }}"
xpath: "/opnsense/vlans/vlan[tag/text()='{{ item.0.tag }}']/{{ item.1.key }}"
value: "{{ item.1.value }}"
pretty_print: true
notify: reconfigure vlans
with_subelements:
- name: vlans - process vlans
ansible.builtin.include_tasks: vlansdo.yml
with_items:
- "{{ opn_vlans }}"
- settings

- name: vlans - setting if
delegate_to: localhost
community.general.xml:
path: "{{ local_config_path }}"
xpath: "/opnsense/vlans/vlan[tag/text()='{{ item.0.tag }}']/if"
value: "{{ item.0.vlan_parent_interface | default(opn_interfaces_vlan_parent_interface) }}"
pretty_print: true
notify: reconfigure vlans
with_subelements:
- "{{ opn_vlans }}"
- settings

- name: vlans - setting vlanif
delegate_to: localhost
community.general.xml:
path: "{{ local_config_path }}"
xpath: "/opnsense/vlans/vlan[tag/text()='{{ item.0.tag }}']/vlanif"
value: "{{ item.0.vlan_parent_interface | default(opn_interfaces_vlan_parent_interface) }}_vlan{{ item.0.tag }}"
pretty_print: true
notify: reconfigure vlans
with_subelements:
- "{{ opn_vlans }}"
- settings

...
loop_control:
label: "{{ _vlan.tag }}"
loop_var: _vlan
49 changes: 49 additions & 0 deletions tasks/vlansdo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
---

- name: vlans - create vlans
delegate_to: localhost
community.general.xml:
path: "{{ local_config_path }}"
xpath: "/opnsense/vlans/vlan[tag/text()='{{ _vlan.tag }}']/{{ _vlansettings.key }}"
value: "{{ _vlansettings.value }}"
pretty_print: true
notify: reconfigure vlans
with_items:
- "{{ _vlan.settings }}"
loop_control:
label: "{{ _vlan.tag }} {{ _vlansettings.key }}"
loop_var: _vlansettings

- name: vlans - setting if
delegate_to: localhost
community.general.xml:
path: "{{ local_config_path }}"
xpath: "/opnsense/vlans/vlan[tag/text()='{{ _vlan.tag }}']/if"
value: "{{ _vlan.vlan_parent_interface | default(opn_interfaces_vlan_parent_interface) }}"
pretty_print: true
notify: reconfigure vlans

- name: vlans - setting vlanif
delegate_to: localhost
community.general.xml:
path: "{{ local_config_path }}"
xpath: "/opnsense/vlans/vlan[tag/text()='{{ _vlan.tag }}']/vlanif"
value: "{{ _vlan.vlan_parent_interface | default(opn_interfaces_vlan_parent_interface) }}_vlan{{ _vlan.tag }}"
pretty_print: true
notify: reconfigure vlans

- name: vlans - define uuid
ansible.builtin.set_fact:
_uuid: "{{ _vlan.uuid | default(_vlan.tag | to_uuid) }}"

- name: vlans - set uuid
delegate_to: localhost
community.general.xml:
path: "{{ local_config_path }}"
xpath: "/opnsense/vlans/vlan[tag/text()='{{ _vlan.tag }}']"
attribute: uuid
value: "{{ _uuid }}"
pretty_print: true
notify: reconfigure vlans

...
4 changes: 4 additions & 0 deletions test/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@
- name: nut restart
debug:
msg: fake handler - nut restart
- name: reconfigure vlans
debug:
msg: fake handler - reconfigure vlans
tasks:
- name: include default vars
ansible.builtin.include_vars:
Expand All @@ -51,6 +54,7 @@
- general
- filter
- alias
- vlans
- gateways
- wireguard
- ipsec
Expand Down
19 changes: 19 additions & 0 deletions test/vlans-test-legacy-expect.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version='1.0' encoding='UTF-8'?>
<opnsense>
<system>
</system>
<vlans>
<vlan uuid="e4f4bc10-1718-550b-bb20-972318edf556">
<tag>110</tag>
<descr>110_USR</descr>
<if>lagg1</if>
<vlanif>lagg1_vlan110</vlanif>
</vlan>
<vlan uuid="bdf28cf6-e4d0-5782-aee4-e4d8c8946032">
<tag>220</tag>
<descr>220_SRV</descr>
<if>lagg2</if>
<vlanif>lagg2_vlan220</vlanif>
</vlan>
</vlans>
</opnsense>
13 changes: 13 additions & 0 deletions test/vlans-test-legacy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---

opn_vlans:
- tag: 110
vlan_parent_interface: lagg1
settings:
- key: descr
value: 110_USR
- tag: 220
vlan_parent_interface: lagg2
settings:
- key: descr
value: 220_SRV
19 changes: 19 additions & 0 deletions test/vlans-test-uuid-expect.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version='1.0' encoding='UTF-8'?>
<opnsense>
<system>
</system>
<vlans>
<vlan uuid="60383065-4adf-5652-ace0-936604cd8376">
<tag>110</tag>
<descr>110_USR</descr>
<if>lagg1</if>
<vlanif>lagg1_vlan110</vlanif>
</vlan>
<vlan uuid="5847f2ba-18e3-5405-97aa-991425034f8a">
<tag>220</tag>
<descr>220_SRV</descr>
<if>lagg2</if>
<vlanif>lagg2_vlan220</vlanif>
</vlan>
</vlans>
</opnsense>
15 changes: 15 additions & 0 deletions test/vlans-test-uuid.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---

opn_vlans:
- tag: 110
vlan_parent_interface: lagg1
uuid: 60383065-4adf-5652-ace0-936604cd8376
settings:
- key: descr
value: 110_USR
- tag: 220
vlan_parent_interface: lagg2
uuid: 5847f2ba-18e3-5405-97aa-991425034f8a
settings:
- key: descr
value: 220_SRV