From fe0cd3ab676ef9561c0413190ae214e45f248bd8 Mon Sep 17 00:00:00 2001 From: Ethan Paul Date: Sat, 6 Nov 2021 21:37:15 -0400 Subject: [PATCH] Reorganize network spec to more accurately reflect settings --- inventory.yaml | 105 +++++++++++++++--------------- roles/server/tasks/networkd.yaml | 8 +-- roles/server/templates/netdev.j2 | 6 +- roles/server/templates/network.j2 | 8 ++- 4 files changed, 66 insertions(+), 61 deletions(-) diff --git a/inventory.yaml b/inventory.yaml index 87f7e6e..b50e010 100644 --- a/inventory.yaml +++ b/inventory.yaml @@ -44,23 +44,24 @@ en1: address: 10.42.101.10/24 interface: bond0 skylab_networking: - dns: [10.42.101.1] - gateway: 10.42.101.1/24 - interfaces: - eno1: - bond: bond0 - eno2: - bond: bond0 - bond0: - type: bond - addresses: - - 10.42.101.100/24 - - 192.168.255.255/32 - dhcp: false - bond0.99: - type: vlan - addresses: [192.168.42.10/24] - dhcp: false + eno1: + bond: bond0 + eno2: + bond: bond0 + bond0: + type: bond + gateway: 10.42.101.1/24 + dns: + - 10.42.101.1 + addresses: + - 10.42.101.100/24 + - 192.168.255.255/32 + dhcp: false + bond0.99: + type: vlan + addresses: + - 192.168.42.10/24 + dhcp: false saturn: # remus ansible_host: 10.42.101.110 @@ -70,23 +71,24 @@ en1: address: 10.42.101.11/24 interface: bond0 skylab_networking: - dns: [10.42.101.1] - gateway: 10.42.101.1/24 - interfaces: - eno1: - bond: bond0 - eno2: - bond: bond0 - bond0: - type: bond - addresses: - - 10.42.101.110/24 - - 192.168.255.255/32 - dhcp: false - bond0.99: - type: vlan - addresses: [192.168.42.20/24] - dhcp: false + eno1: + bond: bond0 + eno2: + bond: bond0 + bond0: + type: bond + dhcp: false + gateway: 10.42.101.1/24 + addresses: + - 10.42.101.110/24 + - 192.168.255.255/32 + dns: + - 10.42.101.1 + bond0.99: + type: vlan + dhcp: false + addresses: + - 192.168.42.20/24 orion: # romulus ansible_host: 10.42.101.120 @@ -96,23 +98,24 @@ en1: address: 10.42.101.12/24 interface: bond0 skylab_networking: - dns: [10.42.101.1] - gateway: 10.42.101.1/24 - interfaces: - eno1: - bond: bond0 - eno2: - bond: bond0 - bond0: - type: bond - addresses: - - 10.42.101.120/24 - - 192.168.255.255/32 - dhcp: false - bond0.99: - type: vlan - addresses: [192.168.42.30/24] - dhcp: false + eno1: + bond: bond0 + eno2: + bond: bond0 + bond0: + type: bond + gateway: 10.42.101.1/24 + dns: + - 10.42.101.1 + addresses: + - 10.42.101.120/24 + - 192.168.255.255/32 + dhcp: false + bond0.99: + type: vlan + addresses: + - 192.168.42.30/24 + dhcp: false en2: vars: diff --git a/roles/server/tasks/networkd.yaml b/roles/server/tasks/networkd.yaml index a05223a..9e15742 100644 --- a/roles/server/tasks/networkd.yaml +++ b/roles/server/tasks/networkd.yaml @@ -22,19 +22,19 @@ mode: 0644 owner: root group: "{{ ansible_user }}" - loop: "{{ skylab_networking.interfaces | dict2items }}" + loop: "{{ skylab_networking | dict2items }}" loop_control: label: "{{ item.key }}" - name: Create netdev files - when: item.value.type is defined + when: item.value.device is defined ansible.builtin.template: src: netdev.j2 dest: /etc/systemd/network/{{ item.key }}.netdev mode: 0644 owner: root group: "{{ ansible_user }}" - loop: "{{ skylab_networking.interfaces | dict2items }}" + loop: "{{ skylab_networking | dict2items }}" loop_control: label: "{{ item.key }}" @@ -45,7 +45,7 @@ register: _network_config_dir_raw - name: Remove legacy network config files - when: item.strip().replace('.netdev', '').replace('.network', '') not in skylab_networking.interfaces + when: item.strip().replace('.netdev', '').replace('.network', '') not in skylab_networking ansible.builtin.file: path: /etc/systemd/network/{{ item }} state: absent diff --git a/roles/server/templates/netdev.j2 b/roles/server/templates/netdev.j2 index 08e679e..321670e 100644 --- a/roles/server/templates/netdev.j2 +++ b/roles/server/templates/netdev.j2 @@ -2,15 +2,15 @@ # [NetDev] Name={{ item.key }} -type={{ item.value.type }} +Kind={{ item.value.device }} -{% if item.value.type.lower() == 'bond' %} +{% if item.value.device.lower() == 'bond' %} [Bond] Mode={{ item.value.bond_mode | default('balance-rr') }} PrimaryReselectPolicy=always MIIMonitorSec=1s {% endif %} -{% if item.value.type.lower() == 'vlan' %} +{% if item.value.device.lower() == 'vlan' %} [VLAN] Id={{ item.key.partition('.')[2] }} {% endif %} diff --git a/roles/server/templates/network.j2 b/roles/server/templates/network.j2 index ee233d7..494ef80 100644 --- a/roles/server/templates/network.j2 +++ b/roles/server/templates/network.j2 @@ -14,14 +14,16 @@ DNS={{ server }} {% if item.value.bond is defined %} Bond={{ item.value.bond }} {% endif %} -{% if item.value.dhcp | default(false) %} +{% if not item.value.dhcp | default(false) %} +{% if item.value.gateway is defined %} Gateway={{ item.value.gateway | ansible.netcommon.ipaddr('address') }} -{% for address in item.value.addresses %} +{% endif %} +{% for address in item.value.addresses | default([]) %} Address={{ address | ansible.netcommon.ipaddr('host/prefix') }} {% endfor %} {% endif %} -{% for interface in skylab_networking.interfaces.keys() %} +{% for interface in skylab_networking.keys() %} {% if interface.startswith(item.key) and interface.partition('.')[2] | regex_search('^[0-9]{1,4}$') and interface != item.key %} VLAN={{ interface }} {% endif %}