2012-02-24 19:10:03 +01:00
|
|
|
define apt::key (
|
|
|
|
$key = $title,
|
|
|
|
$ensure = present,
|
|
|
|
$key_content = false,
|
|
|
|
$key_source = false,
|
2012-10-11 08:37:15 +02:00
|
|
|
$key_server = 'keyserver.ubuntu.com',
|
|
|
|
$key_options = false
|
2012-02-24 19:10:03 +01:00
|
|
|
) {
|
|
|
|
|
|
|
|
include apt::params
|
|
|
|
|
2012-03-14 23:36:33 +01:00
|
|
|
$upkey = upcase($key)
|
2013-06-29 13:06:26 +02:00
|
|
|
# trim the key to the last 8 chars so we can match longer keys with apt-key list too
|
|
|
|
$trimmedkey = regsubst($upkey, '^.*(.{8})$', '\1')
|
2012-03-14 23:36:33 +01:00
|
|
|
|
2012-02-24 19:10:03 +01:00
|
|
|
if $key_content {
|
2012-03-21 14:20:13 +01:00
|
|
|
$method = 'content'
|
2012-02-24 19:10:03 +01:00
|
|
|
} elsif $key_source {
|
2012-03-21 14:20:13 +01:00
|
|
|
$method = 'source'
|
2012-02-24 19:10:03 +01:00
|
|
|
} elsif $key_server {
|
2012-03-21 14:20:13 +01:00
|
|
|
$method = 'server'
|
2012-02-24 19:10:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
# This is a hash of the parts of the key definition that we care about.
|
|
|
|
# It is used as a unique identifier for this instance of apt::key. It gets
|
|
|
|
# hashed to ensure that the resource name doesn't end up being pages and
|
|
|
|
# pages (e.g. in the situation where key_content is specified).
|
2012-03-14 23:36:33 +01:00
|
|
|
$digest = sha1("${upkey}/${key_content}/${key_source}/${key_server}/")
|
2012-02-24 19:10:03 +01:00
|
|
|
|
|
|
|
# Allow multiple ensure => present for the same key to account for many
|
|
|
|
# apt::source resources that all reference the same key.
|
|
|
|
case $ensure {
|
|
|
|
present: {
|
2012-03-07 22:49:12 +01:00
|
|
|
|
2012-05-08 19:47:43 +02:00
|
|
|
anchor { "apt::key/${title}": }
|
2012-03-07 22:49:12 +01:00
|
|
|
|
2012-03-21 14:35:48 +01:00
|
|
|
if defined(Exec["apt::key ${upkey} absent"]) {
|
|
|
|
fail("Cannot ensure Apt::Key[${upkey}] present; ${upkey} already ensured absent")
|
2012-02-24 19:10:03 +01:00
|
|
|
}
|
2012-03-07 22:49:12 +01:00
|
|
|
|
2012-03-21 14:35:48 +01:00
|
|
|
if !defined(Anchor["apt::key ${upkey} present"]) {
|
2012-05-08 19:47:43 +02:00
|
|
|
anchor { "apt::key ${upkey} present": }
|
2012-03-07 22:49:12 +01:00
|
|
|
}
|
|
|
|
|
2012-10-11 08:37:15 +02:00
|
|
|
if $key_options{
|
|
|
|
$options_string = "--keyserver-options ${key_options}"
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
$options_string = ''
|
|
|
|
}
|
|
|
|
|
2012-02-24 19:10:03 +01:00
|
|
|
if !defined(Exec[$digest]) {
|
2012-03-21 14:35:48 +01:00
|
|
|
$digest_command = $method ? {
|
|
|
|
'content' => "echo '${key_content}' | /usr/bin/apt-key add -",
|
|
|
|
'source' => "wget -q '${key_source}' -O- | apt-key add -",
|
2012-10-11 08:37:15 +02:00
|
|
|
'server' => "apt-key adv --keyserver '${key_server}' ${options_string} --recv-keys '${upkey}'",
|
2012-03-21 14:35:48 +01:00
|
|
|
}
|
2012-02-24 19:10:03 +01:00
|
|
|
exec { $digest:
|
2012-06-07 23:53:41 +02:00
|
|
|
command => $digest_command,
|
|
|
|
path => '/bin:/usr/bin',
|
2013-06-29 13:06:26 +02:00
|
|
|
unless => "/usr/bin/apt-key list | /bin/grep '${trimmedkey}'",
|
2012-06-07 23:53:41 +02:00
|
|
|
logoutput => 'on_failure',
|
|
|
|
before => Anchor["apt::key ${upkey} present"],
|
2012-02-24 19:10:03 +01:00
|
|
|
}
|
|
|
|
}
|
2012-03-07 22:49:12 +01:00
|
|
|
|
2012-08-21 22:55:24 +02:00
|
|
|
Anchor["apt::key ${upkey} present"] -> Anchor["apt::key/${title}"]
|
2012-03-07 22:49:12 +01:00
|
|
|
|
2012-02-24 19:10:03 +01:00
|
|
|
}
|
|
|
|
absent: {
|
2012-03-07 22:49:12 +01:00
|
|
|
|
2012-03-21 14:35:48 +01:00
|
|
|
if defined(Anchor["apt::key ${upkey} present"]) {
|
|
|
|
fail("Cannot ensure Apt::Key[${upkey}] absent; ${upkey} already ensured present")
|
2012-02-24 19:10:03 +01:00
|
|
|
}
|
2012-03-07 22:49:12 +01:00
|
|
|
|
2012-03-21 14:35:48 +01:00
|
|
|
exec { "apt::key ${upkey} absent":
|
2012-06-07 23:53:41 +02:00
|
|
|
command => "apt-key del '${upkey}'",
|
|
|
|
path => '/bin:/usr/bin',
|
2013-06-29 13:06:26 +02:00
|
|
|
onlyif => "apt-key list | grep '${trimmedkey}'",
|
2012-06-07 23:53:41 +02:00
|
|
|
user => 'root',
|
|
|
|
group => 'root',
|
|
|
|
logoutput => 'on_failure',
|
2012-02-24 19:10:03 +01:00
|
|
|
}
|
|
|
|
}
|
2012-03-07 22:49:12 +01:00
|
|
|
|
2012-02-24 19:10:03 +01:00
|
|
|
default: {
|
2012-03-21 14:20:13 +01:00
|
|
|
fail "Invalid 'ensure' value '${ensure}' for aptkey"
|
2012-02-24 19:10:03 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|