0

When using Vagrant (and subsequently Chef), I'm provisioning my VM using Zend Server CE, which automatically installs the usually *AMP stack.

I'd like to install some packages via PEAR, for which the "php" cookbook already has a "pear" and "pear_channel" provider. However, by calling require_recipe("php"), default.rb is ran automatically which attempts to reinstall PHP.

I just want to take advantage of it's few providers without executing default.rb.

Is there a way to do this?

Eric
  • 111
  • 4
  • I don't know why this was voted down, but it isn't necessary. I think a lot of people newer to chef run into this. – Kyle Mar 02 '12 at 00:33

2 Answers2

2

You need to make sure all your chef recipes are idempotent and nondestructive for your environment. Chef will always run default.rb when you require or include the recipe.

Two ways to fix this:

  1. Make your PHP recipe check for installed PHP binaries, and do nothing if they are found
  2. Move the installation steps to a new recipe file outside of default.rb

Number one is the best solution, but if you do indeed have situations where you want to use PEAR but not have chef manage php, you could do the second.

Kyle
  • 1,589
  • 9
  • 14
  • Thanks for this. The Opscode cookbooks for PHP attempt a second installation on top of Zend Server CE's PHP. I initially went with #2 and removed the forced installation of PHP, but ran into difficulties even referencing the providers. Finally, moving the pear portions into my own "zend" cookbook sufficed. – Eric Mar 02 '12 at 04:52
2

You can specify that your cookbook depends on the opscode php cookbook by adding depends 'php' to your cookbook's metadata.rb. By using depends, you don't have to actually run the php cookbook. See http://wiki.opscode.com/display/chef/Metadata#Metadata-depends

Then, assuming the php cookbook is available from your chef server, a chef-client run will pull down the php cookbook, so that the php_pear and php_pear_channel resources are available. In your own recipe, simply add instructions according to the php cookbook:

php_pear "DB" do
  action :install
end
Mike C
  • 21
  • 2