We’ve been using Vagrant more and more, especially for testing our Puppet code. It can be much more flexible than testing on an existing box, and Vagrant AWS is really promising.

But when we first started using Puppet with Vagrant, Puppet was freaking out.

Freaked out puppets

We resolved most of the errors quickly, but we couldn’t figure out what to do about this error message:

can't convert String into Integer at /tmp/vagrant-puppet/modules-0/puppet/manifests/init.pp:11 on node localhost.localdomain

Immediately, we tracked it down to a use of the fqdn_rand function.

minute => fqdn_rand(60),

The easy fix was to cheat and just put in a number by hand.

minute => 42, # fqdn_rand(60),

That got us by, but it felt dirty. We knew the problem was only happening when we tried to use Puppet in conjunction with Vagrant. Since FQDN stands for Fully Qualified Domain Name, it seemed like Puppet needed more information, but the documentation wasn’t too helpful on how to provide that.

I had found out how to set the hostname to provision Vagrant boxes as different nodes, so that was my first attempt.

config.vm.hostname = 'vagrant-foo.example.com'

Alas, that didn’t fix the issue. What other options were there? Use another function for random numbers?

The trouble is, the only random number function we could find for the Puppet language was fqdn_rand. There wasn’t anything else, and that’s really weird. Something like mac_rand (using the MAC address) would make sense, but all we could find was abandoned tickets in the Puppet Redmine, if anything. (That’s becoming a theme in our experience, actually…)

We went back to doing the dirty solution, and just avoided committing that file. That went on for at least a week.

I got fed up with it again today, and searched some more. It turns out that you can set the FQDN using puppet.facter, and there was a bug with this before Puppet 3. We are currently using 3.1.1.

This is what we had to do to get Puppet to stop complaining. Note that this didn’t work for us without both the hostname and the fqdn values set.

Update (2013-04-26): It seems like FQDN doesn’t play as big of a role as I first thought – the problem seems to go away with just hostname set when using Puppet 3.1.1.

# File: Vagrantfile
Vagrant.configure('2') do |config|
  config.vm.box      = '[...]'
  config.vm.hostname = 'vagrant-foo.example.com'

  # [...]

  config.vm.provision :puppet, :module_path => %w(modules) do |puppet|
    # fix `fqdn_rand` error
    puppet.facter = { 'fqdn' => config.vm.hostname }

And now our Puppet is happy again.

Happy puppet

(Keep in mind that Vagrantfile settings like these might require a vagrant reload or a vagrant destroy --force && vagrant up.)

Puppet is a little hard to understand sometimes, and this solved a long standing issue for us. It’s worth noting that this could also be used for testing virtual hosts, as mentioned in the vagrant-puppet README.