Skip to content

Instantly share code, notes, and snippets.

@jtimberman
Created December 20, 2011 02:59
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jtimberman/e87e3d77d47a5151b8ee to your computer and use it in GitHub Desktop.
Save jtimberman/e87e3d77d47a5151b8ee to your computer and use it in GitHub Desktop.
Minimal, fastest way to go with chef-solo:

Install Chef (use wget -O- instead of curl -L if you don't have curl installed):

curl -L http://opscode.com/chef/install.sh | sudo bash

Create the directory where the test cookbook will live:

mkdir -p ~/chef-repo/cookbooks/my_thing/recipes/
cd ~/chef-repo

Create a Chef Solo configuration file that can be used by non-privileged users:

echo -e "file_cache_path '${HOME}/.chef/cache'\ncookbook_path '${HOME}/chef-repo/cookbooks'\nchecksum_path '${HOME}/.chef/checksums'" > ~/chef-repo/solo.rb

Create the JSON file that tells Chef what recipe(s) to run:

echo '{"run_list": [ "recipe[my_thing]" ] }' > ~/chef-repo/node.json

Create the default recipe with a simple log resource.

echo 'log "Im running Chef!"' > ~/chef-repo/cookbooks/my_thing/recipes/default.rb

Run chef-solo with the config and JSON files above, and specify a node name:

chef-solo -N guineapig -j node.json -c solo.rb
# Example recipe. This will need to be run as root as it installs a package
# writes to /etc and manages a service.
file "/tmp/testfile" do
mode "0600"
end
file "/etc/nologin" do
content 'Server will be down for maintenance 2 AM - 4 AM'
end
# change apache2 to httpd on RHEL
package "apache2"
service "apache2" do
action :start
end
jtimberman@guineapig:~/chef-repo$ chef-solo -N guineapig -j node.json -c solo.rb
[Mon, 19 Dec 2011 20:05:26 -0700] INFO: *** Chef 0.10.8 ***
[Mon, 19 Dec 2011 20:05:26 -0700] INFO: Setting the run_list to ["recipe[my_thing]"] from JSON
[Mon, 19 Dec 2011 20:05:26 -0700] INFO: Run List is [recipe[my_thing]]
[Mon, 19 Dec 2011 20:05:26 -0700] INFO: Run List expands to [my_thing]
[Mon, 19 Dec 2011 20:05:26 -0700] INFO: Starting Chef Run for guineapig
[Mon, 19 Dec 2011 20:05:26 -0700] INFO: Running start handlers
[Mon, 19 Dec 2011 20:05:26 -0700] INFO: Start handlers complete.
[Mon, 19 Dec 2011 20:05:26 -0700] INFO: Processing log[Im running Chef!] action write (my_thing::default line 1)
[Mon, 19 Dec 2011 20:05:26 -0700] INFO: Im running Chef!
[Mon, 19 Dec 2011 20:05:26 -0700] INFO: Chef Run complete in 0.003911608 seconds
[Mon, 19 Dec 2011 20:05:26 -0700] INFO: Running report handlers
[Mon, 19 Dec 2011 20:05:26 -0700] INFO: Report handlers complete
[Mon, 19 Dec 2011 20:07:57 -0700] INFO: *** Chef 0.10.8 ***
[Mon, 19 Dec 2011 20:07:57 -0700] INFO: Setting the run_list to ["recipe[my_thing]"] from JSON
[Mon, 19 Dec 2011 20:07:57 -0700] INFO: Run List is [recipe[my_thing]]
[Mon, 19 Dec 2011 20:07:57 -0700] INFO: Run List expands to [my_thing]
[Mon, 19 Dec 2011 20:07:57 -0700] INFO: Starting Chef Run for guineapig
[Mon, 19 Dec 2011 20:07:57 -0700] INFO: Running start handlers
[Mon, 19 Dec 2011 20:07:57 -0700] INFO: Start handlers complete.
[Mon, 19 Dec 2011 20:07:57 -0700] INFO: Processing log[Im running Chef!] action write (my_thing::default line 1)
[Mon, 19 Dec 2011 20:07:57 -0700] INFO: Im running Chef!
[Mon, 19 Dec 2011 20:07:57 -0700] INFO: Processing file[/tmp/testfile] action create (my_thing::default line 5)
[Mon, 19 Dec 2011 20:07:57 -0700] INFO: file[/tmp/testfile] created file /tmp/testfile
[Mon, 19 Dec 2011 20:07:57 -0700] INFO: file[/tmp/testfile] mode changed to 600
[Mon, 19 Dec 2011 20:07:57 -0700] INFO: Processing file[/etc/nologin] action create (my_thing::default line 9)
[Mon, 19 Dec 2011 20:07:57 -0700] INFO: file[/etc/nologin] created file /etc/nologin
[Mon, 19 Dec 2011 20:07:57 -0700] INFO: Processing package[apache2] action install (my_thing::default line 14)
[Mon, 19 Dec 2011 20:08:14 -0700] INFO: package[apache2] installed version 2.2.14-5ubuntu8.7
[Mon, 19 Dec 2011 20:08:14 -0700] INFO: Processing service[apache2] action start (my_thing::default line 16)
[Mon, 19 Dec 2011 20:08:14 -0700] INFO: Chef Run complete in 16.595604314 seconds
[Mon, 19 Dec 2011 20:08:14 -0700] INFO: Running report handlers
[Mon, 19 Dec 2011 20:08:14 -0700] INFO: Report handlers complete
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment