Vagrant is an amazing tool, especially switching between projects it comes in
handy to keep the dependencies separated. This works even better with puppet to
provision the machines in a reproducible fashion.
Installing vagrant
First things first, we need to install vagrant,
which has changed some time ago from being a gem to provide
installer packages. Installation now is really
simple, just download and install.
Setting up vagrant
To get of the ground lets setup an example box.
$ mkdir myproject && cd myproject
$ vagrant init precise32 http://files.vagrantup.com/precise32.box
This will download, and setup a basic box with ubuntu precise32.
Configure puppet
Inside the Vagrantfile we now configure vagrant to use
puppet, to provision the box for us. This will make
it easy to spin up a similar box whenever we need a new one.
Personally I prefer to modify the default vagrant behavior a bit and keep
everything puppet under puppet/*
inside the project.
Setting up phantomjs
Now to the meat of this example, setting up phantomjs from the tarball download
Netinstall
Luckily the good guys from example42 provide a nice
puppet module to handle just these installs, it comes packaged with
puppi. Right now puppi seems a little much
such we just extract the netinstall code inside a module of its own and set it
up
inside the repo
Netinstall is a quite simple module, the only dependency we need to worry about
is the uri_parser which is implemented as a ruby extension and located in lib.
I also decided to rename netinstall.pp
to init.pp
since it is autoloaded
this way, and removed the puppi prefix.
Setting up the init.pp
Under manifests
we can now create the custom init.pp
in which we install
phantomjs and libfontconfig1
on which it depends.
Vagrant up
Now a simple
$ vagrant up
Will provision the machine with phantomjs installed, which we can test via after
provisioning is done.
$ vagrant ssh
$ phantomjs
Missed something?
Installing new packages is now easy as adding them to the init.pp
file and
running
$ vagrant provision
Bundle all the dependencies!