From ba2916ec936446c5157a5888fb1d88405feb44dc Mon Sep 17 00:00:00 2001 From: Thomas Schneider <tschneider@asta.rwth-aachen.de> Date: Fri, 3 Jul 2020 22:20:26 +0200 Subject: [PATCH] Add ifupdown2 role --- ifupdown2/handlers/main.yml | 4 ++++ ifupdown2/tasks/main.yml | 29 +++++++++++++++++++++++++++++ ifupdown2/templates/interfaces.j2 | 28 ++++++++++++++++++++++++++++ 3 files changed, 61 insertions(+) create mode 100644 ifupdown2/handlers/main.yml create mode 100644 ifupdown2/tasks/main.yml create mode 100644 ifupdown2/templates/interfaces.j2 diff --git a/ifupdown2/handlers/main.yml b/ifupdown2/handlers/main.yml new file mode 100644 index 0000000..e109783 --- /dev/null +++ b/ifupdown2/handlers/main.yml @@ -0,0 +1,4 @@ +--- + +- name: Reload interfaces + command: ifreload -a diff --git a/ifupdown2/tasks/main.yml b/ifupdown2/tasks/main.yml new file mode 100644 index 0000000..8c2ddbc --- /dev/null +++ b/ifupdown2/tasks/main.yml @@ -0,0 +1,29 @@ +--- + +- name: Install ifupdown2 + apt: + name: + - ifupdown2 + +- name: Configure interfaces + template: + src: interfaces.j2 + dest: /etc/network/interfaces + notify: + - Reload interfaces + +- name: Disable systemd-networkd + systemd: + name: "{{ item }}" + enabled: false + state: stopped + loop: + - systemd-networkd.service + - systemd-networkd.socket + - systemd-networkd-wait-online.service + +- name: Enable and start networking + systemd: + name: networking.service + enabled: true + state: started diff --git a/ifupdown2/templates/interfaces.j2 b/ifupdown2/templates/interfaces.j2 new file mode 100644 index 0000000..cccfe91 --- /dev/null +++ b/ifupdown2/templates/interfaces.j2 @@ -0,0 +1,28 @@ +{% macro delist(key, val) -%} +{% if val is iterable and not val is string %} +{% for v in val %} +{{ key }} {{ v }} +{% endfor %} +{% else %} +{{ key }} {{ val }} +{% endif %} +{%- endmacro %} +{{ ansible_managed | comment }} + +source /etc/network/interfaces.d/* + +{% for iface in interfaces %} +{% if iface.auto | default(True) %} +auto {{ iface.name }} +{% endif %} +{% if iface.allow | default(False) %} +allow-{{ iface.allow }} {{ iface.name }} +{% endif %} +iface {{ iface.name }} {{ iface.family | default("") }} {{ iface.method | default("") }} +{% if iface.config is defined %}{% for k, v in iface.config.items() %} + {{ delist(k, v) }} +{%- endfor %}{% endif %} +{% if not loop.last %} + +{% endif %} +{% endfor %} -- GitLab