
Chef Infrastructure Automation Cookbook Second Edition
By :

Sometimes, you may want to peek into the files stored on your Chef server. You might not be sure about an implementation detail of that specific cookbook version, which is currently installed on your Chef server, and need to look it up. Knife can help you out by letting you show various aspects of the files stored on your Chef server.
Make sure that you have the iptables
cookbook installed locally and uploaded on your Chef server.
mma@laptop:~/chef-repo $ knife cookbook site install iptables
Installing iptables to /Users/mma/work/chef-repo/cookbooks ...TRUNCATED OUTPUT...
Take a look at the following error:
ERROR: IOError: Cannot open or read ../chef-repo/cookbooks/iptables/metadata.rb!
If you get the preceding error, your cookbook only has a metadata.json
file. Make sure that you delete it and create a valid metadata.rb
, file instead.
iptables
cookbook on your Chef server by executing the following given command and code lines:mma@laptop:~/chef-repo $ knife cookbook upload iptables
Uploading iptables [0.14.0] Uploaded 1 cookbook.
Let's find out how knife can help you to look into a cookbook stored in your Chef server:
iptables
cookbook:mma@laptop:~/work/chef_helpster $ knife cookbook show iptables iptables 0.14.0
iptables
cookbook, using the version number that you found out in the previous step:mma@laptop:~/chef-repo $ knife cookbook show iptables 0.14.0 definitions
checksum: 45c0b77ff10d7177627694827ce47340 name: iptables_rule.rb path: definitions/iptables_rule.rb specificity: default url: https://s3.amazonaws.com/opscode-platform...
iptables_rule.rb
definition file, as stored on the server:mma@laptop:~/chef-repo $ knife cookbook show iptables 0.14.0 definitions iptables_rule.rb
# # Cookbook Name:: iptables # Definition:: iptables_rule # # define :iptables_rule, :enable => true, :source => nil, :variables => {} do ...TRUNCATED OUTPUT... end
The knife cookbook show
subcommand helps you understand what exactly is stored on the Chef server. It lets you drill down into specific sections of your cookbooks and see the exact content of the files stored in your Chef server.
Since Chef 11, you can pass patterns to the knife show
command to tell it what exactly you want to see. Showing the contents of the iptables_rule
definition can be done as follows, in addition to the way we described previously:
mma@laptop:~/work/chef_helpster $ knife show cookbooks/iptables/definitions/*
cookbooks/iptables/definitions/iptables_rule.rb: # # Cookbook Name:: iptables # Definition:: iptables_rule # # define :iptables_rule, :enable => true, :source => nil, :variables => {} do ...TRUNCATED OUTPUT... end
Change the font size
Change margin width
Change background colour