Sunday, 8 July 2012

Vagrant, Puppet and git

Vagrant, Puppet and git are powerful tools on their own, used together and you can have a fully functioning configured virtual box or multiple boxes with one command, and you can push changes to boxes with another command.

This is the command to create a node,

dev-macbook # vagrant up

This launches a virtual machine based on a base box (i.e. Ubuntu 12) via virtual box, vagrant uses a VagrantFile to configure the box, things like port forwarding, host name etc, however I prefer to leave all the configuration to puppet (which we will see later).

One very useful thing that  the VagrantFile can configure is a provisioner, it has support for Puppet, Chef and good ole Shell provisioners.  What this boils down to is just after the machine is created (the first time it boots) it calls the provisioner. I use the Shell provisioner as I want to use the same  mechansim for bootstrapping a node whether its with vagrant or with a cloud provider, and shell scripts are the most widely supported.  Another reason is some cloud providers allow limited length of a boot-strap script.

The bash script does a couple of things, it installs git and puppet then it sets up a ssh key for root to enable a git clone of a puppet repository automatically.  Bitbucket is a good choice for hosting your repository as it allows free unlimited private repos, with git ssh access.  Once the puppet repo is cloned it calls puppet apply on the site.pp.  I based my script on this excellent blog post, the part under "The Code", it is focused on AWS ec2 but it also works for Vagrant.

Puppet then takes over and builds your node, and I get  puppet to do a few things that allow pushing puppet changes to the node (or many nodes).  I will cover this in my next post.






No comments:

Post a Comment