Control a whole network of computers from PuppetMaster.
Wikipedia uses puppet for servers, Google uses puppet for OSX laptops. With this article, you can use puppet with Ubuntu servers and desktops.
Prequisites
To follow this article, you should be fluent with command line, apt, sudo, installing and configuring daemons. You should have basic knowledge about public key encryption, client server -model and networking.
I assume you do the obvious stuff without mentioning: Setup and use SSH to connect to your hosts, as logging in and out of hosts is not listed here. Run ‘sudo apt-get update’ before other apt commands.
I tested with Ubuntu 12.04 LTS. If you want to use 10.04 LTS, you can find the new Puppet 2.7.x packages in backports. At least 20 persons have successfully installed PuppetMaster with this guide.
Conventions
We have two computers, hostnames master and slave. Prompt shows where the commands are given, eg. running ‘pwd’ on host master.
master$ pwd
Test connectivity
slave$ ping -c 1 master.local
If your master doesn’t answer, fix that first.
Feel free to use whatever hostnames you want. If you hosts are in the same local network, you can use Avahi/ZeroConf/Rendevouz to use hostname.local names. If your master has a public DNS name or a dynamic name, you can use that, too.
To use .local names, you might need to ‘sudo apt-get -y install avahi-utils’.
Install PuppetMaster
master$ sudo apt-get -y install puppetmaster
Regenerate Master Certificate
Let’s create PuppetMaster certificate with correct names. Clients will only accept certificate if it matches the DNS name they use for contacting the master.
To avoid using hackish “puppet in hosts” method, create a certificate with all names of master. First, remove the old certificate
master$ sudo service puppetmaster stop
master$ sudo trash /var/lib/puppet/ssl
Add master’s name to config
master$ sudoedit /etc/puppet/puppet.conf
add these names under [master] heading
dns_alt_names = puppet, master.local, puppet.terokarvinen.com
Certificate is automatically generated when you start PuppetMaster
master$ sudo service puppetmaster start
You can verify certificate details with ‘sudo ls /var/lib/puppet/ssl/certs/’ and ‘sudo openssl x509 -in /var/lib/puppet/ssl/certs/puppet.terokarvinen.com.pem -text|grep -i dns’. It should show all of your DNS names.
Connect from Slave
slave$ sudo apt-get -y install puppet
slave$ sudoedit /etc/puppet/puppet.conf
Add master DNS name under [agent] heading. Puppet will connect to server.
[agent]
server = master.local
Allow puppet slave (aka agent) to start
slave$ sudoedit /etc/default/puppet
Change to yes:
START=yes
If you have connected to master before, force slave certificate regeneration with ‘sudo service puppet stop’ and ‘sudo trash /var/lib/puppet/ssl’. The new slave certificate will be generated the next time puppet starts.
Start puppet agent
slave$ sudo service puppet restart
Slave should now connect to master.
Sign Slave Certificate on Master
master$ sudo puppet cert --list
master$ sudo puppet cert --sign slave.example.com
Of course, use the actual name of the slave you have chosen.
Create Site Manifest and a Module
Create site manifest, the config file that includes everyghing else:
master$ cd /etc/puppet
master$ sudo mkdir -p manifests/ modules/helloworld/manifests/
master$ sudoedit manifests/site.pp
Add just one line
include helloworld
Create a hello world module
master$ sudoedit modules/helloworld/manifests/init.pp
Write the module
class helloworld {
file { '/tmp/helloFromMaster':
content => "See you at http://terokarvinen.com/tag/puppet\n"
}
}
Test & Enjoy
Puppet will automatically fetch configuration every now and then. Restarting (or usually, just reloading) the service will fetch and apply configuration immediately.
slave$ sudo service puppet restart
Congratulate yourself when you see the file from PuppetMaster
slave$ cat /tmp/helloFromMaster
See you at http://terokarvinen.com/tag/puppet
Administrivia
Tested on two instances of Xubuntu 12.04 LTS beta1 on Vagrant running on Xubuntu 12.04 LTS beta2. Also, at least 20 persons have successfully installed PuppetMaster with this tutorial.
Update: Fixed puppet.conf path on slave. About 20 persons successfully tested this guide.