diff --git a/apt/conf.sls b/apt/conf.sls new file mode 100644 index 0000000..755f72b --- /dev/null +++ b/apt/conf.sls @@ -0,0 +1,23 @@ +{% from "apt/map.jinja" import apt as apt_map with context %} +{% set confd_dir = salt['pillar.get']('apt:confd_dir', apt_map.confd_dir) %} +{% set clean_conf_d = salt['pillar.get']('apt:clean_conf_d', apt_map.clean_conf_d) %} +{% set apt_conf = salt['pillar.get']('apt:conf', apt_map.conf) %} + +{{ confd_dir }}: + file.directory: + - mode: '0755' + - user: root + - group: root + - clean: {{ clean_conf_d }} + +{% for file, contents in apt_conf|dictsort %} +{{ confd_dir }}/{{ file }}: + file.managed: + - source: salt://apt/templates/conf.jinja + - template: jinja + - user: root + - group: root + - mode: 644 + - context: + data: {{ contents }} +{% endfor %} diff --git a/apt/map.jinja b/apt/map.jinja index d962626..48d1cd7 100644 --- a/apt/map.jinja +++ b/apt/map.jinja @@ -14,6 +14,7 @@ 'preferences': {}, 'remove_preferences': false, 'clean_preferences_d': false, + 'clean_conf_d': false, 'default_keyserver': 'pool.sks-keyservers.net', 'default_url': 'http://deb.debian.org/debian/', 'default_keyring_package': 'debian-archive-keyring', diff --git a/apt/templates/conf.jinja b/apt/templates/conf.jinja new file mode 100644 index 0000000..3307987 --- /dev/null +++ b/apt/templates/conf.jinja @@ -0,0 +1,30 @@ +{%- macro print(mname, mvalue) %} + {%- if mvalue is string %} + {{ mname }} "{{ mvalue }}"; + {%- elif mvalue is sequence %} + {{ mname }} { + {%- for item in mvalue %} + "{{ item }}"; + {%- endfor %} + }; + {%- endif %} +{%- endmacro -%} +// This file is managed by salt +{%- for opt, opt_data in data|dictsort -%} + {%- if opt_data is string %} +{{ opt }} "{{ opt_data }}"; + {%- elif opt_data is mapping %} +{{ opt }} +{ + {%- for name, value in opt_data|dictsort %} + {{- print(name, value) }} + {%- endfor %} +}; + {%- elif opt_data is sequence %} +{{ opt }} { + {%- for item in opt_data %} + "{{ item }}"; + {%- endfor %} +}; + {%- endif %} +{%- endfor -%} diff --git a/pillar.example b/pillar.example index 561e84d..e1eb7b4 100644 --- a/pillar.example +++ b/pillar.example @@ -8,6 +8,28 @@ apt: remove_preferences: true clean_preferences_d: true + conf: + 30release: + 'APT::Default-Release': stable + '40dpkg-options': + 'Dpkg::Options': + - '--force-confdef' + - '--force-confold' + 60proxy: + 'Acquire::ftp': + Proxy: "ftp://127.0.0.1/" + 'Proxy::http.us.debian.org': DIRECT + ProxyLogin: + - "USER $(PROXY_USER)" + - "PASS $(PROXY_PASS)" + - "USER $(SITE_USER)@$(SITE):$(SITE_PORT)" + - "PASS $(SITE_PASS)" + DSelect: + Clean: auto + Options: -f + UpdateOptions: "" + PromptAfterUpdate: "no" + unattended: allowed_origins: - origin1