Allow networkd filename override

- Allow configuring the default filename format
- Allow configuring a filename override on a per netdev/network
  basis.

Change-Id: I801fe5604d543ae36daf5bd1764ef1035644ea44
This commit is contained in:
Logan V 2018-03-18 00:10:39 -05:00
parent 48e9cfbcdf
commit b9b135ab9a
3 changed files with 13 additions and 4 deletions

View File

@ -19,6 +19,10 @@ systemd_interface_cleanup: false
# 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_netdev_filename: "{{ item.0 }}-{{ item.1.NetDev.Name }}.netdev"
systemd_networkd_network_filename: "{{ item.0 }}-{{ item.1.interface }}.network"
# 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
@ -41,6 +45,7 @@ systemd_link_config_overrides: {}
# - NetDev: # - NetDev:
# Name: dummy1 # Name: dummy1
# Kind: dummy # Kind: dummy
# filename: "{{ item.1.NetDev.Name }}.netdev"
# - NetDev: # - NetDev:
# Name: bond0 # Name: bond0
# Kind: bond # Kind: bond
@ -84,6 +89,7 @@ systemd_netdevs: []
# bridge: "bond0" # bridge: "bond0"
# mtu: 9000 # mtu: 9000
# - interface: "dummy1" # - interface: "dummy1"
# filename: "{{ item.1.interface }}.network"
# bridge: "bond0" # bridge: "bond0"
# mtu: 9000 # mtu: 9000
# - interface: "bond0" # - interface: "bond0"

View File

@ -55,7 +55,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.0 }}-{{ item.1.NetDev.Name }}.netdev" dest: "/etc/systemd/network/{{ item.1.filename | default(systemd_networkd_netdev_filename) }}"
owner: "root" owner: "root"
group: "root" group: "root"
mode: "0644" mode: "0644"
@ -66,7 +66,7 @@
- name: Create systemd-networkd network(s) - name: Create systemd-networkd network(s)
config_template: config_template:
src: "systemd-network.j2" src: "systemd-network.j2"
dest: "/etc/systemd/network/{{ item.0 }}-{{ item.1.interface }}.network" dest: "/etc/systemd/network/{{ item.1.filename | default(systemd_networkd_network_filename) }}"
owner: "root" owner: "root"
group: "root" group: "root"
mode: "0644" mode: "0644"

View File

@ -1,9 +1,12 @@
# {{ ansible_managed }} # {{ ansible_managed }}
{% set _ignored_sections = ['filename'] %}
{% for key, values in item.1.items() %} {% for key, values in item.1.items() %}
{% if key not in _ignored_sections %}
[{{ key }}] [{{ key }}]
{% for k, v in values.items() %} {% for k, v in values.items() %}
{{ k }}={{ v }} {{ k }}={{ v }}
{% endfor %} {% endfor %}
{% endif %}
{% endfor %} {% endfor %}