From e005b0a31dcba46dd131ed643260d22144ae4461 Mon Sep 17 00:00:00 2001 From: Markus Katharina Brechtel Date: Sun, 7 Oct 2018 02:10:29 +0000 Subject: [PATCH] set interface names with systemd network links --- tasks/main.yml | 13 +++++++++++++ templates/systemd-network.link.j2 | 7 +++++++ 2 files changed, 20 insertions(+) create mode 100644 templates/systemd-network.link.j2 diff --git a/tasks/main.yml b/tasks/main.yml index 4da4852..c87fe0c 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -40,3 +40,16 @@ with_items: "{{ _netifs }}" when: - ( root_target_dist | default('debian') ) == "debian" + +- name: systemd network dir + file: + path: "{{ root_target_directory | default('') }}/etc/systemd/network" + state: directory + +- name: systemd network interface names + template: + src: systemd-network.link.j2 + dest: "{{ root_target_directory | default('') }}/etc/systemd/network/10-{{ item }}.link" + with_items: "{{ _netifs }}" + when: + - ( root_target_dist | default('debian') ) == "debian" diff --git a/templates/systemd-network.link.j2 b/templates/systemd-network.link.j2 new file mode 100644 index 0000000..13fe6a9 --- /dev/null +++ b/templates/systemd-network.link.j2 @@ -0,0 +1,7 @@ +{{ ansible_managed | comment }} +{% set netif = item %} +{% set dev = netifs[netif].device | default( 'enx' + netifs[netif].mac | regex_replace(':') ) %} +[Match] +MACAddress={{netifs[netif].mac}} +[Link] +Name={{dev}}