Pear Packages installation under Vagrant with Puppet
I have been running Vagrant vm with Puppet for the last 4 months for my development work.
Most of the vagrant stuff is pretty straight forward, once you grasp the concepts.
This post will assume that you are familiar with Vagrant and Puppet, if you are not this is a great place to start.
One aspect of my setup was lacking pear packages installation was prone to errors and as a result of that failed dependencies.
More often than not I would get this fun little error message
1
err: /Stage[main]//Exec[pear upgrade]/returns: change from notrun to 0 failed: /usr/bin/pear upgrade returned instead of one of [0] at /tmp/vagrant-puppet/manifests/base.pp:98
All other puppet tasks that rely on this one would be skipped due to failed dependencies.
The problem arises from the fact that pear upgrade will return a null or '’ value if there is nothing to update, and puppet will misinterpret that as an error as you can see in the error message above.
One solutions that I found was to add the possible returned values like this:
On line 5 the returned values are defined, 0 is the default one, and I added the empty string and space just in case, that resolved the problem of the pear upgrade.
To keep things simple, pear should be allowed to auto-discover channels and dependencies.
1
2
3
4
5
# set channels to auto discover
exec { "pear auto_discover" :
command =>"/usr/bin/pear config-set auto_discover 1",
require =>[Package['php-pear']]
}
And to wrap up the prerequisites for pear setup the pear update-channels should be executed.
It may not be necessary, but in some cases it was reported that this command would prevent the pear errors during installation of pear packages.
So we come to the last piece of the puzzle, if you try to reinstall the pear package, you will get the message that the package is already installed and the task will fail.
The solution for this was a tip from Robert Basic.
I need to use the creates parameter, that checks if the file exists, and if it does not, the install will be attempted.
So here is how I installed a good portion of tools from The PHP Quality Assurance Toolchain