Ensure filename is always defined for network/netdev
Right now we define resulting filename in the loop itself, which limits ability to predict expected filename for another loop where list might get filtered. So to get more expected behaviour between tasks we always add filename to the elements in vars. Change-Id: I579980ea3a5e9349d25885530c979649cb6dcb81
This commit is contained in:
parent
1e6fc97dbe
commit
18b36137dc
@ -27,10 +27,6 @@ systemd_networkd_prefix: "general"
|
|||||||
# Enable systemd-networkd and (re)start the service
|
# Enable systemd-networkd and (re)start the service
|
||||||
systemd_run_networkd: false
|
systemd_run_networkd: false
|
||||||
|
|
||||||
# Default filename formatting
|
|
||||||
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.
|
# 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:
|
||||||
# https://www.freedesktop.org/software/systemd/man/systemd.link.html
|
# https://www.freedesktop.org/software/systemd/man/systemd.link.html
|
||||||
@ -75,6 +71,11 @@ 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
|
||||||
|
# `filename` -- (Optional, Recommended) Defines resulted filename for config
|
||||||
|
# to be placed in. For consistency and more
|
||||||
|
# expected behaviour when list of networks
|
||||||
|
# may change it is recommended to supply
|
||||||
|
# filename for each interface.
|
||||||
# `link_config_overrides` -- (Optional) Used to inject extra configuration
|
# `link_config_overrides` -- (Optional) Used to inject extra configuration
|
||||||
# options into link file. A full list
|
# options into link file. A full list
|
||||||
# of all options can be found here:
|
# of all options can be found here:
|
||||||
|
@ -0,0 +1,12 @@
|
|||||||
|
---
|
||||||
|
|
||||||
|
deprecations:
|
||||||
|
- |
|
||||||
|
Variables controlling systemd-networkd default filename templating when one
|
||||||
|
is not supplied were deprecated and has no effect from now on.
|
||||||
|
|
||||||
|
* systemd_networkd_filename
|
||||||
|
* systemd_networkd_filename_alt
|
||||||
|
|
||||||
|
It is highly recommended to provide ``filename`` parameter explicitly
|
||||||
|
whenever you define ``systemd_netdevs`` or ``systemd_networks`` structures.
|
@ -143,11 +143,11 @@
|
|||||||
- 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_filename)) ~ '.netdev' }}"
|
dest: "/etc/systemd/network/{{ item.1.filename }}.netdev"
|
||||||
owner: "root"
|
owner: "root"
|
||||||
group: "root"
|
group: "root"
|
||||||
mode: "0644"
|
mode: "0644"
|
||||||
with_indexed_items: "{{ systemd_netdevs }}"
|
with_indexed_items: "{{ _systemd_netdevs_named }}"
|
||||||
notify:
|
notify:
|
||||||
- Restart systemd-networkd
|
- Restart systemd-networkd
|
||||||
tags:
|
tags:
|
||||||
@ -156,13 +156,13 @@
|
|||||||
- name: Create systemd-networkd network link(s)
|
- name: Create systemd-networkd network link(s)
|
||||||
openstack.config_template.config_template:
|
openstack.config_template.config_template:
|
||||||
src: "systemd-link.j2"
|
src: "systemd-link.j2"
|
||||||
dest: "/etc/systemd/network/{{ (item.1.filename | default(systemd_networkd_filename_alt)) ~ '.link' }}"
|
dest: "/etc/systemd/network/{{ item.1.filename }}.link"
|
||||||
owner: "root"
|
owner: "root"
|
||||||
group: "root"
|
group: "root"
|
||||||
mode: "0644"
|
mode: "0644"
|
||||||
config_overrides: "{{ item.1.link_config_overrides | default(systemd_link_config_overrides) }}"
|
config_overrides: "{{ item.1.link_config_overrides | default(systemd_link_config_overrides) }}"
|
||||||
config_type: "ini"
|
config_type: "ini"
|
||||||
with_indexed_items: "{{ systemd_networks }}"
|
with_indexed_items: "{{ _systemd_networks_named }}"
|
||||||
notify:
|
notify:
|
||||||
- Update initramfs
|
- Update initramfs
|
||||||
- Restart systemd-networkd
|
- Restart systemd-networkd
|
||||||
@ -172,13 +172,13 @@
|
|||||||
- name: Create systemd-networkd network network(s)
|
- name: Create systemd-networkd network network(s)
|
||||||
openstack.config_template.config_template:
|
openstack.config_template.config_template:
|
||||||
src: "systemd-network.j2"
|
src: "systemd-network.j2"
|
||||||
dest: "/etc/systemd/network/{{ (item.1.filename | default(systemd_networkd_filename_alt)) ~ '.network' }}"
|
dest: "/etc/systemd/network/{{ item.1.filename }}.network"
|
||||||
owner: "root"
|
owner: "root"
|
||||||
group: "root"
|
group: "root"
|
||||||
mode: "0644"
|
mode: "0644"
|
||||||
config_overrides: "{{ item.1.config_overrides | default({}) }}"
|
config_overrides: "{{ item.1.config_overrides | default({}) }}"
|
||||||
config_type: "ini"
|
config_type: "ini"
|
||||||
with_indexed_items: "{{ systemd_networks }}"
|
with_indexed_items: "{{ _systemd_networks_named }}"
|
||||||
notify:
|
notify:
|
||||||
- Restart systemd-networkd
|
- Restart systemd-networkd
|
||||||
tags:
|
tags:
|
||||||
@ -206,7 +206,7 @@
|
|||||||
sysctl_set: yes
|
sysctl_set: yes
|
||||||
state: present
|
state: present
|
||||||
reload: yes
|
reload: yes
|
||||||
with_indexed_items: "{{ systemd_networks }}"
|
with_indexed_items: "{{ _systemd_networks_named }}"
|
||||||
when:
|
when:
|
||||||
- (ansible_facts['os_family'] | lower) == 'redhat'
|
- (ansible_facts['os_family'] | lower) == 'redhat'
|
||||||
- item.1.ipforward | default(false) | bool
|
- item.1.ipforward | default(false) | bool
|
||||||
|
@ -15,3 +15,21 @@
|
|||||||
|
|
||||||
## APT Cache options
|
## APT Cache options
|
||||||
cache_timeout: 600
|
cache_timeout: 600
|
||||||
|
|
||||||
|
_systemd_networks_named: |-
|
||||||
|
{% set named_networks = systemd_networks | selectattr('filename', 'defined') %}
|
||||||
|
{% for network in systemd_networks | rejectattr('filename', 'defined') %}
|
||||||
|
{% set network_filename = [loop.index0, systemd_networkd_prefix, network['interface']] %}
|
||||||
|
{% set _ = network.update({'filename': network_filename | join('-') }) %}
|
||||||
|
{% set _ = named_networks.append(network) %}
|
||||||
|
{% endfor %}
|
||||||
|
{{ named_networks }}
|
||||||
|
|
||||||
|
_systemd_netdevs_named: |-
|
||||||
|
{% set named_netdevs = systemd_netdevs | selectattr('filename', 'defined') %}
|
||||||
|
{% for netdev in systemd_netdevs | rejectattr('filename', 'defined') %}
|
||||||
|
{% set netdev_filename = [loop.index0, systemd_networkd_prefix, netdev['NetDev']['Name']] %}
|
||||||
|
{% set _ = netdev.update({'filename': netdev_filename | join('-') }) %}
|
||||||
|
{% set _ = named_netdevs.append(netdev) %}
|
||||||
|
{% endfor %}
|
||||||
|
{{ named_netdevs }}
|
||||||
|
Loading…
Reference in New Issue
Block a user