2012-02-24 19:10:03 +01:00
|
|
|
define apt::key (
|
|
|
|
$key = $title,
|
|
|
|
$ensure = present,
|
|
|
|
$key_content = false,
|
|
|
|
$key_source = false,
|
|
|
|
$key_server = "keyserver.ubuntu.com"
|
|
|
|
) {
|
|
|
|
|
|
|
|
include apt::params
|
|
|
|
|
|
|
|
if $key_content {
|
|
|
|
$method = "content"
|
|
|
|
} elsif $key_source {
|
|
|
|
$method = "source"
|
|
|
|
} elsif $key_server {
|
|
|
|
$method = "server"
|
|
|
|
}
|
|
|
|
|
|
|
|
# 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).
|
|
|
|
$digest = sha1("${key}/${key_content}/${key_source}/${key_server}/")
|
|
|
|
|
|
|
|
# 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
|
|
|
|
|
|
|
anchor { "apt::key/$title":; }
|
|
|
|
|
2012-02-24 19:10:03 +01:00
|
|
|
if defined(Exec["apt::key $key absent"]) {
|
|
|
|
fail ("Cannot ensure Apt::Key[$key] present; $key already ensured absent")
|
|
|
|
}
|
2012-03-07 22:49:12 +01:00
|
|
|
|
|
|
|
if !defined(Anchor["apt::key $key present"]) {
|
|
|
|
anchor { "apt::key $key present":; }
|
|
|
|
}
|
|
|
|
|
2012-02-24 19:10:03 +01:00
|
|
|
if !defined(Exec[$digest]) {
|
|
|
|
exec { $digest:
|
|
|
|
path => "/bin:/usr/bin",
|
|
|
|
unless => "/usr/bin/apt-key list | /bin/grep '${key}'",
|
2012-03-07 22:49:12 +01:00
|
|
|
before => Anchor["apt::key $key present"],
|
2012-02-24 19:10:03 +01:00
|
|
|
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 '${key}'",
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
2012-03-07 22:49:12 +01:00
|
|
|
|
|
|
|
Anchor["apt::key $key present"] -> Anchor["apt::key/$title"]
|
|
|
|
|
2012-02-24 19:10:03 +01:00
|
|
|
}
|
|
|
|
absent: {
|
2012-03-07 22:49:12 +01:00
|
|
|
|
|
|
|
if defined(Anchor["apt::key $key present"]) {
|
2012-02-24 19:10:03 +01:00
|
|
|
fail ("Cannot ensure Apt::Key[$key] absent; $key already ensured present")
|
|
|
|
}
|
2012-03-07 22:49:12 +01:00
|
|
|
|
2012-02-24 19:10:03 +01:00
|
|
|
exec { "apt::key $key absent":
|
|
|
|
path => "/bin:/usr/bin",
|
|
|
|
onlyif => "apt-key list | grep '$key'",
|
|
|
|
command => "apt-key del '$key'",
|
|
|
|
user => "root",
|
|
|
|
group => "root",
|
|
|
|
}
|
|
|
|
}
|
2012-03-07 22:49:12 +01:00
|
|
|
|
2012-02-24 19:10:03 +01:00
|
|
|
default: {
|
|
|
|
fail "Invalid 'ensure' value '$ensure' for aptkey"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|