- Chef uses popular Ruby language to create a domain-specific language.
- Chef does not make assumptions on the current status of a node. It uses its mechanisms to get the current status of machine.
- Chef is ideal for deploying and managing the cloud server, storage, and software.
Chef works on a three-tier client server model
- Chef Workstation
- Chef Server
- Chef Nodes (contain ohai)
- It is a directory where all cookbook are stored.
- Directory name should be cookbooks
- To create cookbook inside cookbooks don't create directly, use chef command to generate cookbook.
chef generate cookbook <cookbookname>
Recipe is the file where all ruby code is written.Never create file manual or with touch or any other command. Use chef command to create recipe file.
create recipe being in cookbook directory
chef generate recipe <recipename>
Ex- vi democookbook/recipes/demorecipe.rb
chef exec ruby -c <democookbook/recipes/demorecipe.rb>
We run chef-client to apply recipe to bring node into desired state.
chef-client -zr "recipe[<cookbookname>::<recipename>"
TO run the recipes in a sequence order that use mention in a run list. With this process , we can run multiple recipes, but the condition is *** there must be only one Recipe from one cookbook ***.
chef-client -zr "recipe[<cookbook1>::<recipename>],recipe[<cookbook2>::<recipename>]"
To run multiply recipe of same cookbook: - we need to import all the necessary recipes inside default.rb recipe. - imported recipes should be of same cookbook.
include_recipe "::"
Firstly need to make account in manage chef io Then download chef starter kit and extract directory(chef repo). *** Alway work indise chef-repo ***
Attaching a node to chef server is called bootstraping
knife ssl check
knife cookbook upload <cookbookName>
knife cookbook list
knife bootstrap <PrivateIpaddressOfNode> --ssh-user <user> --sudo -i <nodeKey> -N <NameOfNodeYouWantToCall>
knife node list
Here ,we set recipe for each node or more node depending upto needs.Only that recipe will be run in set node.If there is any changes/updates in setted recipe then node will take that changes and run recipe.But other than this recipe if any other recipes are updated/changed there will be no action performed by set node.
knife node run_list set <NameOfNodeWeGaveNAmeToNode> "recipe[<cookbookName>::<recipeNAme>]"
knife node show <NameOfNodeWeGaveNAmeToNode>
After completing all the step above ** chef Architecture is partially automated ** to run recipe in node.We need run command
chef-client
in node.
Go to node and configure /etc/crontab
vi /etc/crontab
After running this CMD new console will open.Just write
* * * * * <userName> chef-client
Here, each star have it's own meaning.Inside crontab there is explaned meaning of each *
- defines the pulling period of chef-client
Now as we have configured node.Now there is no need to manual run chef-client in node.As we update/change in cookbook recipe node will pull that recipe and run in node.
*** Yet there is no Complete automation ***
If new recipe is created then again we need to run_list for recipe for each desired node. To solve this problem roles comes into the picture. Concept is attach role as run_list after any recipe you need to attach just put inside role,That's it.
Some important command
To delete cookbook from server
knife cookbook delete <cookbookName> -y
similary to delete node from server
knife node delete <nodeName> -y
similary to delete clients from chef-server
knife client delete <clientName> -y
To see list of roles
knife role list
To delete roles
knife role delete <roleName>
*** To upload role on server
knife role from file roles/<filename>.rb
Note : Whatever recipe we have included in role file upload that cookbook also in server.
attaching role run list to node
knife node run_list set <NameOfNodeWeGaveNAmeToNode> "role[filename]"
Now it is fully automated. *END