skylab
/
skylab-ansible
Archived
2
0
Fork 0

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
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:

View File

@ -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

View File

@ -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 %}

View File

@ -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 %}