From b9b135ab9a3e9645696c3b0abba8cc32a1818120 Mon Sep 17 00:00:00 2001 From: Logan V Date: Sun, 18 Mar 2018 00:10:39 -0500 Subject: [PATCH] Allow networkd filename override - Allow configuring the default filename format - Allow configuring a filename override on a per netdev/network basis. Change-Id: I801fe5604d543ae36daf5bd1764ef1035644ea44 --- defaults/main.yml | 6 ++++++ tasks/main.yml | 4 ++-- templates/systemd-netdev.j2 | 7 +++++-- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/defaults/main.yml b/defaults/main.yml index 9f710df..56a23c0 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -19,6 +19,10 @@ systemd_interface_cleanup: false # Enable systemd-networkd and (re)start the service 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. # See the following link for all available options: # https://www.freedesktop.org/software/systemd/man/systemd.link.html @@ -41,6 +45,7 @@ systemd_link_config_overrides: {} # - NetDev: # Name: dummy1 # Kind: dummy +# filename: "{{ item.1.NetDev.Name }}.netdev" # - NetDev: # Name: bond0 # Kind: bond @@ -84,6 +89,7 @@ systemd_netdevs: [] # bridge: "bond0" # mtu: 9000 # - interface: "dummy1" +# filename: "{{ item.1.interface }}.network" # bridge: "bond0" # mtu: 9000 # - interface: "bond0" diff --git a/tasks/main.yml b/tasks/main.yml index 8ecce4c..b87b9e7 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -55,7 +55,7 @@ - name: Create systemd-networkd network device(s) template: 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" group: "root" mode: "0644" @@ -66,7 +66,7 @@ - name: Create systemd-networkd network(s) config_template: 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" group: "root" mode: "0644" diff --git a/templates/systemd-netdev.j2 b/templates/systemd-netdev.j2 index 6df853b..c28e2f2 100644 --- a/templates/systemd-netdev.j2 +++ b/templates/systemd-netdev.j2 @@ -1,9 +1,12 @@ # {{ ansible_managed }} +{% set _ignored_sections = ['filename'] %} {% for key, values in item.1.items() %} +{% if key not in _ignored_sections %} [{{ key }}] -{% for k, v in values.items() %} +{% for k, v in values.items() %} {{ k }}={{ v }} -{% endfor %} +{% endfor %} +{% endif %} {% endfor %}