X-Git-Url: https://review.fuel-infra.org/gitweb?a=blobdiff_plain;f=manifests%2Fkey.pp;h=c78bf658ce984a538aad7552ca3dd98581b3f29c;hb=d0b8ed8f64e413b4d33eaa6b9ce06dd197f1e9b1;hp=e87968d7fbb504f3f6e8ca8a2e38b2e344ca8566;hpb=cd7a3efdf0d82d47efd711d39284fb690f1a4883;p=puppet-modules%2Fpuppetlabs-apt.git diff --git a/manifests/key.pp b/manifests/key.pp index e87968d..c78bf65 100644 --- a/manifests/key.pp +++ b/manifests/key.pp @@ -3,12 +3,15 @@ define apt::key ( $ensure = present, $key_content = false, $key_source = false, - $key_server = 'keyserver.ubuntu.com' + $key_server = 'keyserver.ubuntu.com', + $key_options = false ) { include apt::params $upkey = upcase($key) + # trim the key to the last 8 chars so we can match longer keys with apt-key list too + $trimmedkey = regsubst($upkey, '^.*(.{8})$', '\1') if $key_content { $method = 'content' @@ -29,31 +32,39 @@ define apt::key ( case $ensure { present: { - anchor { "apt::key/${title}":; } + anchor { "apt::key/${title}": } if defined(Exec["apt::key ${upkey} absent"]) { fail("Cannot ensure Apt::Key[${upkey}] present; ${upkey} already ensured absent") } if !defined(Anchor["apt::key ${upkey} present"]) { - anchor { "apt::key ${upkey} present":; } + anchor { "apt::key ${upkey} present": } + } + + if $key_options{ + $options_string = "--keyserver-options ${key_options}" + } + else{ + $options_string = '' } if !defined(Exec[$digest]) { $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}'", + 'server' => "apt-key adv --keyserver '${key_server}' ${options_string} --recv-keys '${upkey}'", } exec { $digest: - path => '/bin:/usr/bin', - unless => "/usr/bin/apt-key list | /bin/grep '${upkey}'", - before => Anchor["apt::key ${upkey} present"], - command => $digest_command, + command => $digest_command, + path => '/bin:/usr/bin', + unless => "/usr/bin/apt-key list | /bin/grep '${trimmedkey}'", + logoutput => 'on_failure', + before => Anchor["apt::key ${upkey} present"], } } - Anchor["apt::key $upkey present"] -> Anchor["apt::key/$title"] + Anchor["apt::key ${upkey} present"] -> Anchor["apt::key/${title}"] } absent: { @@ -63,11 +74,12 @@ define apt::key ( } exec { "apt::key ${upkey} absent": - path => '/bin:/usr/bin', - onlyif => "apt-key list | grep '${upkey}'", - command => "apt-key del '${upkey}'", - user => 'root', - group => 'root', + command => "apt-key del '${upkey}'", + path => '/bin:/usr/bin', + onlyif => "apt-key list | grep '${trimmedkey}'", + user => 'root', + group => 'root', + logoutput => 'on_failure', } }