- chef-apply - runs a single recipe from the command line
- chef-client - uploads policy on your node. Typically downloads and runs the latest Chef code from the Chef server. However, possible to run in the local mode
- kitchen - enabled to run cookbooks in a temporary environment. Steps: kitchen create -> kitchen converge -> kitchen login -> verify -> kitchen destroy
- knife - enables you to communicate with the Chef server from your workstation.
- berks - dependency management tool
Apply particular recipe
$ chef-apply file_name.rp
or
$ chef-client --local-mode hello.rb
To reference a cookbook from inside another, put it's name into metadata.rb file, e.g. put depends 'apt', '~> 4.0', then include it into recipe recipes/default.rb include_recipe 'apt::default'
Create a cookbook
$ chef generate cookbook cookbooks/learn_chef_apache
Generates new template inside given cookbook
$ chef generate template cookbooks/learn_chef_apache2 index.html
Write recipe in the file 'COOKBOOK_NAME/recipes/default.rba'
Run the cookbook
$ sudo chef-client --local-mode --runlist 'recipe[learn_chef_apache2]'
Create the recipe
$ chef generate recipe cookbooks/awesome_customers_ubuntu firewall
Create the custom attributes file
$ chef generate attribute cookbooks/awesome_customers_ubuntu default
#Knife Use file ./chef/knife.rb for Knife configuration Download cookbook from supermaket.chef.io
$ knife cookbook site download COOKBOOK_NAME_IN_supermarket.chef.io
Upload cookbook to the Chef server
$ knife cookbook upload COOKBOOK_NAME
Bootstrap node
$ knife bootstrap NODE_IP_ADDRESS --ssh-user USER --ssh-password 'PASSWORD' --sudo -use-sudo-password -N cnode1 --run-list 'recipe[COOKBOOK_NAME]' -E ENVIRONMENT_NAME -V
Node list (inside folder where is unzipped starter kit)
$ knife node list
Particular node
$ knife node show NODE_NAME
Upload cookbook to node
knife ssh localhost --ssh-port 2200 'sudo chef-client' --manual-list --ssh-user vagrant --identity-file /home/vytautas/learn-chef/chef-server/.vagrant/machines/node1-ubuntu/virtualbox/private_key
knife ssh 'name:NODE_NAME' 'sudo chef-client' --ssh-user root --identity-file ~/.ssh/id_rsa --attribute ipaddress --run-list='cookbook[COOKBOOK_NAME]'
Set up a file named Berksfile.lock that helps Test Kitchen manage dependent cookbooks
$ berks install
Upload cookbooks and dependencies to the Chef server
$ SSL_CERT_FILE='.chef/trusted_certs/chef-server_test.crt' berks upload
Upload role to Chef server
$ knife role from file roles/web.json
Command chef generate cookbook which creates cookbooks, creates file named .kitchen.yml provisioner chef_zero enables you to mimic a Chef server environment on the local machine
See what's in the kitchen:
$ kitchen list
Create the instance
$ kitchen create
$ kitchen converge
Test kitchen runs chef-client on the instance. When chef-client run completes cuccessfully, Test Kitchen exits with code 0 (to check exit code run echo $?)
Login using ssh
$ kitchen login
Execute single command
$ kitchen exec -c 'wget -qO- localhost
Destroy instance
$ kitchen destroy
Check Vagrant version
$ vagrant --version
Download specific Vagrant box
$ vagrant box add bento/ubuntu-14.04 --provider=virtualbox
Create configuration file named Vagrantfile
$ vagrant init bento/ubuntu-14.04
Bring up an instance (create and configure VM instance)
$ vagrant up
Connect to the instance
vagrant ssh
Cleaning up
$ vagrant destroy --force