apt: Add settings, keys and ppas.

* Allow any configuration of apt to be done through data bindings by
  passing in hashes representing the resources.
* Switch apt::ppa to use `distid` as set in `apt::params. This makes
  `apt::ppa` also work for LinuxMint.
This commit is contained in:
Daniele Sluijters 2015-02-28 17:04:47 +01:00
parent fe228435b1
commit 95ae9ab48f
4 changed files with 85 additions and 10 deletions

View file

@ -1,12 +1,14 @@
# #
class apt( class apt(
$update = {}, $update = {},
$purge = {}, $purge = {},
$proxy = {}, $proxy = {},
$sources = undef, $sources = {},
$keys = {},
$ppas = {},
$settings = {},
) inherits ::apt::params { ) inherits ::apt::params {
$frequency_options = ['always','daily','weekly','reluctantly'] $frequency_options = ['always','daily','weekly','reluctantly']
validate_hash($update) validate_hash($update)
if $update['frequency'] { if $update['frequency'] {
@ -60,6 +62,11 @@ class apt(
$_proxy = merge($apt::proxy_defaults, $proxy) $_proxy = merge($apt::proxy_defaults, $proxy)
validate_hash($sources)
validate_hash($keys)
validate_hash($settings)
validate_hash($ppas)
if $proxy['host'] { if $proxy['host'] {
apt::setting { 'conf-proxy': apt::setting { 'conf-proxy':
priority => '01', priority => '01',
@ -135,8 +142,19 @@ class apt(
} }
# manage sources if present # manage sources if present
if $sources != undef { if $sources {
validate_hash($sources)
create_resources('apt::source', $sources) create_resources('apt::source', $sources)
} }
# manage keys if present
if $keys {
create_resources('apt::key', $keys)
}
# manage ppas if present
if $ppas {
create_resources('apt::ppa', $ppas)
}
# manage settings if present
if $settings {
create_resources('apt::setting', $settings)
}
} }

View file

@ -10,8 +10,8 @@ define apt::ppa(
fail('lsbdistcodename fact not available: release parameter required') fail('lsbdistcodename fact not available: release parameter required')
} }
if $::operatingsystem != 'Ubuntu' { if $::apt::distid != 'ubuntu' {
fail('apt::ppa is currently supported on Ubuntu only.') fail('apt::ppa is currently supported on Ubuntu and LinuxMint only.')
} }
$filename_without_slashes = regsubst($name, '/', '-', 'G') $filename_without_slashes = regsubst($name, '/', '-', 'G')

View file

@ -171,6 +171,63 @@ describe 'apt' do
it { is_expected.to contain_file('/etc/apt/sources.list.d/puppetlabs.list').with_content(/^deb http:\/\/apt.puppetlabs.com precise main$/) } it { is_expected.to contain_file('/etc/apt/sources.list.d/puppetlabs.list').with_content(/^deb http:\/\/apt.puppetlabs.com precise main$/) }
end end
context 'with keys defined on valid osfamily' do
let :facts do
{ :osfamily => 'Debian',
:lsbdistcodename => 'precise',
:lsbdistid => 'Debian',
}
end
let(:params) { { :keys => {
'55BE302B' => {
'key_server' => 'subkeys.pgp.net',
},
'4BD6EC30' => {
'key_server' => 'pgp.mit.edu',
}
} } }
it { is_expected.to contain_apt__key('55BE302B').with({
:key_server => 'subkeys.pgp.net',
})}
it { is_expected.to contain_apt__key('4BD6EC30').with({
:key_server => 'pgp.mit.edu',
})}
end
context 'with ppas defined on valid osfamily' do
let :facts do
{ :osfamily => 'Debian',
:lsbdistcodename => 'precise',
:lsbdistid => 'ubuntu',
}
end
let(:params) { { :ppas => {
'ppa:drizzle-developers/ppa' => {},
'ppa:nginx/stable' => {},
} } }
it { is_expected.to contain_apt__ppa('ppa:drizzle-developers/ppa')}
it { is_expected.to contain_apt__ppa('ppa:nginx/stable')}
end
context 'with settings defined on valid osfamily' do
let :facts do
{ :osfamily => 'Debian',
:lsbdistcodename => 'precise',
:lsbdistid => 'Debian',
}
end
let(:params) { { :settings => {
'conf-banana' => { 'content' => 'banana' },
'pref-banana' => { 'content' => 'banana' },
} } }
it { is_expected.to contain_apt__setting('conf-banana')}
it { is_expected.to contain_apt__setting('pref-banana')}
end
describe 'failing tests' do describe 'failing tests' do
context "purge['sources.list']=>'banana'" do context "purge['sources.list']=>'banana'" do
let(:params) { { :purge => { 'sources.list' => 'banana' }, } } let(:params) { { :purge => { 'sources.list' => 'banana' }, } }

View file

@ -214,7 +214,7 @@ describe 'apt::ppa' do
it do it do
expect { expect {
is_expected.to compile is_expected.to compile
}.to raise_error(Puppet::Error, /apt::ppa is currently supported on Ubuntu only./) }.to raise_error(Puppet::Error, /supported on Ubuntu and LinuxMint only/)
end end
end end
end end