Add linux.system.apt state
Change-Id: I1e190f1f5b34a049335efbecffad3dddf7c41644
diff --git a/README.rst b/README.rst
index 1cbc18c..cafb41c 100644
--- a/README.rst
+++ b/README.rst
@@ -626,6 +626,21 @@
system:
purge_repos: true
+Setup custom apt config options:
+
+.. code-block:: yaml
+
+ linux:
+ system:
+ apt:
+ config:
+ compression-workaround:
+ "Acquire::CompressionTypes::Order": "gz"
+ docker-clean:
+ "DPkg::Post-Invoke":
+ - "rm -f /var/cache/apt/archives/*.deb /var/cache/apt/archives/partial/*.deb /var/cache/apt/*.bin || true"
+ "APT::Update::Post-Invoke":
+ - "rm -f /var/cache/apt/archives/*.deb /var/cache/apt/archives/partial/*.deb /var/cache/apt/*.bin || true"
RC
~~
diff --git a/linux/files/apt.conf b/linux/files/apt.conf
new file mode 100644
index 0000000..709fbd6
--- /dev/null
+++ b/linux/files/apt.conf
@@ -0,0 +1,9 @@
+// apt.conf file managed by salt-minion
+// DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
+
+{%- for key, value in config.iteritems() %}
+{{ key }} {% if value is iterable and value is not string %}{ {% for entry in value %}"{{ entry }}";{% endfor %} } {% else %}{{ value }};{% endif %}
+{%- endfor %}
+{#-
+vim: syntax=jinja
+-#}
diff --git a/linux/system/apt.sls b/linux/system/apt.sls
new file mode 100644
index 0000000..938bc8b
--- /dev/null
+++ b/linux/system/apt.sls
@@ -0,0 +1,27 @@
+{%- from "linux/map.jinja" import system with context %}
+{%- if system.enabled %}
+{%- if grains.os_family == 'Debian' %}
+
+{%- if system.repo|length > 0 %}
+include:
+- linux.system.repo
+{%- endif %}
+
+{%- for key, config in system.apt.get('config', {}).iteritems() %}
+
+linux_apt_conf_{{ key }}
+ file.managed:
+ - name: /etc/apt/apt.conf.d/99{{ key }}-salt:
+ - template: jinja
+ - source: salt://linux/files/apt.conf
+ - defaults:
+ config: {{ config|yaml }}
+ {%- if system.repo|length > 0 %}
+ - require_in:
+ - pkg: linux_repo_prereq_pkgs
+ {%- endif %}
+
+{%- endfor %}
+
+{%- endif %}
+{%- endif %}
diff --git a/linux/system/init.sls b/linux/system/init.sls
index 4dc1a8c..e17adc5 100644
--- a/linux/system/init.sls
+++ b/linux/system/init.sls
@@ -99,3 +99,6 @@
{%- if system.directory is defined %}
- linux.system.directory
{%- endif %}
+{%- if system.apt is defined and grains.os_family == 'Debian' %}
+- linux.system.apt
+{%- endif %}