Initial commit
This commit is contained in:
4
ansible/roles/vxlan/handlers/main.yml
Normal file
4
ansible/roles/vxlan/handlers/main.yml
Normal file
@@ -0,0 +1,4 @@
|
||||
---
|
||||
- name: reload systemd
|
||||
systemd:
|
||||
daemon_reload: yes
|
||||
19
ansible/roles/vxlan/tasks/main.yml
Normal file
19
ansible/roles/vxlan/tasks/main.yml
Normal file
@@ -0,0 +1,19 @@
|
||||
---
|
||||
- name: Create VXLAN interface setup script
|
||||
template:
|
||||
src: setup-vxlan.sh.j2
|
||||
dest: /usr/local/bin/setup-vxlan-{{ gateway_config.lab_name }}.sh
|
||||
mode: '0755'
|
||||
|
||||
- name: Create systemd service for VXLAN
|
||||
template:
|
||||
src: vxlan.service.j2
|
||||
dest: /etc/systemd/system/vxlan-{{ gateway_config.lab_name }}.service
|
||||
notify: reload systemd
|
||||
|
||||
- name: Enable and start VXLAN service
|
||||
systemd:
|
||||
name: vxlan-{{ gateway_config.lab_name }}
|
||||
enabled: yes
|
||||
state: started
|
||||
daemon_reload: yes
|
||||
35
ansible/roles/vxlan/templates/setup-vxlan.sh.j2
Normal file
35
ansible/roles/vxlan/templates/setup-vxlan.sh.j2
Normal file
@@ -0,0 +1,35 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
LAB_NAME="{{ gateway_config.lab_name }}"
|
||||
VNI="{{ gateway_config.vni }}"
|
||||
WG_IF="wg-${LAB_NAME}"
|
||||
VXLAN_IF="vxlan${VNI}"
|
||||
|
||||
# Wait for WireGuard interface
|
||||
timeout=30
|
||||
while [ $timeout -gt 0 ]; do
|
||||
if ip link show ${WG_IF} &>/dev/null; then
|
||||
break
|
||||
fi
|
||||
sleep 1
|
||||
((timeout--))
|
||||
done
|
||||
|
||||
# Create VXLAN interface
|
||||
if ! ip link show ${VXLAN_IF} &>/dev/null; then
|
||||
ip link add ${VXLAN_IF} type vxlan \
|
||||
id ${VNI} \
|
||||
dev ${WG_IF} \
|
||||
dstport {{ vxlan_port }} \
|
||||
nolearning \
|
||||
proxy
|
||||
fi
|
||||
|
||||
# Configure VXLAN peers (FDB entries)
|
||||
{% for peer in gateway_config.peers %}
|
||||
bridge fdb append 00:00:00:00:00:00 dev ${VXLAN_IF} dst {{ peer.wg_ip }}
|
||||
{% endfor %}
|
||||
|
||||
# Bring up interface
|
||||
ip link set ${VXLAN_IF} up
|
||||
13
ansible/roles/vxlan/templates/vxlan.service.j2
Normal file
13
ansible/roles/vxlan/templates/vxlan.service.j2
Normal file
@@ -0,0 +1,13 @@
|
||||
[Unit]
|
||||
Description=VXLAN interface for {{ gateway_config.lab_name }}
|
||||
After=wg-quick@wg-{{ gateway_config.lab_name }}.service
|
||||
Requires=wg-quick@wg-{{ gateway_config.lab_name }}.service
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
RemainAfterExit=yes
|
||||
ExecStart=/usr/local/bin/setup-vxlan-{{ gateway_config.lab_name }}.sh
|
||||
ExecStop=/sbin/ip link delete vxlan{{ gateway_config.vni }}
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
Reference in New Issue
Block a user