Created
January 24, 2012 14:10
-
-
Save phrawzty/1670357 to your computer and use it in GitHub Desktop.
APT hooks for Puppet
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Shamelessly based on https://gist.github.com/844735 | |
define apt::key ( | |
$keyserv, | |
$ensure = present | |
) { | |
$grep_for_key = "apt-key finger | grep fingerprint | awk '{print \$10 \$11 \$12 \$13}' | grep '${name}'" | |
case $ensure { | |
present: { | |
exec { "Import ${name} to apt keystore": | |
path => '/bin:/usr/bin', | |
environment => 'HOME=/root', | |
command => "gpg --keyserver ${keyserv} --recv-keys ${name} && gpg --export --armor ${name} | apt-key add -", | |
user => 'root', | |
group => 'root', | |
unless => "${grep_for_key}", | |
logoutput => on_failure, | |
} | |
} | |
absent: { | |
exec { "Remove ${name} from apt keystore": | |
path => '/bin:/usr/bin', | |
environment => 'HOME=/root', | |
command => "apt-key del ${name}", | |
user => 'root', | |
group => 'root', | |
onlyif => "${grep_for_key}", | |
} | |
} | |
default: { | |
fail "Invalid 'ensure' value '${ensure}' for apt::key." | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Shamelessly adapted from https://gist.github.com/844735 | |
define apt::ppa ( | |
$url, | |
$dist, | |
$type = 'deb', | |
$comp = 'main', | |
$key = false, | |
$keyserv = 'keyserver.ubuntu.com', | |
$ensure = present | |
) { | |
$basedir = '/etc/apt/sources.list.d' | |
$file = "${basedir}/${name}.list" | |
file { $file: | |
owner => 'root', | |
group => 'root', | |
mode => '0644' | |
} | |
case $ensure { | |
present: { | |
if ( $key ) { | |
apt::key { $key: keyserv => $keyserv } | |
File[$file] { | |
content => "${type} ${url} ${dist} ${comp}", | |
require => Apt::Key[$key] | |
} | |
} else { | |
File[$file] { content => "${type} ${url} ${dist} ${comp}" } | |
} | |
apt::update { $name: require => File[$file] } | |
} | |
absent: { | |
File[$file] { ensure => absent } | |
apt::update { $name: require => File[$file] } | |
} | |
default: { | |
fail "Invalid 'ensure' value '${ensure}' for apt::ppa." | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
define apt::update { | |
exec { "apt_update-${name}": | |
command => '/usr/bin/apt-get update' | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage example: