5

I am new to Chef and following a tutorial which is providing information on running a default recipe inside a cookbook or a specific recipe. The tree output for my Cookbook is as follows:

pwd
/opt/dk-chef/python_code/Chef
[root@LUMOS Chef]# tree Cookbooks/BasicLinux/
Cookbooks/BasicLinux/
├── Berksfile
├── chefignore
├── LICENSE
├── metadata.rb
├── nodes
│   └── LUMOS.RMT.com.json
├── README.md
├── recipes
│   ├── default.rb
│   ├── nodes
│   │   └── LUMOS.RMT.com.json
│   └── setup.rb
├── spec
│   ├── spec_helper.rb
│   └── unit
│       └── recipes
│           └── default_spec.rb
└── test
    └── smoke
        └── default
            └── default_test.rb

Running the chef-client command as follows tells me that the Cookbook is always missing. Is there a configuration parameter that I need to set so that the cookbook is found?

chef-client -z -r "recipe[BasicLinux::setup]"
[2017-12-21T15:18:20-05:00] WARN: No config file found or specified on command line, using command line options.
[2017-12-21T15:18:20-05:00] WARN: No cookbooks directory found at or above current directory.  Assuming /opt/dk-chef/python_code/Chef.
[2017-12-21T15:18:20-05:00] WARN: No cookbooks directory found at or above current directory.  Assuming /opt/dk-chef/python_code/Chef.
Starting Chef Client, version 13.6.4
resolving cookbooks for run list: ["BasicLinux::setup"]

================================================================================
Error Resolving Cookbooks for Run List:
================================================================================

Missing Cookbooks:
------------------
No such cookbook: BasicLinux

Expanded Run List:
------------------
* BasicLinux::setup

System Info:
------------
chef_version=13.6.4
platform=redhat
platform_version=6.6
ruby=ruby 2.4.2p198 (2017-09-14 revision 59899) [x86_64-linux]
program_name=chef-client worker: ppid=23170;start=15:18:20;
executable=/opt/chefdk/bin/chef-client


Running handlers:
[2017-12-21T15:18:23-05:00] ERROR: Running exception handlers
[2017-12-21T15:18:23-05:00] ERROR: Running exception handlers
Running handlers complete
[2017-12-21T15:18:23-05:00] ERROR: Exception handlers complete
[2017-12-21T15:18:23-05:00] ERROR: Exception handlers complete
Chef Client failed. 0 resources updated in 03 seconds
[2017-12-21T15:18:23-05:00] FATAL: Stacktrace dumped to /root/.chef/local-mode-cache/cache/chef-stacktrace.out
[2017-12-21T15:18:23-05:00] FATAL: Stacktrace dumped to /root/.chef/local-mode-cache/cache/chef-stacktrace.out
[2017-12-21T15:18:23-05:00] FATAL: Please provide the contents of the stacktrace.out file if you file a bug report
[2017-12-21T15:18:23-05:00] FATAL: Please provide the contents of the stacktrace.out file if you file a bug report
[2017-12-21T15:18:23-05:00] ERROR: 412 "Precondition Failed"
[2017-12-21T15:18:23-05:00] ERROR: 412 "Precondition Failed"
[2017-12-21T15:18:23-05:00] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully (exit code 1)
[2017-12-21T15:18:23-05:00] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully (exit code 1)
John Squarry
  • 81
  • 1
  • 9

2 Answers2

3

1.Create the directory with name "cookbooks" and put(or create) your cookbook in that directory 2.From the outside of cookbooks directory, fire your or following command. sudo chef-client -z --runlist "your_cookbook_name::your_recipe_name"

0

That needs to be cookbooks/BasicLinux/, and you also need name 'BasicLinux' in the metadata.rb. Given the recipes/nodes/ folder also make sure you are in the right folder, you need to be in /opt/dk-chef/python_code/Chef, not /opt/dk-chef/python_code/Chef/cookbooks/BasicLinux/recipes/ or anything else (you can delete the nodes/ folders inside the cookbook).

coderanger
  • 52,400
  • 4
  • 52
  • 75
  • Hello @coderanger, the metadata.rb has the entry for BasicLinux. Here is the content of the file. cat Cookbooks/BasicLinux/metadata.rb name 'BasicLinux' maintainer 'The Authors' maintainer_email 'you@example.com' license 'All Rights Reserved' description 'Installs/Configures BasicLinux' long_description 'Installs/Configures BasicLinux' version '0.2.1' chef_version '>= 12.1' if respond_to?(:chef_version) [root@LUMOS Chef]# pwd /opt/dk-chef/python_code/Chef – John Squarry Dec 27 '17 at 16:06
  • I followed your suggestion and I still get the same error: [root@LUMOS Chef]# chef-client -z -r "recipe[Cookbooks/BasicLinux::setup]" [2017-12-27T11:03:46-05:00] WARN: No config file found or specified on command line, using command line options. [2017-12-27T11:03:46-05:00] WARN: No cookbooks directory found at or above current directory. Assuming /opt/dk-chef/python_code/Chef. Starting Chef Client, version 13.6.4 resolving cookbooks for run list: ["Cookbooks/BasicLinux::setup"] Error Resolving Cookbooks for Run List: Missing Cookbooks: No such cookbook: Cookbooks/BasicLinux – John Squarry Dec 27 '17 at 16:07
  • You still have `Cookbooks`, with a capital. It needs to be lowercase. And `cookbooks/` is not part of the name of the cookbook. – coderanger Dec 27 '17 at 21:48
  • Hello, no change using lowercase cookbooks either – John Squarry Dec 29 '17 at 16:23
  • chef-client -zr "recipe[cookbooks/BasicLinux::setup]" resolving cookbooks for run list: ["cookbooks/BasicLinux::setup"] ================================================================================ Error Resolving Cookbooks for Run List: ================================================================================ Missing Cookbooks: ------------------ No such cookbook: cookbooks/BasicLinux – John Squarry Dec 29 '17 at 16:23
  • As I said, `cookbooks/` is not part of the recipe name. `-r recipe[BasicLinux::setup]`. – coderanger Dec 29 '17 at 16:44
  • that is exactly what I tried initially and posted in the initial post. chef-client -z -r "recipe[BasicLinux::setup]" . are you suggesting I remove the double quotes? If so, I tried that as well – John Squarry Jan 10 '18 at 22:32
  • No, you need to both fix the folder structure and use the correct name in the run list. – coderanger Jan 10 '18 at 22:47