Reorganize network spec to more accurately reflect settings

This commit is contained in:
Ethan Paul 2021-11-06 21:37:15 -04:00
parent 2cff4e4354
commit fe0cd3ab67
No known key found for this signature in database
GPG Key ID: 6A337337DF6B5B1A
4 changed files with 66 additions and 61 deletions

View File

@ -44,23 +44,24 @@ en1:
address: 10.42.101.10/24 address: 10.42.101.10/24
interface: bond0 interface: bond0
skylab_networking: skylab_networking:
dns: [10.42.101.1] eno1:
gateway: 10.42.101.1/24 bond: bond0
interfaces: eno2:
eno1: bond: bond0
bond: bond0 bond0:
eno2: type: bond
bond: bond0 gateway: 10.42.101.1/24
bond0: dns:
type: bond - 10.42.101.1
addresses: addresses:
- 10.42.101.100/24 - 10.42.101.100/24
- 192.168.255.255/32 - 192.168.255.255/32
dhcp: false dhcp: false
bond0.99: bond0.99:
type: vlan type: vlan
addresses: [192.168.42.10/24] addresses:
dhcp: false - 192.168.42.10/24
dhcp: false
saturn: # remus saturn: # remus
ansible_host: 10.42.101.110 ansible_host: 10.42.101.110
@ -70,23 +71,24 @@ en1:
address: 10.42.101.11/24 address: 10.42.101.11/24
interface: bond0 interface: bond0
skylab_networking: skylab_networking:
dns: [10.42.101.1] eno1:
gateway: 10.42.101.1/24 bond: bond0
interfaces: eno2:
eno1: bond: bond0
bond: bond0 bond0:
eno2: type: bond
bond: bond0 dhcp: false
bond0: gateway: 10.42.101.1/24
type: bond addresses:
addresses: - 10.42.101.110/24
- 10.42.101.110/24 - 192.168.255.255/32
- 192.168.255.255/32 dns:
dhcp: false - 10.42.101.1
bond0.99: bond0.99:
type: vlan type: vlan
addresses: [192.168.42.20/24] dhcp: false
dhcp: false addresses:
- 192.168.42.20/24
orion: # romulus orion: # romulus
ansible_host: 10.42.101.120 ansible_host: 10.42.101.120
@ -96,23 +98,24 @@ en1:
address: 10.42.101.12/24 address: 10.42.101.12/24
interface: bond0 interface: bond0
skylab_networking: skylab_networking:
dns: [10.42.101.1] eno1:
gateway: 10.42.101.1/24 bond: bond0
interfaces: eno2:
eno1: bond: bond0
bond: bond0 bond0:
eno2: type: bond
bond: bond0 gateway: 10.42.101.1/24
bond0: dns:
type: bond - 10.42.101.1
addresses: addresses:
- 10.42.101.120/24 - 10.42.101.120/24
- 192.168.255.255/32 - 192.168.255.255/32
dhcp: false dhcp: false
bond0.99: bond0.99:
type: vlan type: vlan
addresses: [192.168.42.30/24] addresses:
dhcp: false - 192.168.42.30/24
dhcp: false
en2: en2:
vars: vars:

View File

@ -22,19 +22,19 @@
mode: 0644 mode: 0644
owner: root owner: root
group: "{{ ansible_user }}" group: "{{ ansible_user }}"
loop: "{{ skylab_networking.interfaces | dict2items }}" loop: "{{ skylab_networking | dict2items }}"
loop_control: loop_control:
label: "{{ item.key }}" label: "{{ item.key }}"
- name: Create netdev files - name: Create netdev files
when: item.value.type is defined when: item.value.device is defined
ansible.builtin.template: ansible.builtin.template:
src: netdev.j2 src: netdev.j2
dest: /etc/systemd/network/{{ item.key }}.netdev dest: /etc/systemd/network/{{ item.key }}.netdev
mode: 0644 mode: 0644
owner: root owner: root
group: "{{ ansible_user }}" group: "{{ ansible_user }}"
loop: "{{ skylab_networking.interfaces | dict2items }}" loop: "{{ skylab_networking | dict2items }}"
loop_control: loop_control:
label: "{{ item.key }}" label: "{{ item.key }}"
@ -45,7 +45,7 @@
register: _network_config_dir_raw register: _network_config_dir_raw
- name: Remove legacy network config files - 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: ansible.builtin.file:
path: /etc/systemd/network/{{ item }} path: /etc/systemd/network/{{ item }}
state: absent state: absent

View File

@ -2,15 +2,15 @@
# #
[NetDev] [NetDev]
Name={{ item.key }} Name={{ item.key }}
type={{ item.value.type }} Kind={{ item.value.device }}
{% if item.value.type.lower() == 'bond' %} {% if item.value.device.lower() == 'bond' %}
[Bond] [Bond]
Mode={{ item.value.bond_mode | default('balance-rr') }} Mode={{ item.value.bond_mode | default('balance-rr') }}
PrimaryReselectPolicy=always PrimaryReselectPolicy=always
MIIMonitorSec=1s MIIMonitorSec=1s
{% endif %} {% endif %}
{% if item.value.type.lower() == 'vlan' %} {% if item.value.device.lower() == 'vlan' %}
[VLAN] [VLAN]
Id={{ item.key.partition('.')[2] }} Id={{ item.key.partition('.')[2] }}
{% endif %} {% endif %}

View File

@ -14,14 +14,16 @@ DNS={{ server }}
{% if item.value.bond is defined %} {% if item.value.bond is defined %}
Bond={{ item.value.bond }} Bond={{ item.value.bond }}
{% endif %} {% 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') }} 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') }} Address={{ address | ansible.netcommon.ipaddr('host/prefix') }}
{% endfor %} {% endfor %}
{% endif %} {% 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 %} {% if interface.startswith(item.key) and interface.partition('.')[2] | regex_search('^[0-9]{1,4}$') and interface != item.key %}
VLAN={{ interface }} VLAN={{ interface }}
{% endif %} {% endif %}