Chef Cheat Sheet
General
Chef Dry Run
chef-client -Fmin --why-run
List Facts
ohai
Bootstrap Chef client
knife bootstrap <FQDN/IP>
Change Chef Run List
knife node run_list <add|remove> <node> <cookbook>::<recipe>
Runlist Status
knife status --run-list
knife status "role:webserver" --run-list
Nodes and Roles
List Node Info
knife node show <node>
List Nodes per Role
knife search node 'roles:<role name>'
Load role from file
knife role from file <file> [<file> [...]]
Data Bags
Load data bag from file
knife data bag from file <data bag name> <file>
knife + SSH
knife ssh -a ipaddress name:server1 "chef-client"
you can also use patterns:
knife ssh -a ipaddress name:www* "uptime"
Debugging
Inheritance
Debugging Attribute Inheritance
# Invoke chef shell in attribute mode
chef-shell -z
chef > attributes
chef:attributes >
# Query attributes examples
chef:attributes > default["authorized_keys"]
[...]
chef:attributes > node["packages"]
[...]
Editing Files
using a Script resource.
bash "some_commands" do
user "root"
cwd "/tmp"
code <<-EOT
echo "alias rm='rm -i'" >> /root/.bashrc
EOT
end
Misc
- Hardening cookbook
- Drift Detection Cookbook
- Fix RabbitMQ 100% CPU usage
- Exporting Nagios Hostgroups
- Chef - Manage Amazon EC2 instances
- Chef - Tutorial on how to Setup Nagios in EC2
Chef Enterprise - Push Jobs (using the Push Cookbook)
knife job start ... knife job list knife node status ...