Skip to content

Instantly share code, notes, and snippets.

@jessepeterson
Last active December 19, 2015 02:28
Show Gist options
  • Save jessepeterson/5882901 to your computer and use it in GitHub Desktop.
Save jessepeterson/5882901 to your computer and use it in GitHub Desktop.
Puppet definition to download a tarball of a Github repo and extract it to a filesystem location.
# example:
#
# github_dlextract { "mxcl/homebrew",
# path => "/my/path/directory",
# rev => "b8c7e203d1", # optional
# }
define github_dlextract ($repo = $title, $path, $rev = 'master') {
file { $path:
ensure => directory,
}
$reporepl = regsubst($repo, '\/', '-')
$inst_marker_file = "/var/db/.puppet_github_${reporepl}_${rev}"
exec { "github_dlextract-${repo}":
command => "curl -kL https://github.com/${repo}/tarball/${rev} | tar xzf - && cp -pR ${reporepl}-*/ ${path} && rm -rf /tmp/${reporepl}-*",
cwd => "/tmp",
path => ["/bin", "/sbin", "/usr/bin", "/usr/sbin"],
refreshonly => $rev ? {
'master' => false,
default => true},
subscribe => File[$inst_marker_file],
require => File[$path],
}
if $rev == 'master' {
exec { "github_dlextract-delmarker-${repo}":
command => "rm -f /var/db/.puppet_github_${reporepl}_*",
path => ["/bin", "/sbin", "/usr/bin", "/usr/sbin"],
onlyif => "ls /var/db/.puppet_github_${reporepl}_*"
}
}
file { $inst_marker_file:
ensure => $rev ? {
'master' => absent,
default => present},
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment