Move link options to a link file
The link options being set within the network files, which functional, does not expose all of the link capabilities we have within a specific link file. This change implements link files per network interface giving the user the ability to customize links as they need. Change-Id: Ie999c541a6a566141e81c6d9f95b8a30bbbefa8c Signed-off-by: Kevin Carter <kevin.carter@rackspace.com>
This commit is contained in:
parent
744357be82
commit
2921156fd1
@ -28,8 +28,8 @@ systemd_networkd_prefix: "general"
|
|||||||
systemd_run_networkd: false
|
systemd_run_networkd: false
|
||||||
|
|
||||||
# Default filename formatting
|
# Default filename formatting
|
||||||
systemd_networkd_netdev_filename: "{{ item.0 }}-{{ systemd_networkd_prefix }}-{{ item.1.NetDev.Name }}.netdev"
|
systemd_networkd_filename: "{{ item.0 }}-{{ systemd_networkd_prefix }}-{{ item.1.NetDev.Name }}"
|
||||||
systemd_networkd_network_filename: "{{ item.0 }}-{{ systemd_networkd_prefix }}-{{ item.1.interface }}.network"
|
systemd_networkd_filename_alt: "{{ item.0 }}-{{ systemd_networkd_prefix }}-{{ item.1.interface }}"
|
||||||
|
|
||||||
# The `systemd_link_config_overrides` option can be used on the default link.
|
# The `systemd_link_config_overrides` option can be used on the default link.
|
||||||
# See the following link for all available options:
|
# See the following link for all available options:
|
||||||
@ -75,6 +75,10 @@ systemd_netdevs: []
|
|||||||
# into the network file. A full list of all
|
# into the network file. A full list of all
|
||||||
# options can be found here:
|
# options can be found here:
|
||||||
# https://www.freedesktop.org/software/systemd/man/systemd.network.html
|
# https://www.freedesktop.org/software/systemd/man/systemd.network.html
|
||||||
|
# `link_config_overrides` -- (Optional) Used to inject extra configuration
|
||||||
|
# options into link file. A full list
|
||||||
|
# of all options can be found here:
|
||||||
|
# https://www.freedesktop.org/software/systemd/man/systemd.link.html
|
||||||
# `interface` -- (required) Name of interface to match
|
# `interface` -- (required) Name of interface to match
|
||||||
# `address` -- (option) IP address the interface should be given. To make this
|
# `address` -- (option) IP address the interface should be given. To make this
|
||||||
# interface use DHCP set this string to "dhcp"
|
# interface use DHCP set this string to "dhcp"
|
||||||
@ -148,3 +152,10 @@ systemd_networkd_update_initramfs: "{{ _systemd_networkd_update_initramfs | defa
|
|||||||
# - systemd-resolved
|
# - systemd-resolved
|
||||||
|
|
||||||
systemd_networkd_distro_packages: "{{ _systemd_networkd_distro_packages | default([]) }}"
|
systemd_networkd_distro_packages: "{{ _systemd_networkd_distro_packages | default([]) }}"
|
||||||
|
|
||||||
|
# The systemd networkd service can be used to set specific link configuration options.
|
||||||
|
# For more information on all of the possible configuration see
|
||||||
|
# https://www.freedesktop.org/software/systemd/man/systemd.link.html
|
||||||
|
|
||||||
|
systemd_networkd_link:
|
||||||
|
MACAddressPolicy: "persistent"
|
||||||
|
@ -46,21 +46,6 @@
|
|||||||
tags:
|
tags:
|
||||||
- systemd-networkd
|
- systemd-networkd
|
||||||
|
|
||||||
- name: Create systemd-networkd link
|
|
||||||
config_template:
|
|
||||||
src: "systemd-network-link.j2"
|
|
||||||
dest: "/etc/systemd/network/99-default.link"
|
|
||||||
owner: "root"
|
|
||||||
group: "root"
|
|
||||||
mode: "0644"
|
|
||||||
config_overrides: "{{ systemd_link_config_overrides }}"
|
|
||||||
config_type: "ini"
|
|
||||||
notify:
|
|
||||||
- Restart systemd-networkd
|
|
||||||
- Update initramfs
|
|
||||||
tags:
|
|
||||||
- systemd-networkd
|
|
||||||
|
|
||||||
- name: Create systemd-resolved config
|
- name: Create systemd-resolved config
|
||||||
template:
|
template:
|
||||||
src: "systemd-resolved.conf.j2"
|
src: "systemd-resolved.conf.j2"
|
||||||
@ -100,7 +85,7 @@
|
|||||||
- name: Create systemd-networkd network device(s)
|
- name: Create systemd-networkd network device(s)
|
||||||
template:
|
template:
|
||||||
src: "systemd-netdev.j2"
|
src: "systemd-netdev.j2"
|
||||||
dest: "/etc/systemd/network/{{ item.1.filename | default(systemd_networkd_netdev_filename) }}"
|
dest: "/etc/systemd/network/{{ (item.1.filename | default(systemd_networkd_filename)) ~ '.netdev' }}"
|
||||||
owner: "root"
|
owner: "root"
|
||||||
group: "root"
|
group: "root"
|
||||||
mode: "0644"
|
mode: "0644"
|
||||||
@ -110,10 +95,26 @@
|
|||||||
tags:
|
tags:
|
||||||
- systemd-networkd
|
- systemd-networkd
|
||||||
|
|
||||||
- name: Create systemd-networkd network(s)
|
- name: Create systemd-networkd network link(s)
|
||||||
|
config_template:
|
||||||
|
src: "systemd-link.j2"
|
||||||
|
dest: "/etc/systemd/network/{{ (item.1.filename | default(systemd_networkd_filename_alt)) ~ '.link' }}"
|
||||||
|
owner: "root"
|
||||||
|
group: "root"
|
||||||
|
mode: "0644"
|
||||||
|
config_overrides: "{{ item.1.link_config_overrides | default(systemd_link_config_overrides) }}"
|
||||||
|
config_type: "ini"
|
||||||
|
with_indexed_items: "{{ systemd_networks }}"
|
||||||
|
notify:
|
||||||
|
- Update initramfs
|
||||||
|
- Restart systemd-networkd
|
||||||
|
tags:
|
||||||
|
- systemd-networkd
|
||||||
|
|
||||||
|
- name: Create systemd-networkd network network(s)
|
||||||
config_template:
|
config_template:
|
||||||
src: "systemd-network.j2"
|
src: "systemd-network.j2"
|
||||||
dest: "/etc/systemd/network/{{ item.1.filename | default(systemd_networkd_network_filename) }}"
|
dest: "/etc/systemd/network/{{ (item.1.filename | default(systemd_networkd_filename_alt)) ~ '.network' }}"
|
||||||
owner: "root"
|
owner: "root"
|
||||||
group: "root"
|
group: "root"
|
||||||
mode: "0644"
|
mode: "0644"
|
||||||
|
13
templates/systemd-link.j2
Normal file
13
templates/systemd-link.j2
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
# {{ ansible_managed }}
|
||||||
|
|
||||||
|
[Match]
|
||||||
|
Name={{ item.1.interface }}
|
||||||
|
|
||||||
|
[Link]
|
||||||
|
{% if item.1.mtu is defined %}
|
||||||
|
MTUBytes={{ item.1.mtu }}
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
{% for key, value in systemd_networkd_link.items() %}
|
||||||
|
{{ key }}={{ value }}
|
||||||
|
{% endfor %}
|
@ -1,5 +0,0 @@
|
|||||||
# {{ ansible_managed }}
|
|
||||||
|
|
||||||
[Link]
|
|
||||||
NamePolicy=kernel database onboard slot path
|
|
||||||
MACAddressPolicy=persistent
|
|
@ -55,8 +55,3 @@ MACVLAN={{ item.1.macvlan }}
|
|||||||
{% elif item.1.vxlan is defined %}
|
{% elif item.1.vxlan is defined %}
|
||||||
VXLAN={{ item.1.vxlan }}
|
VXLAN={{ item.1.vxlan }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
[Link]
|
|
||||||
{% if item.1.mtu is defined %}
|
|
||||||
MTUBytes={{ item.1.mtu }}
|
|
||||||
{% endif %}
|
|
||||||
|
@ -22,6 +22,9 @@
|
|||||||
roles:
|
roles:
|
||||||
- role: "systemd_networkd"
|
- role: "systemd_networkd"
|
||||||
vars:
|
vars:
|
||||||
|
systemd_networkd_link:
|
||||||
|
MACAddressPolicy: "persistent"
|
||||||
|
NamePolicy: "kernel database onboard slot path"
|
||||||
systemd_run_networkd: yes
|
systemd_run_networkd: yes
|
||||||
systemd_resolved:
|
systemd_resolved:
|
||||||
DNS: "208.67.222.222"
|
DNS: "208.67.222.222"
|
||||||
@ -64,7 +67,7 @@
|
|||||||
- interface: "br-dummy"
|
- interface: "br-dummy"
|
||||||
address: "10.0.0.100"
|
address: "10.0.0.100"
|
||||||
netmask: "255.255.255.0"
|
netmask: "255.255.255.0"
|
||||||
gateway: "10.0.0.1"
|
gateway: "{{ ansible_default_ipv4.gateway | default('10.0.0.1') }}"
|
||||||
mtu: 9000
|
mtu: 9000
|
||||||
usedns: true
|
usedns: true
|
||||||
static_routes:
|
static_routes:
|
||||||
@ -73,6 +76,8 @@
|
|||||||
config_overrides:
|
config_overrides:
|
||||||
Network:
|
Network:
|
||||||
ConfigureWithoutCarrier: true
|
ConfigureWithoutCarrier: true
|
||||||
|
link_config_overrides:
|
||||||
|
Alias: "dummy-bridge0"
|
||||||
- interface: "dummy2"
|
- interface: "dummy2"
|
||||||
bridge: "br-test"
|
bridge: "br-test"
|
||||||
- interface: "br-test"
|
- interface: "br-test"
|
||||||
@ -117,6 +122,15 @@
|
|||||||
- ansible_br_test['type'] == 'bridge'
|
- ansible_br_test['type'] == 'bridge'
|
||||||
- ansible_br_test['ipv4']['address'] == '10.1.0.1'
|
- ansible_br_test['ipv4']['address'] == '10.1.0.1'
|
||||||
- ansible_br_test['ipv4']['netmask'] == '255.255.255.0'
|
- ansible_br_test['ipv4']['netmask'] == '255.255.255.0'
|
||||||
|
- name: Check link config overrides
|
||||||
|
shell: 'grep -wo "Alias" /etc/systemd/network/*br-dummy.link'
|
||||||
|
changed_when: false
|
||||||
|
- name: Check general link config
|
||||||
|
shell: 'grep -wo "{{ item }}" /etc/systemd/network/*.link'
|
||||||
|
changed_when: false
|
||||||
|
with_items:
|
||||||
|
- MACAddressPolicy
|
||||||
|
- NamePolicy
|
||||||
|
|
||||||
|
|
||||||
- name: Playbook for role testing with cleanup
|
- name: Playbook for role testing with cleanup
|
||||||
|
Loading…
Reference in New Issue
Block a user