1
votes

I am learning chef and so far I understood that it is best to have all opscode cookbooks in the cookbooks directory and all my customizations in site-cookbooks. This way I can mirror for example the apt cookbook in site-cookbooks and and change the

default['apt']['compile_time_update'] = true

to force an apt-get update which it didn't do before that. By the way to find out that this attribute file has going to be named "customize.rb" took me quite a while and isn't documented anywhere, as far as I know.

To get all cookbooks with it's dependencies for a simple LAMP Stack I am using the vagrant-librarian plugin. So my Cheffile looks like this.

site 'http://community.opscode.com/api/v1'

cookbook 'apt', '~> 2.8.2'
cookbook 'openssl', '~> 4.4.0'
cookbook 'apache2', '~> 3.1.0'
cookbook 'mysql', '~> 6.1.0'
cookbook "php", github: "priestjim/chef-php"
cookbook 'phpmyadmin', '~> 1.0.6'

My Vagrantfile is as follows:

Vagrant.configure(2) do |config|
   config.vm.box = "ubuntu/trusty64"
   config.vm.provider "virtualbox" do |v|
      v.memory = 1024
      v.name = 'chef-lamp'
   end
   config.vm.network "private_network", ip: "192.168.33.10"
   config.vm.host_name = "project.dev"
   config.vm.synced_folder "./public", "/vagrant/"

   config.omnibus.chef_version = "12.3.0"
   config.vm.provision "chef_solo" do |chef|
   chef.arguments = '--force-formatter'
   chef.cookbooks_path = ["cookbooks", "site-cookbooks"]
   chef.add_recipe 'apt'
   chef.add_recipe 'build-essential'
   chef.add_recipe 'mysql'
   chef.add_recipe 'xml'
   chef.add_recipe 'openssl'
   chef.add_recipe 'apache2'
   chef.add_recipe 'apache2::mod_php5'
   chef.add_recipe 'apache2::mod_rewrite'
   chef.add_recipe 'php'
   chef.add_recipe 'php::module_mysql'
   chef.add_recipe 'apache2::mod_php5'
   chef.add_recipe 'apache2::vhost'
   #chef.add_recipe 'phpmyadmin'
  end
 end

My main question is why is chef always trying to install php right after dealing with the apt cookbook although it is way down in the runlist which results in a compile error when trying to restart apache, such as apache is running threaded MPM, but your PHP Module is not compiled to be threadsafe.

When I split provisioning into two parts having the first run without any php recources and then add php resources in the second run (vagrant provision) then it works fine.

What am I missing there ... how can I tell chef to run through "apt, apache2, mysql," - first .... and then install php ??

Another Question would be -- Can I be shure that all dependencies added by librarian are included into the runlist by chef(automatically), or do I have to include all of them manually like I did with "build-essentials" for example in my Vagrantfile.

hope someone can help me, thanks.

2
I hardly think the cookbooks/site-cookbooks pattern is the way to go these days. Use Berkshelf to manage dependencies. Have you looked into chefdk?cassianoleal
well I thought it is the best way to save yourself from roles and wrapper cookbooks while keeping things separated for versioning.FitzPatrick
Why would you want to save yourself from roles and wrappers?cassianoleal

2 Answers

1
votes

It is possible to execute action earlier that running run-list using run_action method. Priestjim cookbook installs php in that way. The solution might be using community cookbook and copy custom recipes or do php installation inside your custom recipe.

0
votes

The solution was writing a custom recipe in site-cookbooks and changing package installations where it says # Run the package installation at compile time into the following

node['php']['packages'].each do |pkg|
  package pkg
end

and of course appending all the following template and directory definitions from the original recipe to the custom recipe.

Seems to be working now.

Maybe this is useful for anyone although it might not be the way a chef professional would do it.