diff --git a/ifupdown2/handlers/main.yml b/ifupdown2/handlers/main.yml new file mode 100644 index 0000000000000000000000000000000000000000..e1097839183ec9cf27f43d53073d84a29141ab3d --- /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 0000000000000000000000000000000000000000..8c2ddbc7d1c14dd4bd153c3dc302eba34d83c4ca --- /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 0000000000000000000000000000000000000000..cccfe91a7f78fc27dec6fc9aa6b761a07e1d2d80 --- /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 %}