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
|
||||
|
||||
# Default filename formatting
|
||||
systemd_networkd_netdev_filename: "{{ item.0 }}-{{ systemd_networkd_prefix }}-{{ item.1.NetDev.Name }}.netdev"
|
||||
systemd_networkd_network_filename: "{{ item.0 }}-{{ systemd_networkd_prefix }}-{{ item.1.interface }}.network"
|
||||
systemd_networkd_filename: "{{ item.0 }}-{{ systemd_networkd_prefix }}-{{ item.1.NetDev.Name }}"
|
||||
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.
|
||||
# See the following link for all available options:
|
||||
@ -75,6 +75,10 @@ systemd_netdevs: []
|
||||
# into the network file. A full list of all
|
||||
# options can be found here:
|
||||
# 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
|
||||
# `address` -- (option) IP address the interface should be given. To make this
|
||||
# interface use DHCP set this string to "dhcp"
|
||||
@ -148,3 +152,10 @@ systemd_networkd_update_initramfs: "{{ _systemd_networkd_update_initramfs | defa
|
||||
# - systemd-resolved
|
||||
|
||||
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:
|
||||
- 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
|
||||
template:
|
||||
src: "systemd-resolved.conf.j2"
|
||||
@ -100,7 +85,7 @@
|
||||
- name: Create systemd-networkd network device(s)
|
||||
template:
|
||||
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"
|
||||
group: "root"
|
||||
mode: "0644"
|
||||
@ -110,10 +95,26 @@
|
||||
tags:
|
||||
- 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:
|
||||
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"
|
||||
group: "root"
|
||||
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 %}
|
||||
VXLAN={{ item.1.vxlan }}
|
||||
{% endif %}
|
||||
|
||||
[Link]
|
||||
{% if item.1.mtu is defined %}
|
||||
MTUBytes={{ item.1.mtu }}
|
||||
{% endif %}
|
||||
|
@ -22,6 +22,9 @@
|
||||
roles:
|
||||
- role: "systemd_networkd"
|
||||
vars:
|
||||
systemd_networkd_link:
|
||||
MACAddressPolicy: "persistent"
|
||||
NamePolicy: "kernel database onboard slot path"
|
||||
systemd_run_networkd: yes
|
||||
systemd_resolved:
|
||||
DNS: "208.67.222.222"
|
||||
@ -64,7 +67,7 @@
|
||||
- interface: "br-dummy"
|
||||
address: "10.0.0.100"
|
||||
netmask: "255.255.255.0"
|
||||
gateway: "10.0.0.1"
|
||||
gateway: "{{ ansible_default_ipv4.gateway | default('10.0.0.1') }}"
|
||||
mtu: 9000
|
||||
usedns: true
|
||||
static_routes:
|
||||
@ -73,6 +76,8 @@
|
||||
config_overrides:
|
||||
Network:
|
||||
ConfigureWithoutCarrier: true
|
||||
link_config_overrides:
|
||||
Alias: "dummy-bridge0"
|
||||
- interface: "dummy2"
|
||||
bridge: "br-test"
|
||||
- interface: "br-test"
|
||||
@ -117,6 +122,15 @@
|
||||
- ansible_br_test['type'] == 'bridge'
|
||||
- ansible_br_test['ipv4']['address'] == '10.1.0.1'
|
||||
- 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
|
||||
|
Loading…
Reference in New Issue
Block a user