Skip to content

Commit

Permalink
Add apt's preferences mgmt
Browse files Browse the repository at this point in the history
Ignore .kitchen dir

Add defaults for preferences mgmt

Add some pillar examples for preferences mgmt

Add tests for preferences

Add entries in the README file

Missing map.jinja entry
  • Loading branch information
javierbertoli committed May 2, 2016
1 parent 988c59f commit 6f7022f
Show file tree
Hide file tree
Showing 9 changed files with 152 additions and 33 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
*.swp
.kitchen
35 changes: 14 additions & 21 deletions .kitchen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,15 @@ platforms:
provisioner:
name: salt_solo
salt_version: 2015.8.8
data_path: test/shared
is_file_root: true
pillars-from-files:
apt.sls: pillar.example
pillars:
top.sls:
base:
'*':
- apt
grains:
os_family: Debian

Expand All @@ -22,24 +30,9 @@ suites:
'*':
- apt.repositories
- apt.update
pillars:
top.sls:
base:
'*':
- apt
apt.sls:
apt:
remove_sources_list: true
clean_sources_list_d: true
repositories:
debian-jessie:
distro: jessie
url: http://httpredir.debian.org/debian
type: [source]
comps: [main, contrib, non-free]
dropbox:
distro: jessie
url: http://linux.dropbox.com/debian
arch: [i386, amd64]
keyid: 1C61A2656FB57B7E4DE0F4C1FC918B335044912E
keyserver: pgp.mit.edu
- name: preferences
provisioner:
state_top:
base:
'*':
- apt.preferences
14 changes: 12 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Runs ``apt-get update``.
Runs ``apt-get upgrade``.

``apt.repositories``
---------------
--------------------

Allows you to configure and manage repositories from pillar. Check ``pillar.example``
to see possible values. If used and no repositories are provided, sane default
Expand All @@ -39,8 +39,18 @@ values from ``map.jinja`` are used.
Check https://wiki.debian.org/SourcesList for an explanation about the resulting
files structure.

``apt.preferences``
-------------------

Allows you to configure and manage apt's preferences from pillar. Check
``pillar.example`` to see possible values. If used and no repositories are
provided, sane default values from ``map.jinja`` are used.

Check https://wiki.debian.org/AptPreferences?action=show&redirect=preferences
and ``man 5 apt_preferences`` for an explanation about the resulting files structure.

``apt.ppa``
-------------
-----------
Installs ``python-software-properties``
(``$ /usr/bin/apt-add-repository ppa:user/repository``).

Expand Down
4 changes: 4 additions & 0 deletions apt/map.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
'sources_list_dir': '/etc/apt/sources.list.d',
'remove_sources_list': false,
'clean_sources_list_d': false,
'preferences_dir': '/etc/apt/preferences.d',
'remove_preferences': false,
'clean_preferences_d': false,
'default_keyserver': 'pool.sks-keyservers.net',
'default_url': 'http://httpredir.debian.org/debian/',
'repositories': {
'sane_default': {
Expand Down
38 changes: 38 additions & 0 deletions apt/preferences.sls
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{% from "apt/map.jinja" import apt as apt_map with context %}
{% set apt = pillar.get('apt', {}) %}
{% set remove_preferences = apt.get('remove_preferences', apt_map.remove_preferences) %}
{% set clean_preferences_d = apt.get('clean_preferences_d', apt_map.clean_preferences_d) %}
{% set preferences_dir = apt.get('preferences_dir', apt_map.preferences_dir) %}
{% set preferences = apt.get('preferences', apt_map.preferences) %}
{% set default_url = apt.get('default_url', apt_map.default_url) %}
/etc/apt/preferences:
{% if remove_preferences %}
file.absent
{% else %}
file.managed:
- mode: '0644'
- user: root
- group: root
{% endif %}
{{ preferences_dir }}:
file.directory:
- mode: '0755'
- user: root
- group: root
- clean: {{ clean_preferences_d }}
{% for pref_file, args in preferences.iteritems() %}
{%- set p_package = args.package if args.package is defined else '*' %}
{{ preferences_dir }}/{{ pref_file }}:
file.managed:
- mode: '0644'
- user: root
- group: root
- contents:
- "{{ 'Package: ' ~ p_package }}"
- "{{ 'Pin: ' ~ args.pin }}"
- "{{ 'Pin-Priority: ' ~ args.priority }}"
{% endfor %}
43 changes: 34 additions & 9 deletions pillar.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ apt:
remove_sources_list: true
clean_sources_list_d: true

remove_preferences: true
clean_preferences_d: true

unattended:
allowed_origins:
- origin1
Expand Down Expand Up @@ -35,13 +38,35 @@ apt:
distro: stable-updates
url: http://httpredir.debian.org/debian/
comps: [main, contrib, non-free]
my-fancy-repo:
distro: whatever/is/needed/here
url: http://my.repo.url
raspbian:
distro: wheezy
url: http://archive.raspbian.org/raspbian
type: [source]
key_url: https://archive.raspbian.org/raspbian.public.key
debian-jessie:
distro: jessie
url: http://httpredir.debian.org/debian
type: [source]
key_url: http://my.repo.url/GPG-KEY-my.repo
perconap-repo:
distro: stable
url: http://repo.percona.com/apt
keyid: CD2EFD2A
keyserver: pool.sks-keyservers.net
comps: [main, contrib, non-free]
dropbox:
distro: jessie
url: http://linux.dropbox.com/debian
arch: [i386, amd64]
keyid: 1C61A2656FB57B7E4DE0F4C1FC918B335044912E
keyserver: pgp.mit.edu

preferences:
00-rspamd:
package: rspamd
pin: origin rspamd.com
priority: 650
01-all:
pin: release stable
priority: 610
02-all:
pin: release testing
priority: 600
03-all:
pin: release unstable
priority: 50

48 changes: 48 additions & 0 deletions test/integration/preferences/serverspec/preferences_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
require_relative '../../../kitchen/data/spec_helper'

describe 'apt.preferences' do

describe file('/etc/apt/preferences') do
it { should_not exist }
end

describe file('/etc/apt/preferences.d') do
it { should be_directory }
it { should be_mode 755 }
it { should be_owned_by 'root' }
it { should be_grouped_into 'root' }
end

describe file('/etc/apt/preferences.d/00-rspamd') do
it { should exist }
it { should be_mode 644 }
it { should be_owned_by 'root' }
it { should be_grouped_into 'root' }
its(:content) { should match("Package: rspamd\nPin: origin rspamd.com\nPin-Priority: 650\n") }
end

describe file('/etc/apt/preferences.d/01-all') do
it { should exist }
it { should be_mode 644 }
it { should be_owned_by 'root' }
it { should be_grouped_into 'root' }
its(:content) { should match("Package: *\nPin: release stable\nPin-Priority: 610\n") }
end

describe file('/etc/apt/preferences.d/02-all') do
it { should exist }
it { should be_mode 644 }
it { should be_owned_by 'root' }
it { should be_grouped_into 'root' }
its(:content) { should match("Package: *\nPin: release testing\nPin-Priority: 600\n") }
end

describe file('/etc/apt/preferences.d/03-all') do
it { should exist }
it { should be_mode 644 }
it { should be_owned_by 'root' }
it { should be_grouped_into 'root' }
its(:content) { should match("Package: *\nPin: release unstable\nPin-Priority: 50\n") }
end

end
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require 'spec_helper'
require_relative '../../../kitchen/data/spec_helper'

describe 'apt.repositories' do

Expand Down
File renamed without changes.

0 comments on commit 6f7022f

Please sign in to comment.