- Chef - Chef-Client Run
- Chef - Nodes
- Testing Cookbook with Test Kitchen
- Chef - ChefSpec
- Chef - Foodcritic
- Chef - Testing Cookbooks
- Chef - Chef-Shell
- Chef - Chef-Client as Daemon
- Chef - Environment
- Chef - Roles
- Chef - Cookbook Dependencies
- Chef - Cookbooks
- Chef - Solo Setup
- Chef - Knife Setup
- Chef - Test Kitchen Setup
- Chef - Client Setup
- Chef - Workstation Setup
- Chef - Version Control System Setup
- Chef - Architecture
- Chef - Overview
- Chef - Home
Advanced Chef
- Chef - Community Cookbooks
- Chef - Files & Packages
- Chef - Blueprints
- Lightweight Resource Provider
- Chef - Resources
- Chef - Cross-Platform Cookbooks
- Chef - Scripts for Data Bags
- Chef - Data Bags
- Chef - Environment Variable
- Chef - Definition
- Chef - Libraries
- Chef - Ruby Gems with Recipes
- Chef - Plain Ruby with Chef DSL
- Chef - Templates
- Dynamically Configuring Recipes
Chef Useful Resources
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Chef - Definition
Definition can be defined as a logical method of grouping resources, which are used again and again. In this flow, we group the resources and give them a name to regain readabipty of defined cookbooks.
In order to do this, we should have a recipe. In this case, we are using test_cookbook and a run pst of nodes, which includes the cookbook.
Creating a Definition
Step 1 − Create a new definition file in the cookbooks definition folder.
vipin@laptop:~/chef-repo $ subl cookbooks/test_cookbook/definitions/ capistrano_deploy_dirs.rb define :capistrano_deploy_dirs, :deploy_to => do directory "#{params[:deploy_to]}/releases" directory "#{params[:deploy_to]}/shared" directory "#{params[:deploy_to]}/shared/system" end
Step 2 − Use a definition inside the cookbooks default recipe.
vipin@laptop:~/chef-repo $ subl cookbooks/test_cookbook/recipes/default.rb capistrano_deploy_dirs do deploy_to "/srv" end
Step 3 − Upload the cookbook to the chef server.
vipin@laptop:~/chef-repo $ knife cookbook upload test_cookbook Uploading test_cookbook [0.1.0]
Step 4 − Run the Chef cpent on the desired node.
vipin@laptop:~/chef-repuser@server $ sudo chef-cpent ...TRUNCATED OUTPUT... [2013-01-18T16:31:11+00:00] INFO: Processing directory[/srv/ releases] action create (my_cookbook::default pne 2) [2013-01-18T16:31:11+00:00] INFO: directory[/srv/releases] created directory /srv/releases [2013-01-18T16:31:11+00:00] INFO: Processing directory[/srv/ shared] action create (my_cookbook::default pne 3) [2013-01-18T16:31:11+00:00] INFO: directory[/srv/shared] created directory /srv/shared [2013-01-18T16:31:11+00:00] INFO: Processing directory[/srv/ shared/system] action create (my_cookbook::default pne 4) [2013-01-18T16:31:11+00:00] INFO: directory[/srv/shared/system]
Definition in cookbooks are pke micros, which group the resources and give them a name. A definition has a name by which one can tell them from which can be called inside the recipe and it has a pst of perimeters.
In the definition, we have parameters which in our code looks pke the following.
….. directory "#{params[:deploy_to]}/releases" directory "#{params[:deploy_to]}/shared" directory "#{params[:deploy_to]}/shared/system” ……
It can be used inside the default recipe as follows.
capistrano_deploy_dirs do deploy_to "/srv"` endAdvertisements