How to run Chefspec on a cookbook that depends on another cookbook?

252 views Asked by At

I'm re-learning Chef (I did it for 2+ years in a previous life), and to help I am just installing a LAMP application on a CentOS 7 Vagrant box. To keep it simple, all my cookbooks are in the same /path_to/cookbooks directory, that is,

/path_to/cookbooks/
------------------/my_mysql
------------------/my_php
------------------/my_apache

They are also in the same chef-repo.git repository, again to keep it simple. That is, when I clone my chef-repo.git repository, I get the directory structure above.

The my_php cookbook depends on the my_apache cookbook, so I have this..

my_php:metadata.rb file
depends 'my_apache'

So that I can restart the httpd service in my my_php:default.rb recipe, like this

file '/var/www/html/info.php' do
  content "
    <?php phpinfo();
  "
  mode '0644'
  owner 'root'
  group 'root'
  notifies :restart, 'service[httpd]', :immediately
end

Again to keep it simple, I don't want to use Berkshelf. How do I then make this work for my_php cookbook? Is it possible?

$ chef exec rspec --color spec/unit/recipes/default_spec.rb

If I HAD to do this with Berkshelf, what should my Berksfile look like?

1

There are 1 answers

0
Chris F On

Ok, I recall now. Using a Berksfile, I had to do this. (It's slowly coming back)

source 'https://supermarket.chef.io'

cookbook 'cf_apache', '~> 0.1.0', github: "my_user/chef-repo", rel: 'cookbooks/cf_apache'

I now am able to run my chefspec, but will have to fix errors.