From e7870f6ef6e36cb28d2dd4a35258c7df92bdeab0 Mon Sep 17 00:00:00 2001 From: michael Date: Mon, 5 Sep 2022 22:56:49 +1200 Subject: [PATCH] networking --- ansible/roles/networking/defaults/main.yml | 2 ++ ansible/roles/networking/tasks/main.yml | 32 +++++++++++++++++++ .../roles/networking/templates/bond.netdev.j2 | 0 .../networking/templates/bond.network.j2 | 0 .../networking/templates/bridge.netdev.j2 | 6 ++++ .../networking/templates/bridge.network.j2 | 15 +++++++++ .../networking/templates/ethernet.network.j2 | 0 .../roles/networking/templates/vlan.netdev.j2 | 6 ++++ .../networking/templates/vlan.network.j2 | 9 ++++++ 9 files changed, 70 insertions(+) create mode 100644 ansible/roles/networking/defaults/main.yml create mode 100644 ansible/roles/networking/tasks/main.yml create mode 100644 ansible/roles/networking/templates/bond.netdev.j2 create mode 100644 ansible/roles/networking/templates/bond.network.j2 create mode 100644 ansible/roles/networking/templates/bridge.netdev.j2 create mode 100644 ansible/roles/networking/templates/bridge.network.j2 create mode 100644 ansible/roles/networking/templates/ethernet.network.j2 create mode 100644 ansible/roles/networking/templates/vlan.netdev.j2 create mode 100644 ansible/roles/networking/templates/vlan.network.j2 diff --git a/ansible/roles/networking/defaults/main.yml b/ansible/roles/networking/defaults/main.yml new file mode 100644 index 0000000..30258d9 --- /dev/null +++ b/ansible/roles/networking/defaults/main.yml @@ -0,0 +1,2 @@ +--- +network_vlan_id: '25' \ No newline at end of file diff --git a/ansible/roles/networking/tasks/main.yml b/ansible/roles/networking/tasks/main.yml new file mode 100644 index 0000000..c692bc9 --- /dev/null +++ b/ansible/roles/networking/tasks/main.yml @@ -0,0 +1,32 @@ +--- +- name: add network files + become: true + ansible.builtin.template: + src: "{{ item.source }}" + dest: "{{ item.destination }}" + owner: root + group: root + mode: 0664 + with_items: + - source: vlan.netdev.j2 + destination: /etc/systemd/network/30-vlan{{ network_vlan_id }}.netdev + - source: vlan.network.j2 + destination: /etc/systemd/network/31-vlan{{ network_vlan_id }}.network + - source: bridge.netdev.j2 + destination: /etc/systemd/network/40-br{{ network_vlan_id }}.netdev + - source: bridge.network.j2 + destination: /etc/systemd/network/41-br{{ network_vlan_id }}.network + +- name: modify lacp network file + become: true + ansible.builtin.lineinfile: + state: present + insertafter: '^\[Network\]$' + line: VLAN=vlan{{ network_vlan_id }} + path: /etc/systemd/network/21-lacp.network + +- name: restart systemd-networkd + become: true + ansible.builtin.service: + name: systemd-networkd.service + state: restarted \ No newline at end of file diff --git a/ansible/roles/networking/templates/bond.netdev.j2 b/ansible/roles/networking/templates/bond.netdev.j2 new file mode 100644 index 0000000..e69de29 diff --git a/ansible/roles/networking/templates/bond.network.j2 b/ansible/roles/networking/templates/bond.network.j2 new file mode 100644 index 0000000..e69de29 diff --git a/ansible/roles/networking/templates/bridge.netdev.j2 b/ansible/roles/networking/templates/bridge.netdev.j2 new file mode 100644 index 0000000..54785b4 --- /dev/null +++ b/ansible/roles/networking/templates/bridge.netdev.j2 @@ -0,0 +1,6 @@ +[NetDev] +Name=br{{ network_vlan_id }} +Kind=bridge + +[Bridge] + diff --git a/ansible/roles/networking/templates/bridge.network.j2 b/ansible/roles/networking/templates/bridge.network.j2 new file mode 100644 index 0000000..6b87ca7 --- /dev/null +++ b/ansible/roles/networking/templates/bridge.network.j2 @@ -0,0 +1,15 @@ +[Match] +Name=br{{ network_vlan_id }} + +[Link] +ARP=yes + +[Address] +Address=192.168.{{ network_vlan_id }}.100/24 + +[Route] +Gateway=192.168.{{ network_vlan_id }}.254 + +[Network] +DHCP=no + diff --git a/ansible/roles/networking/templates/ethernet.network.j2 b/ansible/roles/networking/templates/ethernet.network.j2 new file mode 100644 index 0000000..e69de29 diff --git a/ansible/roles/networking/templates/vlan.netdev.j2 b/ansible/roles/networking/templates/vlan.netdev.j2 new file mode 100644 index 0000000..35ff16a --- /dev/null +++ b/ansible/roles/networking/templates/vlan.netdev.j2 @@ -0,0 +1,6 @@ +[NetDev] +Name=vlan{{ network_vlan_id }} +Kind=vlan + +[VLAN] +Id={{ network_vlan_id }} \ No newline at end of file diff --git a/ansible/roles/networking/templates/vlan.network.j2 b/ansible/roles/networking/templates/vlan.network.j2 new file mode 100644 index 0000000..6a812da --- /dev/null +++ b/ansible/roles/networking/templates/vlan.network.j2 @@ -0,0 +1,9 @@ +[Match] +Name=vlan{{ network_vlan_id }} + +[Link] +ARP=off + +[Network] +DHCP=off +Bridge=br{{ network_vlan_id }}