To easily clone the repo with all submodules:
git clone [email protected]:OpenWatch/chef-repo.git --recursive
To update all submodules after the initial clone.
git submodule update --init --recursive
We're using JewelryBox to manage our ruby installation due to potential conflicts between ruby packages and the ruby build bundled with OSX.
-
Download JewelryBox
-
Within JewelryBox, install rvm This is a virtual environment manager for ruby
-
Under the 'Add Ruby' tab, select the most recent 'pxxx' release. Click 'Install'. See Notes if your build fails.
-
Check that the following has been added to your
~/.bash_profile
:source $HOME/.rvm/scripts/rvm
-
In JewelryBox, select the 'Manage Rubies' tab, and then the build you just installed. The first 'Options' pane should include a 'Set As Default' Button. Click it.
- Check that this worked with
ruby --version
- Check that this worked with
gem install chef
cd /chef-repo
-
mkdir .chef
-
Copy the project secrets into
/chef-repo/.chef
:- Chef User private key (username.pem)
- Knife configuration file (knife.rb)
- Chef Organization private key (organization.pem)
Librarian helps tracks the cookbooks and dependencies via a Cheffile
. Read more about Librarian here.
-
If you don't have it already:
$ gem install librarian
-
Ensure the cookbooks directory is empty
-
From your Chef repo's directory, run
librarian-chef install --clean --verbose
- Note: This will delete the contents of
/cookbooks
- Note: This will delete the contents of
-
Add the following to your knife.rb file
require 'librarian/chef/integration/knife' cookbook_path Librarian::Chef.install_path, "/path/to/chef-repo/site-cookbooks"
+Note: Librarian recommends in-development cookbooks be stored in
/site-cookbooks
rather than being managed by Librarian. -
Upload cookbooks to Chef Server
$ knife cookbook upload --all
FoodCritic is a cookbook linter that requires Ruby 1.9.2+
$ gem install foodcritic
To criticize a cookbook invoke:
$ foodcritic /path/to/cookbook
knife-sync-all wraps knife commands to simplify bulk syncing. To install simply copy sync-all.rb to ./chef/plugins/knife
. Now you can do great things:
$ knife sync-all -r
# syncs all roles
$ knife sync-all --help
# lists all options
When developing cookbooks, be sure to pass a path command to knife to ensure they don't end up in /cookbooks
to be overwritten by Librarian.
$ knife cookbook create new_cookbook -o site-cookbooks/
-
Add your new resource to the
Cheffile
# Cheffile ... cookbook "chef-ssh-wrapper", :git => "https://github.com/OpenWatch/chef-git_ssh_wrapper.git"
-
Call the librarian
librarian-chef install
$ librarian-chef update
Note: If building halts with an error like that below, you need to install apple-gcc-4.2 with Homebrew.
regparse.c:582:15: error: implicit conversion loses integer precision: 'st_index_t' (aka 'unsigned long') to 'int' [-Werror,-Wshorten-64-to-32]
return t->num_entries;
Remedy:
$ brew tap homebrew/dupes
$ brew install apple-gcc42