2012-02-24 19:10:03 +01:00
|
|
|
define apt::key (
|
|
|
|
$key = $title,
|
|
|
|
$ensure = present,
|
|
|
|
$key_content = false,
|
|
|
|
$key_source = false,
|
2012-03-21 14:20:13 +01:00
|
|
|
$key_server = 'keyserver.ubuntu.com'
|
2012-02-24 19:10:03 +01:00
|
|
|
) {
|
|
|
|
|
|
|
|
include apt::params
|
|
|
|
|
2012-03-14 23:36:33 +01:00
|
|
|
$upkey = upcase($key)
|
|
|
|
|
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-03-21 14:20:13 +01: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"]) {
|
|
|
|
anchor { "apt::key ${upkey} present":; }
|
2012-03-07 22:49:12 +01:00
|
|
|
}
|
|
|
|
|
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 -",
|
|
|
|
'server' => "apt-key adv --keyserver '${key_server}' --recv-keys '${upkey}'",
|
|
|
|
}
|
2012-02-24 19:10:03 +01:00
|
|
|
exec { $digest:
|
2012-03-21 14:20:13 +01:00
|
|
|
path => '/bin:/usr/bin',
|
2012-03-14 23:36:33 +01:00
|
|
|
unless => "/usr/bin/apt-key list | /bin/grep '${upkey}'",
|
2012-03-21 14:20:13 +01:00
|
|
|
before => Anchor["apt::key ${upkey} present"],
|
2012-03-21 14:35:48 +01:00
|
|
|
command => $digest_command,
|
2012-02-24 19:10:03 +01:00
|
|
|
}
|
|
|
|
}
|
2012-03-07 22:49:12 +01:00
|
|
|
|
2012-03-14 23:36:33 +01: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-03-21 14:20:13 +01:00
|
|
|
path => '/bin:/usr/bin',
|
|
|
|
onlyif => "apt-key list | grep '${upkey}'",
|
|
|
|
command => "apt-key del '${upkey}'",
|
|
|
|
user => 'root',
|
|
|
|
group => 'root',
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|