Skip to content

Commit

Permalink
Add initial support for apt conf management
Browse files Browse the repository at this point in the history
- Add template file
- Add pillar example
  • Loading branch information
devster31 authored and Adrien "ze" Urban committed Apr 11, 2018
1 parent 35cf2e0 commit 9850446
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 0 deletions.
23 changes: 23 additions & 0 deletions apt/conf.sls
Original file line number Diff line number Diff line change
@@ -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 %}
1 change: 1 addition & 0 deletions apt/map.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
30 changes: 30 additions & 0 deletions apt/templates/conf.jinja
Original file line number Diff line number Diff line change
@@ -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 -%}
22 changes: 22 additions & 0 deletions pillar.example
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 9850446

Please sign in to comment.