Commit aac43d55 authored by Lars Beckers's avatar Lars Beckers
Browse files

add networkd role

This implements all our current use cases. Add new cases as neccessary.
parent 15990bfe
---
networkd_type: 'dhcp' # or: 'static', 'bond'
# for static type only
networkd_address: 10.10.10.10/24
networkd_gateway: 10.10.10.1
# for bond type only
networkd_bond: bond0
networkd_bond_devices: [ eth0, eth1 ]
networkd_bond_vlans:
- id: 23
name: storage
bridge: no
address: 10.10.10.10/24
- id: 42
name: public
bridge: yes
address: 10.10.12.22/24
gateway: 10.10.12.1
- id: 69
name: transport
bridge: yes
---
- name: reload systemd service files
systemd: daemon_reload=yes
- name: restart networkd
service: name=systemd-networkd state=restarted
---
- name: ensure networkd has a valid configuration
template:
src: "20-wired-{{ networkd_type }}.network.j2"
dest: /etc/systemd/network/20-wired.network
owner: root
group: root
mode: 0644
notify:
- reload systemd service files
- restart networkd
- name: ensure bonding works correctly
block:
- name: ensure the network packages are installed
apt:
name: "{{ item }}"
state: present
with_items:
- vlan
- bridge-utils
- name: ensure bond module is loaded
modprobe:
name: 8021q
state: present
- name: ensure bond module is loaded after a reboot
copy:
content: "8021q"
dest: /etc/modules-load.d/bond.conf
- name: ensure bond netdev is configured
template:
src: bond.netdev.j2
dest: /etc/systemd/network/{{ networkd_bond }}.netdev
owner: root
group: root
mode: 0644
- name: ensure bond network is configured
template:
src: bond.network.j2
dest: /etc/systemd/network/{{ networkd_bond }}.network
owner: root
group: root
mode: 0644
- name: ensure vlan netdevs are configured
template:
src: vlan.netdev.j2
dest: /etc/systemd/network/vl-{{ item.name }}.netdev
owner: root
group: root
mode: 0644
with_items: networkd_bond_vlans
- name: ensure vlan networks are configured
template:
src: vlan.network.j2
dest: /etc/systemd/network/vl-{{ item.name }}.network
owner: root
group: root
mode: 0644
with_items: networkd_bond_vlans
- name: ensure bridge netdevs are configured
template:
src: bridge.netdev.j2
dest: /etc/systemd/network/vmbr-{{ item.name }}.netdev
owner: root
group: root
mode: 0644
with_items: networkd_bond_vlans
when: item.bridge == yes
- name: ensure bridge networks are configured
template:
src: bridge.network.j2
dest: /etc/systemd/network/vmbr-{{ item.name }}.network
owner: root
group: root
mode: 0644
with_items: networkd_bond_vlans
when: item.bridge == yes and 'address' in item
when: networkd_type == 'bond'
notify:
- reload systemd service files
- restart networkd
- meta: flush_handlers
- name: ensure networkd is enabled and running
service:
name: systemd-networkd
state: started
enabled: yes
- name: ensure legacy methods are disabled
systemd:
name: networking
enabled: no
- name: ensure we wait for network to be online
service:
name: systemd-networkd-wait-online
enabled: yes
[Match]
Name={{ networkd_bond_devices|join(' ') }}
[Network]
Bond={{ networkd_bond }}
[Match]
Name={{ ansible_default_ipv4.interface }}
[Network]
DHCP=ipv4
[Match]
Name={{ ansible_default_ipv4.interface }}
[Network]
Address={{ networkd_address }}
Gateway={{ networkd_gateway }}
{%- for server in nameservers %}
DNS={{ server }}
{% endfor -%}
[NetDev]
Name={{ networkd_bond }}
Kind=bond
[Bond]
Mode=802.3ad
TransmitHashPolicy=layer3+4
MIIMonitorSec=100ms
LACPTransmitRate=fast
[Match]
Name={{ networkd_bond }}
[Network]
{%- for vlan in networkd_bond_vlans %}
VLAN=vl-{{ vlan.name }}
{% endfor -%}
BindCarrier={{ networkd_bond_devices|join(' ') }}
[NetDev]
Name=vmbr-{{ item.name }}
Kind=bridge
[Bridge]
STP=false
ForwardDelaySec=0
#VLANFiltering=true
[Match]
Name=vmbr-{{ item.name }}
[Network]
Address={{ item.address }}
{%- if item.gateway %}
Gateway={{ item.gateway }}
{% endif -%}
[NetDev]
Name=vl-{{ item.name }}
Kind=vlan
[VLAN]
Id={{ item.id }}
[Match]
Name=vl-{{ item.name }}
[Network]
{%- if item.bridge %}
Bridge=vmbr-{{ item.name }}
{% else %}
{%- if item.address %}
Address={{ item.address }}
{%- if item.gateway %}
Gateway={{ item.gateway }}
{% endif -%}
{% endif -%}
{% endif -%}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment