Basic configuration
How to knife the chef
- Uploading cookbooks
knife cookbook upload -a
Will upload all cookbooks - Updating cookbooks from source
knife cookbook site vendor cookbook_name # e.g. jenkins
- Adding roles
knife role from file path/filename.ext #e.g. roles/jenkins_node.json
Checking the diff between chef and local repository
Using the knife-essentials gem enables us to check the diff of cookbooks, roles, definitions, etc.
Usage: knife diff cookbooks/name
Installing cookbooks from scratch
-
Installing a cookbook found on gitbhub. Using this gem 'knife-github-cookbooks'. If the repo was https://github.com/fnichol/chef-jenkins
knife cookbook github install fnichol/chef-jenkins
-
Installing cookbooks from http://community.opscode.com/. If the cookbook was runit
knife cookbook site install runit
Managing nodes
- Delete instance from AWS and node/client from chef
knife ec2 server delete i-be7e6fc3 -N "Jenkins-Node-030" --purge
- List instances
knife ec2 server list
- add role or recipe to all nodes
for n in \`knife node list`; do knife node run_list add $n 'role[lpos_default]' done
- Run arbitrary command on boxes with role
knife ssh -xubuntu "role:jenkins_agent" "sudo chef-client"
- Run arbitrary command on all nodes
knife ssh -xubuntu "name:*" "sudo chef-client"
- Get last number of Jenkins node
knife node list | grep Jenkins-Node- | tail -n1 | cut -d '-' -f3
- Delete all the jenkins agents
for node in $(knife search node "ohai_time:[* TO $(date -v-16H +%s)]" -i); do knife client delete $node knife node delete $node done
- delete all nodes
for node in `knife ec2 server list | grep 'i-' | cut -d ' ' -f 1`; do knife ec2 server delete $node --purge -y done