1. Runs the Chef client, which applies the configuration to the node.
chef-client –zr " recipe[apache-cookbook::recipe3]"
Multiple recipes execute:
chef-client –zr " recipe[test-cookbook::default], recipe[apache-cookbook::default]"
2. The Swiss Army knife of Chef, used for managing nodes, cookbooks, roles, environments, and more.
knife cookbook upload apache-cookbook
Check uploaded files on server:
Run list according to server (only recipes we want to run on a particular server will run):
knife node run-list set node1 " recipe[apache-cookbook::apache-recipe]"
knife cookbook delete < cookbook name> -y
To check the number of client nodes connected to the server:
Clients present on nodes that are connected to the server:
To delete a connected client from the server:
knife role delete < role-name> -y
knife role delete < role-name> -y
Upload the role on Chef server:
knife role from file /devops.rb
To check roles stored in Chef server:
3. Runs Chef in a standalone mode without a Chef server, useful for testing or simple deployments.
sudo chef-solo -c solo.rb -j solo.json
4. Interactive shell for exploring the Chef server API and testing recipes.
5. Applies a single recipe from the command line without a Chef server.
Example usage (only when Chef server is not available):
6. Manages encrypted data bags using keys from a key/value store.
Create a vault and add a file:
chef-vault create my_vault my_item --json ' {"username": "admin", "password": "s3cr3t"}'
To add an existing file to the vault:
chef-vault update my_vault my_item --json ' {"username": "new_admin", "password": "new_s3cr3t"}'
To check files inside a vault:
chef-vault show my_vault my_item
To delete a file from the vault:
chef-vault delete my_vault my_item
7. Controls the Chef server, including starting, stopping, reconfiguring, and managing services.
8. Bootstraps a new node to be managed by Chef.
Example usage (connect node with server):
knife bootstrap < private-ip> --ssh-user ec2-user --sudo -i node-key.pem -n node1
9. Command to ignore recipes which we don’t want to commit, similar to .gitignore.
10. Testing cookbook to verify proper functionality without deploying on a live server ("demo run").
11. Information like name, version, author, etc., of the cookbook.
12. Use this for opening existing files for changes.
13. Information about the usage of the cookbook.
14. Here we write code for recipes.
Command to create a recipe:
chef generate recipe < recipe name>
15. Create a cookbook to store recipes.
Command to create a cookbook:
chef generate cookbook < cookbook name>
Command to test a small part of the script (unit):
chef spec ruby -c test-cookbook/recipe/test-recipe.rb
17. Integration testing (entire).
Command to run integration tests:
chef exec ruby -c test-cookbook/recipe/recipe2.rb