2010-04-27 22:38:28 +02:00
|
|
|
# source.pp
|
|
|
|
# add an apt source
|
|
|
|
|
|
|
|
define apt::source(
|
2012-05-21 23:17:37 +02:00
|
|
|
$ensure = present,
|
|
|
|
$location = '',
|
|
|
|
$release = $lsbdistcodename,
|
|
|
|
$repos = 'main',
|
|
|
|
$include_src = true,
|
2011-05-30 19:24:06 +02:00
|
|
|
$required_packages = false,
|
2012-05-21 23:17:37 +02:00
|
|
|
$key = false,
|
|
|
|
$key_server = 'keyserver.ubuntu.com',
|
|
|
|
$key_content = false,
|
|
|
|
$key_source = false,
|
|
|
|
$pin = false
|
2010-04-27 22:38:28 +02:00
|
|
|
) {
|
|
|
|
|
2011-05-30 19:18:13 +02:00
|
|
|
include apt::params
|
2012-05-04 22:35:13 +02:00
|
|
|
include apt::update
|
2010-04-27 22:38:28 +02:00
|
|
|
|
2012-04-11 23:54:13 +02:00
|
|
|
$sources_list_d = $apt::params::sources_list_d
|
|
|
|
$provider = $apt::params::provider
|
|
|
|
|
Modify apt::source release parameter test
This commit modifies the release parameter test in apt::source to work
correctly within puppet-rspec for edge-case resource definitions. Previously,
the test for the $release parameter was written as
`if ! $release { fail() }`
This commit updates the test to be written as
`if $release == undef { fail() }`
Additionally, the tests for correct behavior in the presence or absence of a
$release parameter have been beefed up.
The reason for making this change relates to examples such as the following
resource definition:
apt::source { "jenkins":
location => "http://pkg.jenkins-ci.org/debian",
release => "",
repos => "binary/",
key => "D50582E6",
key_source => "http://pkg.jenkins-ci.org/debian/jenkins-ci.org.key",
include_src => false,
}
Note that the $release parameter is given as the empty string. In practice,
this is perfectly valid and everything will work great. However, it seems that
the empty string gets interpreted by something in puppet-rspec as something
equivalent to "False", and thus when testing, the above resource definition
would fail with "Puppet::Error: lsbdistcodename fact not available: release
parameter required" even though the $release parameter has been explicitely
specified (as the empty string).
See also: https://github.com/rtyler/puppet-jenkins/issues/9
2012-03-07 19:10:46 +01:00
|
|
|
if $release == undef {
|
2012-03-21 14:20:13 +01:00
|
|
|
fail('lsbdistcodename fact not available: release parameter required')
|
2012-02-24 23:03:51 +01:00
|
|
|
}
|
|
|
|
|
2011-05-30 19:24:06 +02:00
|
|
|
file { "${name}.list":
|
2012-05-04 01:59:13 +02:00
|
|
|
ensure => $ensure,
|
2012-04-12 02:49:30 +02:00
|
|
|
path => "${sources_list_d}/${name}.list",
|
2012-03-21 14:20:13 +01:00
|
|
|
owner => root,
|
|
|
|
group => root,
|
|
|
|
mode => '0644',
|
|
|
|
content => template("${module_name}/source.list.erb"),
|
2012-05-04 00:44:17 +02:00
|
|
|
notify => Exec['apt_update'],
|
2011-05-30 19:24:06 +02:00
|
|
|
}
|
|
|
|
|
2012-05-21 23:19:18 +02:00
|
|
|
|
2012-05-21 23:52:36 +02:00
|
|
|
if ($pin != false) {
|
2012-05-21 23:19:18 +02:00
|
|
|
# Get the host portion out of the url so we can pin to origin
|
|
|
|
$url_split = split($location, '/')
|
|
|
|
$host = $url_split[2]
|
|
|
|
|
|
|
|
apt::pin { $name:
|
2012-05-21 23:52:36 +02:00
|
|
|
ensure => $ensure,
|
2012-05-03 01:00:27 +02:00
|
|
|
priority => $pin,
|
2012-05-21 23:19:18 +02:00
|
|
|
before => File["${name}.list"],
|
|
|
|
origin => $host,
|
2012-05-03 01:00:27 +02:00
|
|
|
}
|
2011-05-30 19:24:06 +02:00
|
|
|
}
|
|
|
|
|
2012-05-04 01:59:13 +02:00
|
|
|
if ($required_packages != false) and ($ensure == 'present') {
|
2012-02-24 06:01:20 +01:00
|
|
|
exec { "Required packages: '${required_packages}' for ${name}":
|
2012-04-11 23:54:13 +02:00
|
|
|
command => "${provider} -y install ${required_packages}",
|
2012-02-24 06:01:20 +01:00
|
|
|
subscribe => File["${name}.list"],
|
2011-05-30 19:24:06 +02:00
|
|
|
refreshonly => true,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-04 01:59:13 +02:00
|
|
|
# We do not want to remove keys when the source is absent.
|
|
|
|
if ($key != false) and ($ensure == 'present') {
|
2012-02-24 19:10:03 +01:00
|
|
|
apt::key { "Add key: ${key} from Apt::Source ${title}":
|
|
|
|
ensure => present,
|
2012-03-21 14:20:13 +01:00
|
|
|
key => $key,
|
2012-02-24 19:10:03 +01:00
|
|
|
key_server => $key_server,
|
|
|
|
key_content => $key_content,
|
|
|
|
key_source => $key_source,
|
|
|
|
before => File["${name}.list"],
|
2011-05-30 19:24:06 +02:00
|
|
|
}
|
|
|
|
}
|
2012-05-08 00:27:53 +02:00
|
|
|
|
|
|
|
# Need anchor to provide containment for dependencies.
|
|
|
|
anchor { "apt::source::${name}":
|
|
|
|
require => Class['apt::update'],
|
|
|
|
}
|
2010-04-27 22:38:28 +02:00
|
|
|
}
|