Intro I am learning Chef to automate the server management at work. I downloaded chefdk 3.0 from here and now I am trying to build my first cookbook using chef.
Important I am using this in a Windows environment for testing purpose, I do expect it to fail since Windows does not have iptables, but I do not expect it to fail saying that it can't find the cookbook. I've tried using Windows cookbook and it works.
The problem I am able to create the cookbook and run it, but I am not able to reference dependencies from supermarket.
I have tried two alternatives:
Alternative 1
I used the following command to create the cookbook
chef generate cookbook learn_chef_httpd
(from this tutorial)
I was able to complete the tutorial and now I would like to test referencing another cookbook, so I chose simple_iptables
I added this line
cookbook 'simple_iptables', '~> 0.7.0'
To my Berksfile, as described in the Supermarket.
Then I added these lines to my default.rb file:
include_recipe 'simple_iptables'
# Allow HTTP, HTTPS
simple_iptables_rule "http" do
rule [ "--proto tcp --dport 80",
"--proto tcp --dport 443" ]
jump "ACCEPT"
end
And I run the cookbook using:
chef-client --local-mode --runlist 'recipe[learn_chef_httpd]'
The problem is that Chef doesn't find the cookbook
Chef::Exceptions::CookbookNotFound
----------------------------------
Cookbook simple_iptables not found. If you're loading simple_iptables from anoth er cookbook, make sure you configure the dependency in your metadata
I tried adding it to the metadata:
depends 'simple_iptables', '~> 0.7.0'
But I still get an error:
Error Resolving Cookbooks for Run List:
Missing Cookbooks:
No such cookbook: simple_iptables
Alternative 2
I am still trying to make it work so I also tried making it "the berkshelf way", so I created a new cookbook.
berks cookbook test
And I added this line
cookbook 'simple_iptables', '~> 0.7.0'
To my Berksfile, as described in the Supermarket.
Then I added these lines to my default.rb file:
include_recipe 'simple_iptables'
# Allow HTTP, HTTPS
simple_iptables_rule "http" do
rule [ "--proto tcp --dport 80",
"--proto tcp --dport 443" ]
jump "ACCEPT"
end
Executed berks install:
berks install
and ran it:
chef-client --local-mode --runlist 'recipe[test]'
The same error came back
Chef::Exceptions::CookbookNotFound
----------------------------------
Cookbook simple_iptables not found. If you're loading simple_iptables from anoth er cookbook, make sure you configure the dependency in your metadata
I tried adding it to the metadata:
depends 'simple_iptables', '~> 0.7.0'
But I still get an error:
Error Resolving Cookbooks for Run List:
Missing Cookbooks:
No such cookbook: simple_iptables
I looked at the ~/berkshelf folder and the cookbooks are there.
** Alternative 3 **
I started a CentOS 6.5 EC2 instance on Amazon, installed Ruby 2.1.3 and Chef. created a ~/chef-repo/cookbooks folder
I created a cookbook using berkshelf, ran
bundle install
added the reference/code as in the other alterantives then
berks install
and ran the same way I did last time.
I got the same issues.
What am I missing? What do I need to make it work?
berks install
after modifying the berksfile. You may also wish to use berks vendor to make a directory conatining all the cookbooks needed, and pointing chef-client repo path to this directory. All in all, your cookbooks are on your disk, but not somewhere chef-zero look to. – Ensphere