Created
February 25, 2011 23:48
-
-
Save blueyed/844735 to your computer and use it in GitHub Desktop.
This defines pparepo which allows to add a PPA (Personal Package Archive) repository from Launchpad to a client. It uses apt::key, which I have taken (and maybe modified) from http://projects.puppetlabs.com/projects/1/wiki/Apt_Keys_Patterns (blog post at
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
# Setup a PPA repo, where the name is "user/ppaname", e.g. "blueyed/ppa" ("ppa" being the default) | |
define pparepo($apt_key = "", $dist = $ppa_default_name, $supported = ["lucid", "hardy"], $ensure = present, $keyserver = "keyserver.ubuntu.com") { | |
$name_for_file = regsubst($name, '/', '-', 'G') | |
$file = "/etc/apt/sources.list.d/pparepo-${name_for_file}.list" | |
file { "$file": } | |
case $ensure { | |
present: { | |
if ($dist) and ($dist in $supported) { | |
File["$file"] { | |
content => "deb http://ppa.launchpad.net/$name/ubuntu $dist main\n" | |
} | |
File["$file"] { ensure => file } | |
if ( $apt_key ) { | |
apt::key { "$apt_key": } | |
} | |
} else { | |
File["$file"] { ensure => false } | |
} | |
} | |
absent: { | |
File["$file"] { ensure => false } | |
} | |
default: { | |
fail "Invalid 'ensure' value '$ensure' for pparepo" | |
} | |
} | |
} | |
# source http://projects.puppetlabs.com/projects/1/wiki/Apt_Keys_Patterns | |
define apt::key($ensure = present, $keyserver = "keyserver.ubuntu.com") { | |
$grep_for_key = "apt-key list | grep '^pub' | sed -r 's.^pub\\s+\\w+/..' | grep '^$name'" | |
case $ensure { | |
present: { | |
exec { "Import $name to apt keystore": | |
path => "/bin:/usr/bin", | |
environment => "HOME=/root", | |
command => "gpg --keyserver $keyserver --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" | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment