2
votes

I've begun to try out Chef on Windows (though I don't believe that the OS is necessarily relevant here), and I've come across a sort of a conundrum.

I was following a "getting started" tutorial, which recommended that I clone a Chef repository from GitHub. The readme file for this repository, however, states that this isn't recommended, and instead recommends running chef generate repo, so I did. In my home directory, I ran chef generate repo chef_repo and got (what looked like) mostly the same files and directories. Great.

One of the directories I got was a .chef directory, where (as I understand it) I am to place various files. The tutorial I was following recommended that I place the .chef directory in my .gitignore file. Ok, that's fine.

As I progressed through the tutorial, I came across the documentation for the knife.rb file, which states that knife, by default, expects the knife.rb file to be in ~/.chef. This seems strange to me, as it's fairly clear that the .chef directory should be in the chef repository (both the GitHub sample repository and the chef-generated repository have it this way), unless Chef expects that my entire home directory will be a Git repository, and Chef's Git repository.

Where should the knife.rb file go? Is it "standard practice" to have multiple .chef directories? Is it "standard practice" to never provide a default knife.rb file?

1
"~/.chef" or "$HOME/.chef" or "%HOME%/.chef" is the default location (OS dependent) for the chef configuration files. Alternatively they can be located in a ".chef" directory local to the user when running the knife command. All is explained in the doco: docs.chef.io/config_rb_knife.html - Mark O'Connor
Yeah, I mentioned that. It's not the answer, it's part of the question. - Mark
It's up to you where your configuration file goes. Personally I like to centralize my configuration in one place and use the knife block plugin to switch between chef servers. Others prefer to create a .chef directory in each chef repository associated with each chef server. Completely up to you. If you choose the latter approach it is recommended to add .chef to the ignore file so that it doesn't get committed into you repository, why? Bad idea to have private keys in a repo. Yes... You've stated all this in your question. You have all the information I hope this perspective has been of help. - Mark O'Connor
Is it common to work with multiple chef servers? - Mark
For me it is :-) The number of chef servers you require is ultimately determined by your organisational processes. Speaking generically you'd probably have at least two: Production and non-production. Not uncommon to restrict access to production system. Finally you may want to have one or more additional development chef servers (although tools like chef zero allow developers to run chef server locally). - Mark O'Connor

1 Answers

0
votes

You can use knife block to switch between configurations to work with multiple Chef servers. This works by symlinking the multiple knife configurations (like ~/.chef/knife-chef11.rb and ~/.chef/knife-chef12.rb) to the main knife.rb location.

Example: knife block use chef11

To install, run: chef gem install knife-block