Skip to content

Instantly share code, notes, and snippets.

@pheisiph
Last active April 26, 2016 13:26
Show Gist options
  • Save pheisiph/5656614 to your computer and use it in GitHub Desktop.
Save pheisiph/5656614 to your computer and use it in GitHub Desktop.
Puppet Bootstrapping with capistrano
#config/recipes/bootstrap.rb
#capistrano recipe
namespace :bootstrap do
desc "Prepare the system to run Puppet. Requires root access (once)."
task :default do
set :user, 'root' # because we haven't provisioned any users yet
# install puppet standalone
run "wget http://apt.puppetlabs.com/puppetlabs-release-#{config['os_code_name']}.deb"
run "dpkg -i puppetlabs-release-#{config['os_code_name']}.deb"
run "apt-get -y update"
run "apt-get -y install puppet-common"
run "rm puppetlabs-release-#{config['os_code_name']}.deb"
# We need this fix on some systems in order to get build-essential
# to be install correctly. If that fails, uncomment this.
# `dpkg -l libc6 libc6-dev`
# `apt-cache madison libc6 libc6-dev`
# should provide hints as to which versions need to be installed.
# run 'apt-get -y install --reinstall libc6=2.15-0ubuntu10.4 libc6-dev=2.15-0ubuntu10.4'
end
end
#/config/recipes/puppet.rb
# This runs once as root after bootstrapping, and in the future as the deployer user
namespace :puppet do
desc "Provision the server by applying this project's Puppet config"
task :default do
# create a tarball of the puppet directory and upload to the server
system "mkdir -p ./tmp && tar czf './tmp/puppet.tgz' puppet/"
upload "./tmp/puppet.tgz","/tmp/puppet.tgz", :via => :scp
# unpack the tarball and replace the old puppet system config
run "tar xzf /tmp/puppet.tgz"
run "rm -rf /etc/puppet"
run "mv puppet/ /etc/puppet"
system 'rm ./tmp/puppet.tgz' # cleanup
# let the puppets dance!
try_sudo "puppet apply /etc/puppet/manifests/site.pp"
end
end
# And in your deploy.rb add
# after "bootstrap", "puppet"
# to run this task right after bootstrapping as root once.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment