Add concat and remove for interfaces.d
Change-Id: Ia97c5a79c5298f24aca6ca9148ce48546f3bcb70
diff --git a/README.rst b/README.rst
index 0b4e3dc..31c4701 100644
--- a/README.rst
+++ b/README.rst
@@ -847,6 +847,25 @@
use_interfaces:
- eth1
+Concatinating and removing interface files
+
+Debian based distributions have `/etc/network/interfaces.d/` directory, where
+you can store configuration of network interfaces in separate files. You can
+concatinate the files to the defined destination when needed, this operation
+removes the file from the `/etc/network/interfaces.d/`. If you just need to
+remove iface files, you can use the `remove_iface_files` key.
+
+.. code-block:: yaml
+
+ linux:
+ network:
+ concat_iface_files:
+ - src: '/etc/network/interfaces.d/50-cloud-init.cfg'
+ dst: '/etc/network/interfaces'
+ remove_iface_files:
+ - '/etc/network/interfaces.d/90-custom.cfg'
+
+
DHCP client configuration
None of the keys is mandatory, include only those you really need. For full list
diff --git a/linux/network/interface.sls b/linux/network/interface.sls
index b8363bc..e0bc67f 100644
--- a/linux/network/interface.sls
+++ b/linux/network/interface.sls
@@ -20,6 +20,32 @@
{%- endif %}
+{%- for f in network.get('concat_iface_files', []) %}
+
+{%- if salt['file.file_exists'](f.src) %}
+
+append_{{ f.src }}_{{ f.dst }}:
+ file.append:
+ - name: {{ f.dst }}
+ - source: {{ f.src }}
+
+remove_appended_{{ f.src }}:
+ file.absent:
+ - name: {{ f.src }}
+
+{%- endif %}
+
+{%- endfor %}
+
+{%- for f in network.get('remove_iface_files', []) %}
+
+remove_iface_file_{{ f }}:
+ file.absent:
+ - name: {{ f }}
+
+{%- endfor %}
+
+
{%- for interface_name, interface in network.interface.iteritems() %}
{%- set interface_name = interface.get('name', interface_name) %}