Pārlūkot izejas kodu

Merge pull request #1 from BarbarossaTM/feature/ifupdown-ng

Add support for ifupdown-ng
Maximilian Wilhelm 3 gadi atpakaļ
vecāks
revīzija
7aabde674a

+ 1 - 1
dhcp-server/init.sls

@@ -3,7 +3,7 @@
 #
 
 include:
-  - network.interfaces
+  - network
 
 isc-dhcp-server:
   pkg.installed:

+ 1 - 1
fastd/init.sls

@@ -3,7 +3,7 @@
 #
 
 include:
-  - network.interfaces
+  - network
 
 {% set sites_all = pillar.get ('sites') %}
 {% set node_config = salt['pillar.get']('nodes:' ~ grains.id, {}) %}

+ 9 - 3
network/bootstrap.sls

@@ -1,9 +1,15 @@
 #
+# Install and configure configured network suite, configure links and install
+# /etc/network/interfaces but do not reload the interafces.
+#
 # To be called from pressed
 #
 
+# Which networ suite to configure?
+{% set default_suite = salt['pillar.get']('network:suite', 'ifupdown2') %}
+{% set suite = salt['pillar.get']('nodes:' ~ grains['id'] ~ ':network:suite', default_suite) %}
+
 include:
  - network.link
- - network.interfaces.base
-
-
+ - network.{{ suite }}
+ - network.interfaces

+ 25 - 0
network/ifupdown-ng/ifupdown-ng.conf

@@ -0,0 +1,25 @@
+#
+# /etc/network/ifupdown-ng.conf (Salt managed)
+#
+# The settings specified here are the defaults of ifupdown-ng.
+
+# allow_addon_scripts:
+# Enable support for /etc/if-X.d addon scripts.  These are used for
+# compatibility with legacy setups, and may be disabled for performance
+# improvements in setups where only ifupdown-ng executors are used.
+allow_addon_scripts = 0
+
+# allow_any_iface_as_template:
+# Enable any interface to act as a template for another interface.
+# This is presently the default, but is deprecated.  An admin may choose
+# to disable this setting in order to require inheritance from specified
+# templates.
+allow_any_iface_as_template = 0
+
+# implicit_template_conversion:
+# In some legacy configs, a template may be declared as an iface, and
+# ifupdown-ng automatically converts those declarations to a proper
+# template.  If this setting is disabled, inheritance will continue to
+# work against non-template interfaces without converting them to a
+# template.
+implicit_template_conversion = 1

+ 19 - 0
network/ifupdown-ng/init.sls

@@ -0,0 +1,19 @@
+#
+# Use ifupdown-ng to manage the interfaces of this box
+#
+
+ifupdown-ng:
+  pkg.installed
+
+# ifupdown-ng configuration
+/etc/network/ifupdown-ng.conf:
+  file.managed:
+    - source:
+      - salt://network/ifupdown-ng/ifupdown-ng.conf
+
+# Remove workaround for ifupdown2
+remove-ifupdown2-workarounds:
+  file.absent:
+    - name:
+      - /usr/local/sbin/ff_fix_default_route
+      - /etc/cron.d/ff_fix_default_route

+ 10 - 0
network/ifupdown-ng/reload.sls

@@ -0,0 +1,10 @@
+#
+# network.ifupdown-ng.reload
+#
+
+# Reload interface configuration if neccessary (no-op for now)
+ifreload:
+  cmd.wait:
+    - name: /bin/true
+    - watch:
+      - file: /etc/network/interfaces

+ 0 - 0
network/interfaces/ff_fix_default_route → network/ifupdown2/ff_fix_default_route


+ 0 - 0
network/interfaces/ff_fix_default_route.cron → network/ifupdown2/ff_fix_default_route.cron


+ 0 - 0
network/ifupdown2.conf → network/ifupdown2/ifupdown2.conf


+ 0 - 0
network/ifupdown2.conf.buster → network/ifupdown2/ifupdown2.conf.buster


+ 0 - 0
network/ifupdown2.conf.stretch → network/ifupdown2/ifupdown2.conf.stretch


+ 15 - 0
network/ifupdown2/init.sls

@@ -0,0 +1,15 @@
+#
+# Use ifupdown2 to manage the interfaces of this box
+#
+
+ifupdown2:
+  pkg.installed
+
+# ifupdown2 configuration
+/etc/network/ifupdown2/ifupdown2.conf:
+  file.managed:
+    - source:
+      - salt://network/ifupdown2/ifupdown2.conf.{{ grains['oscodename'] }}
+      - salt://network/ifupdown2/ifupdown2.conf
+    - require:
+      - pkg: ifupdown2

+ 49 - 0
network/ifupdown2/reload.sls

@@ -0,0 +1,49 @@
+#
+# network.ifupdown2.reload
+#
+
+# Reload interface configuration if neccessary
+ifreload:
+  cmd.wait:
+    - name: /sbin/ifreload -a
+    - watch:
+      - file: /etc/network/interfaces
+
+# If there is an interface in vrf_external, install a workaround script
+# for a bug in ifupdown2 which will sometimes drop an IPv4 default route
+# present in the kernel and not reinstall it.
+#
+# The fix script will be called every minute by cron and after ifreload
+# was called to try to minimize any downtime.
+{% set vrf = [False] %}
+{% for iface, iface_config in salt['pillar.get']('nodes:' ~ grains['id'] ~ ':ifaces', {}).items() %}
+  {% if iface_config.get ('vrf', '') == 'vrf_external' %}
+    {% do vrf.append (True) %}
+    {% break %}
+  {% endif %}
+{% endfor %}
+
+/usr/local/sbin/ff_fix_default_route:
+{% if True in vrf %}
+  file.managed:
+    - source: salt://network/ifupdown2/ff_fix_default_route
+    - mode: 755
+  cmd.wait:
+    - require:
+      - cmd: ifreload
+      - file: /usr/local/sbin/ff_fix_default_route
+    - watch:
+      - file: /etc/network/interfaces
+{% else %}
+  file.absent
+{% endif %}
+
+/etc/cron.d/ff_fix_default_route:
+{% if True in vrf %}
+  file.managed:
+    - source: salt://network/ifupdown2/ff_fix_default_route.cron
+    - template: jinja
+{% else %}
+  file.absent
+{% endif %}
+

+ 7 - 5
network/init.sls

@@ -2,14 +2,20 @@
 # Networking
 #
 
+# Which networ suite to configure?
+{% set default_suite = salt['pillar.get']('network:suite', 'ifupdown2') %}
+{% set suite = salt['pillar.get']('nodes:' ~ grains['id'] ~ ':network:suite', default_suite) %}
+
 include:
-  - apt
   - network.link
+  - network.{{ suite }}
   - network.interfaces
+  - network.{{ suite }}.reload
 
 network-pkg:
   pkg.installed:
     - pkgs:
+      - iproute2
       - tcpdump
       - mtr-tiny
       - iperf
@@ -18,10 +24,6 @@ network-pkg:
     - require_in:
       - file: /etc/network/interfaces
 
-iproute2:
-  pkg.latest
-
-
 vnstat:
   pkg.installed:
     - name: vnstat

+ 0 - 26
network/interfaces/base.sls

@@ -1,26 +0,0 @@
-#
-# network.interface.base
-#
-
-# Install required packets and write /etc/network/interfaces but don't apply it!
-
-ifupdown2:
-  pkg.installed
-
-# ifupdown2 configuration
-/etc/network/ifupdown2/ifupdown2.conf:
-  file.managed:
-    - source:
-      - salt://network/ifupdown2.conf.{{ grains['oscodename'] }}
-      - salt://network/ifupdown2.conf
-    - require:
-      - pkg: ifupdown2
-
-
-# Write network configuration
-/etc/network/interfaces:
- file.managed:
-    - template: jinja
-    - source: salt://network/interfaces/interfaces.tmpl
-    - require:
-      - pkg: ifupdown2

+ 5 - 49
network/interfaces/init.sls

@@ -1,54 +1,10 @@
 #
-# /etc/network/interfaces
+# network.interfaces
 #
-
-include:
- - network.interfaces.base
-
-# Reload interface configuration if neccessary
-ifreload:
-  cmd.wait:
-    - name: /sbin/ifreload -a
-    - watch:
-      - file: /etc/network/interfaces
-    - require:
-      - file: /etc/network/ifupdown2/ifupdown2.conf
-
-
-# If there is an interface in vrf_external, install a workaround script
-# for a bug in ifupdown2 which will sometimes drop an IPv4 default route
-# present in the kernel and not reinstall it.
+# Generate and install /etc/network/interfaces file
 #
-# The fix script will be called every minute by cron and after ifreload
-# was called to try to minimize any downtime.
-{% set vrf = [False] %}
-{% for iface, iface_config in salt['pillar.get']('nodes:' ~ grains['id'] ~ ':ifaces', {}).items() %}
-  {% if iface_config.get ('vrf', '') == 'vrf_external' %}
-    {% do vrf.append(True) %}
-    {% break %}
-  {% endif %}
-{% endfor %}
-
-/usr/local/sbin/ff_fix_default_route:
-{% if True in vrf %}
-  file.managed:
-    - source: salt://network/interfaces/ff_fix_default_route
-    - mode: 755
-  cmd.wait:
-    - require:
-      - cmd: ifreload
-      - file: /usr/local/sbin/ff_fix_default_route
-    - watch:
-      - file: /etc/network/interfaces
-{% else %}
-  file.absent
-{% endif %}
 
-/etc/cron.d/ff_fix_default_route:
-{% if True in vrf %}
-  file.managed:
-    - source: salt://network/interfaces/ff_fix_default_route.cron
+/etc/network/interfaces:
+ file.managed:
     - template: jinja
-{% else %}
-  file.absent
-{% endif %}
+    - source: salt://network/interfaces/interfaces.tmpl

+ 1 - 1
openvpn/init.sls

@@ -4,7 +4,7 @@
 
 include:
   - certs
-  - network.interfaces
+  - network
 
 
 openvpn:

+ 1 - 1
snmpd/init.sls

@@ -3,7 +3,7 @@
 #
 
 include:
-  - network.interfaces
+  - network
 
 #
 # Install and start SNMPd