How to create a cookbook in Windows?

I am sorry, if I am asking the question again which is already answered as I could not able to find out an answer. If the question is already answered, please direct me to that link.

How to create a cookbook or generate a coookbook on windows using chef-client? as per the chef site:

chef generate cookbook should work, however, it doesn't work on windows. I want to use chef-client --local-mode to run recipes and cookbooks on windows, I just could not able to set cookbook.

thanks in advance.

Hi Mohit,

You should install ChefDK in Windows and use chef generate command to create cookbook. After updating the generated cookbook, then you can use Chef-client command to run recipes or cookbooks.

Thanks,
Karthi

1 Like

Or you can use chef workstation :slight_smile:

1 Like

Chefdk is your friend for this, especially since you can then use "chef-solo" to test the cookbook locally without ever having to upload it to and possibly break your chef-server with a malformed cookbook update.

chef generate cookbook testcookbook not working even installing chefdk on windows server.

thanks, but I am still not able to generate cookbook with chef workstation

thanks, but even after installing chefdk, I am unable to generate cookbook, I tried command: chef cookbook testcookbook which failed with error: Chef: The term 'chef' is not recognized as the name of cmdlet. whereas when I run chef-solo or chef-client commands, it works fine. Its just I can't generate cookbook. I need default.rb to specify the default path for the recipes.

The issue you're running into is that you probably have chef-client installed as well as chefDK, which is why chef-client/chef-solo run.

What didn't happen properly is your path didn't get added to include chefDK. Windows puts it by default into c:\opscode\chefdk you want c:\opscode\chefdk\bin added to your path.

1 Like

even on a new built server and only chefDk installed, I am getting below:

PS C:> chef generate cookbook testcookbook
chef : The term 'chef' is not recognized as the name of a cmdlet, function, script file, or operable program

Use “knife generate cookbook testcookbook” for older ChefDK

I am using ChefDK 2.4.17 and the “chef generate cookbook testcookbook” works for me on a windows 10 machine.

Could it be your chefDK version installed?

I tried chefdk and workstation, but still unable to generate cookbook. have you recently tried generating cookbook on windows. I am getting below error, I checked the variables and those are fine:

chef : The term 'chef' is not recognized as the name of a cmdlet, function, script file, or operable program. Check
the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1

  • chef generate cookbook testcookbok
  •   + CategoryInfo          : ObjectNotFound: (chef:String) [], CommandNotFoundException
      + FullyQualifiedErrorId : CommandNotFoundException

Are you trying to run that from powershell, or from the ChefDK terminal?

1 Like

so below is what worked for me from both powershell and command prompt.

PS C:\opscode\chef-workstation\bin> .\chef.bat generate cookbook c:\testcookbook

thanks very much to everyone who provided input on this, really learned from all of the posts and able to do what I was wanted.

You shouldn't need to qualify the path to the chef command since it's placed in the PATH environment variable. However, you will have to reboot your system in order for the updated path entry to be recognized since it's added in the SYSTEM context.

As a side note, you don't have to use the ChefDK shortcut if you don't want to run it as Administrator. You can add the following command to your powershell profile and it will initialize the chef dk in any powershell session:

chef shell-init powershell | Invoke-Expression
Import-Module -Name chef -DisableNameChecking