To make a newly provisioned machine part of our Puppet infrastructure, we just need to run a few commands on it, so let's make this process even easier by adding a new bootstrap task to the Rakefile.
Getting ready...
To get ready for the recipe, do the following:
Add the following line to the top of your Rakefile:
You'll need a freshly provisioned server (one that you can log in to, but that doesn't have Puppet installed or any other config changes made on it). If you're using EC2, create a new EC2 instance. Get the public instance address from the AWS control panel; it'll be something like:
ec2-107-22-22-159.compute-1.amazonaws.com
Here are the steps to bootstrap the new server using Rake:
Add a node declaration to your nodes.pp file for the hostname you'll be using on the new server. For example, if you wanted to call it cookbook-test, you could use
node 'cookbook-test' {
include puppet
}
Run the following command in the Puppet repo on your own machine (substitute the address of the new server as the value of CLIENT, and the hostname you want to use as the value of HOSTNAME). The command should all be on one line:
(in /Users/john/git/cookbook)ssh -A -i ~/git/bitfield/bitfield.pem -l ubuntu ec2-107-22-22-159.compute-1.amazonaws.com 'sudo hostname cookbook-test && sudo su -c 'echo cookbook-test >/etc/hostname' && wget http://apt.puppetlabs.com/puppetlabs-release-precise.deb && sudo dpkg -i puppetlabs-release-precise.deb && sudo apt-get update && sudo apt-get -y install git puppet && git clone git@github.com:bitfield/cookbook.git puppet && sudo puppet apply --modulepath=/home/ubuntu/puppet/modules /home/ubuntu/puppet/manifests/site.pp'The authenticity of host 'ec2-107-22-22-159.compute-1.amazonaws.com (107.22.22.159)' can't be established.RSA key fingerprint is 23:c5:06:ad:58:f3:8d:e5:75:bd:94:6e:1e:a0:a3:a4.Are you sure you want to continue connecting (yes/no)? yesWarning: Permanently added 'ec2-107-22-22-159.compute-1.amazonaws.com,107.22.22.159' (RSA) to the list of known hosts.sudo: unable to resolve host cookbook-test--2013-03-15 15:53:44-- http://apt.puppetlabs.com/puppetlabs-release-precise.debResolving apt.puppetlabs.com (apt.puppetlabs.com)... 96.126.116.126, 2600:3c00::f03c:91ff:fe93:711aConnecting to apt.puppetlabs.com (apt.puppetlabs.com)|96.126.116.126|:80... connected.HTTP request sent, awaiting response... 200 OKLength: 3392 (3.3K) [application/x-debian-package]Saving to: `puppetlabs-release-precise.deb' 0K 100% 302M=0s2013-03-15 15:53:44 (302 MB/s) - `puppetlabs-release-precise.deb' saved [3392/3392]Selecting previously unselected package puppetlabs-release.(Reading database ... 25370 files and directories currently installed.)Unpacking puppetlabs-release (from puppetlabs-release-precise.deb) ...Setting up puppetlabs-release (1.0-5) ...Processing triggers for initramfs-tools ...update-initramfs: Generating /boot/initrd.img-3.2.0-29-virtualIgn http://us-east-1.ec2.archive.ubuntu.com precise InRelease[ ... apt output redacted ... ]Setting up hiera (1.1.2-1puppetlabs1) ...Setting up puppet-common (3.2.2-1puppetlabs1) ...Setting up puppet (3.2.2-1puppetlabs1) ...* Starting puppet agentpuppet not configured to start, please edit /etc/default/puppet to enable ...done.Processing triggers for libc-bin ...ldconfig deferred processing now taking placeCloning into 'puppet'...Warning: Permanently added 'github.com,207.97.227.239' (RSA) to the list of known hosts.Notice: /Stage[main]/Puppet/Cron[run-puppet]/ensure: createdNotice: /Stage[main]/Puppet/File[/usr/local/bin/pull-updates]/ensure: defined content as '{md5}20cfc6cf2a40155d4055d475a109137d'Notice: /Stage[main]/Puppet/File[/usr/local/bin/papply]/ensure: defined content as '{md5}171896840d39664c00909eb8cf47a53c'Notice: /Stage[main]/Puppet/File[/home/ubuntu/.ssh/id_rsa]/ensure: defined content as '{md5}db19f750104d3bf4e2603136553c6f3e'Notice: Finished catalog run in 0.11 seconds
How it works...
Here's a line by line breakdown of what the Rake task does. In order to make the machine ready to run Puppet, we need to set its hostname to the name you've chosen:
The new machine will now pull and apply Puppet changes automatically, without you ever having to log into it interactively. You can use this Rake task to bring lots of new servers under Puppet control quickly.