introduction to chef
TRANSCRIPT
![Page 1: Introduction to chef](https://reader035.vdocument.in/reader035/viewer/2022081605/58b8a4ce1a28abc06d8b5c21/html5/thumbnails/1.jpg)
INTRODUCTION TO CHEF – BY DAMITH KOTHALAWALA ,MBCS Content AcknowledgementMost of the internal content are from https://docs.chef.io CHEF™ logo is a registered trademark of Chef.ioPlease do not copy/redistribute without taking prior permission from chef.io
![Page 2: Introduction to chef](https://reader035.vdocument.in/reader035/viewer/2022081605/58b8a4ce1a28abc06d8b5c21/html5/thumbnails/2.jpg)
About Me I am Damith Rushika Kothalawala and I work for Pearson as a Technical Specialist. (Application Solutions Engineering)
I currently owns Basic Chef Fluency Badge from CHEF Certification + 4 other Certifications from different vendors.
Find more about me @: https://www.linkedin.com/in/damithkothalawala/
![Page 3: Introduction to chef](https://reader035.vdocument.in/reader035/viewer/2022081605/58b8a4ce1a28abc06d8b5c21/html5/thumbnails/3.jpg)
Official Approval from CHEF.io
(C) DAMITH RUSHIKA KOTHALAWALA 2017
![Page 4: Introduction to chef](https://reader035.vdocument.in/reader035/viewer/2022081605/58b8a4ce1a28abc06d8b5c21/html5/thumbnails/4.jpg)
What is ChefChef is an open-source systems management and cloud infrastructure automation framework created by Opscode.
(C) DAMITH RUSHIKA KOTHALAWALA 2017
![Page 5: Introduction to chef](https://reader035.vdocument.in/reader035/viewer/2022081605/58b8a4ce1a28abc06d8b5c21/html5/thumbnails/5.jpg)
Why named as Chef ??
(C) DAMITH RUSHIKA KOTHALAWALA 2017
![Page 6: Introduction to chef](https://reader035.vdocument.in/reader035/viewer/2022081605/58b8a4ce1a28abc06d8b5c21/html5/thumbnails/6.jpg)
Traditional Chef1. Chef creates new recipes after undergoing several experimenting with food.
2. Chef has a book with his favorite recipes, which is called a “Cook Book”
3. One Chef can have many “Cook Books” which contains various types of food.❖ Chinese Food Cookbook❖ Cookbook of Soups❖ Cookbook of Sauces❖ Traditional Sri Lankan Cuisine Cookbook
4. There can be relationships between two Cookbooks when its comes to food preparation❖ Chef may have to refer one recipe of Cookbook of Sauces when making a soup from Cookbook of Soups➢ Ex. Sometimes you need Soya Sauce to prepare a “Tom Yum” Soup.
5. Chef needs a Kitchen & Knife to do his preparation of food.
(C) DAMITH RUSHIKA KOTHALAWALA 2017
![Page 7: Introduction to chef](https://reader035.vdocument.in/reader035/viewer/2022081605/58b8a4ce1a28abc06d8b5c21/html5/thumbnails/7.jpg)
So what is the similarity ? OpsCode’s Chef does the same as a traditional Chef in theory, but OpsCode chef is for the system/infra automation.
Thinking about OpsCode’s chef this way will help you to understand its use well.
(C) DAMITH RUSHIKA KOTHALAWALA 2017
![Page 8: Introduction to chef](https://reader035.vdocument.in/reader035/viewer/2022081605/58b8a4ce1a28abc06d8b5c21/html5/thumbnails/8.jpg)
(C) DAMITH RUSHIKA KOTHALAWALA 2017
Let's discuss about CI/CD & DevOps
![Page 9: Introduction to chef](https://reader035.vdocument.in/reader035/viewer/2022081605/58b8a4ce1a28abc06d8b5c21/html5/thumbnails/9.jpg)
CI/CD Continuous Delivery (CD) is the practice of using automation to produce releasable software in short iterations, allowing teams to ship working software more frequently. The recent emphasis on continuous integration, built-in testing, constant monitoring, and analytics feedback all point towards an overall trend in the software industry: increasing the ability to react. As organizations explore what these changes mean for them, they invariably discover continuous delivery which is commonly known as CD.
(C) DAMITH RUSHIKA KOTHALAWALA 2017
![Page 10: Introduction to chef](https://reader035.vdocument.in/reader035/viewer/2022081605/58b8a4ce1a28abc06d8b5c21/html5/thumbnails/10.jpg)
DevOPS DevOps (a clipped compound of "software DEVelopment" and "information technology OPerationS") is a term used to refer to a set of practices that emphasize the collaboration and communication of both software developers and information technology (IT) professionals while automating the process of software delivery and infrastructure changes – Wikipedia
(C) DAMITH RUSHIKA KOTHALAWALA 2017
![Page 11: Introduction to chef](https://reader035.vdocument.in/reader035/viewer/2022081605/58b8a4ce1a28abc06d8b5c21/html5/thumbnails/11.jpg)
Let's go back to …
(C) DAMITH RUSHIKA KOTHALAWALA 2017
![Page 12: Introduction to chef](https://reader035.vdocument.in/reader035/viewer/2022081605/58b8a4ce1a28abc06d8b5c21/html5/thumbnails/12.jpg)
A Single Practical activity is better than 1000 words.. Let’s start learning by doing it ;-)
(C) DAMITH RUSHIKA KOTHALAWALA 2017
![Page 13: Introduction to chef](https://reader035.vdocument.in/reader035/viewer/2022081605/58b8a4ce1a28abc06d8b5c21/html5/thumbnails/13.jpg)
Download ChefDK (Development Kit) Please navigate to https://downloads.chef.io/chefdk then download relevant installer for your OS
(C) DAMITH RUSHIKA KOTHALAWALA 2017
![Page 14: Introduction to chef](https://reader035.vdocument.in/reader035/viewer/2022081605/58b8a4ce1a28abc06d8b5c21/html5/thumbnails/14.jpg)
Let’s verify your installation
(C) DAMITH RUSHIKA KOTHALAWALA 2017
![Page 15: Introduction to chef](https://reader035.vdocument.in/reader035/viewer/2022081605/58b8a4ce1a28abc06d8b5c21/html5/thumbnails/15.jpg)
Let’s write recipes As in ordinary cooking, you may have to do some R&D before you write a perfect recipe for your cookbook. Let's start by writing one.
Something to know before We Start
o Chef software itself is written using a programming language called Rubyo But you do not need to know about ruby to start working with chefo Knowledge about a single programming language would be enough to work with Chef’s recipe files.
(C) DAMITH RUSHIKA KOTHALAWALA 2017
![Page 16: Introduction to chef](https://reader035.vdocument.in/reader035/viewer/2022081605/58b8a4ce1a28abc06d8b5c21/html5/thumbnails/16.jpg)
hello.rb
(C) DAMITH RUSHIKA KOTHALAWALA 2017
![Page 17: Introduction to chef](https://reader035.vdocument.in/reader035/viewer/2022081605/58b8a4ce1a28abc06d8b5c21/html5/thumbnails/17.jpg)
Let’s run hello.rb recipe
(C) DAMITH RUSHIKA KOTHALAWALA 2017
![Page 18: Introduction to chef](https://reader035.vdocument.in/reader035/viewer/2022081605/58b8a4ce1a28abc06d8b5c21/html5/thumbnails/18.jpg)
Let’s review what we have done We have just created “File Resource” called /tmp/hello.txt using chef
What is a Resource??
(C) DAMITH RUSHIKA KOTHALAWALA 2017
![Page 19: Introduction to chef](https://reader035.vdocument.in/reader035/viewer/2022081605/58b8a4ce1a28abc06d8b5c21/html5/thumbnails/19.jpg)
Resource A resource is a statement of configuration policy. It describes the desired state of an element of your infrastructure and the steps needed to bring that item to the desired state.
Source https://docs.chef.io/resources.html
As you know, anything is a file on
Anything on a system is a Resource for
(C) DAMITH RUSHIKA KOTHALAWALA 2017
![Page 20: Introduction to chef](https://reader035.vdocument.in/reader035/viewer/2022081605/58b8a4ce1a28abc06d8b5c21/html5/thumbnails/20.jpg)
Resource Definition
(C) DAMITH RUSHIKA KOTHALAWALA 2017
file ‘/tmp/hello.txt' do
content 'Hello, world!' end
The TYPE named NAME should be ACTION'd with PROPERTIES
![Page 21: Introduction to chef](https://reader035.vdocument.in/reader035/viewer/2022081605/58b8a4ce1a28abc06d8b5c21/html5/thumbnails/21.jpg)
Example Resources
(C) DAMITH RUSHIKA KOTHALAWALA 2017
![Page 22: Introduction to chef](https://reader035.vdocument.in/reader035/viewer/2022081605/58b8a4ce1a28abc06d8b5c21/html5/thumbnails/22.jpg)
What is chef-client chef-client is an agent that runs locally on every node that is under the management of Chef.
When a chef-client runs, it will perform all of the steps that is required to bring the node into the expected state.
Source: https://docs.chef.io/chef_client.html
(C) DAMITH RUSHIKA KOTHALAWALA 2017
![Page 23: Introduction to chef](https://reader035.vdocument.in/reader035/viewer/2022081605/58b8a4ce1a28abc06d8b5c21/html5/thumbnails/23.jpg)
--local-mode (or -z) chef-client's default mode attempts to contact a Chef Server and ask for the recipes to run for the given node.
We override the behavior in order to have it work in the local mode.
(C) DAMITH RUSHIKA KOTHALAWALA 2017
![Page 24: Introduction to chef](https://reader035.vdocument.in/reader035/viewer/2022081605/58b8a4ce1a28abc06d8b5c21/html5/thumbnails/24.jpg)
Recap: Apply the hello Recipe
(C) DAMITH RUSHIKA KOTHALAWALA 2017
What would happen if the 'hello.txt' file contents were modified?
![Page 25: Introduction to chef](https://reader035.vdocument.in/reader035/viewer/2022081605/58b8a4ce1a28abc06d8b5c21/html5/thumbnails/25.jpg)
Test and Repair
(C) DAMITH RUSHIKA KOTHALAWALA 2017
![Page 26: Introduction to chef](https://reader035.vdocument.in/reader035/viewer/2022081605/58b8a4ce1a28abc06d8b5c21/html5/thumbnails/26.jpg)
(C) DAMITH RUSHIKA KOTHALAWALA 2017
What would happen if the file • permissions (mode)
• Owner• or group changed?
Have we define a policy for these properties?
![Page 27: Introduction to chef](https://reader035.vdocument.in/reader035/viewer/2022081605/58b8a4ce1a28abc06d8b5c21/html5/thumbnails/27.jpg)
chef-client’s work on Test & Repair
(C) DAMITH RUSHIKA KOTHALAWALA 2017
chef-client takes an action only when it needs to. Think of it as test and repair. Chef looks at the current state of each resource and takes an action only when that resource is out of policy.
![Page 28: Introduction to chef](https://reader035.vdocument.in/reader035/viewer/2022081605/58b8a4ce1a28abc06d8b5c21/html5/thumbnails/28.jpg)
Let’s change properties of hello.txt1. Read https://docs.chef.io/resources.html
2. Discover the file resource's:◦ default action.◦ default values for mode, owner, and group.
3. Update the file policy in "hello.rb" to: The file named 'hello.txt' should be created with the content 'Hello,
world!', mode '0644', owner is 'root', and group is 'root'.
(C) DAMITH RUSHIKA KOTHALAWALA 2017
![Page 29: Introduction to chef](https://reader035.vdocument.in/reader035/viewer/2022081605/58b8a4ce1a28abc06d8b5c21/html5/thumbnails/29.jpg)
New hello.rb file
(C) DAMITH RUSHIKA KOTHALAWALA 2017
![Page 30: Introduction to chef](https://reader035.vdocument.in/reader035/viewer/2022081605/58b8a4ce1a28abc06d8b5c21/html5/thumbnails/30.jpg)
Learn more on resources. Likewise you can do many things with recipes when it comes to a real deployment. So please try to refer chef’s documentation and make some changes on your local system.
(C) DAMITH RUSHIKA KOTHALAWALA 2017
![Page 31: Introduction to chef](https://reader035.vdocument.in/reader035/viewer/2022081605/58b8a4ce1a28abc06d8b5c21/html5/thumbnails/31.jpg)
Traditional Cookbook
As discussed, a real world cookbook is a collection of recipes which can be
1. An Independent recipe❑ ex. Steamed Rice Recipe
2. Related to one or more recipes on same cookbook ❑ ex. Fried Rice Recipe (You need streamed rice 1st to make
fried rice)
3. Related to one or more recipes on some other Cookbooks❑ ex. Chinese Chopsuey Rice (You need. Multiple recipes
from many cookbooks if you make it without using market products)
(C) DAMITH RUSHIKA KOTHALAWALA 2017
![Page 32: Introduction to chef](https://reader035.vdocument.in/reader035/viewer/2022081605/58b8a4ce1a28abc06d8b5c21/html5/thumbnails/32.jpg)
(C) DAMITH RUSHIKA KOTHALAWALA 2017
HUNGRY?
![Page 33: Introduction to chef](https://reader035.vdocument.in/reader035/viewer/2022081605/58b8a4ce1a28abc06d8b5c21/html5/thumbnails/33.jpg)
OpsCode’s Chef Cookbook A Chef cookbook is the fundamental unit of configuration and policy distribution.
Each cookbook defines a scenario, such as everything needed to install and configure MySQL, and then it contains all of the components that are required to support that scenario.
Read the first three paragraphs here: http://docs.chef.io/cookbooks.html
(C) DAMITH RUSHIKA KOTHALAWALA 2017
![Page 34: Introduction to chef](https://reader035.vdocument.in/reader035/viewer/2022081605/58b8a4ce1a28abc06d8b5c21/html5/thumbnails/34.jpg)
Cookbook
❑Recipes that specify the resources to use and the order in which they are to be applied
❑ Attribute values
❑ File distributions
❑ Templates
❑ Extensions to Chef, such as libraries, definitions, and custom resources
❑ Version Control
(C) DAMITH RUSHIKA KOTHALAWALA 2017
![Page 35: Introduction to chef](https://reader035.vdocument.in/reader035/viewer/2022081605/58b8a4ce1a28abc06d8b5c21/html5/thumbnails/35.jpg)
Common Components of Cookbooks1. README2. metadata 3. Recipes4. testing directories (spec + test)
(C) DAMITH RUSHIKA KOTHALAWALA 2017
![Page 36: Introduction to chef](https://reader035.vdocument.in/reader035/viewer/2022081605/58b8a4ce1a28abc06d8b5c21/html5/thumbnails/36.jpg)
Let’s start with cookbook creation
(C) DAMITH RUSHIKA KOTHALAWALA 2017
Acknowledgement: This section is entirely copied from a chef.io training
![Page 37: Introduction to chef](https://reader035.vdocument.in/reader035/viewer/2022081605/58b8a4ce1a28abc06d8b5c21/html5/thumbnails/37.jpg)
(C) DAMITH RUSHIKA KOTHALAWALA 2017
![Page 38: Introduction to chef](https://reader035.vdocument.in/reader035/viewer/2022081605/58b8a4ce1a28abc06d8b5c21/html5/thumbnails/38.jpg)
(C) DAMITH RUSHIKA KOTHALAWALA 2017
![Page 39: Introduction to chef](https://reader035.vdocument.in/reader035/viewer/2022081605/58b8a4ce1a28abc06d8b5c21/html5/thumbnails/39.jpg)
(C) DAMITH RUSHIKA KOTHALAWALA 2017
![Page 40: Introduction to chef](https://reader035.vdocument.in/reader035/viewer/2022081605/58b8a4ce1a28abc06d8b5c21/html5/thumbnails/40.jpg)
(C) DAMITH RUSHIKA KOTHALAWALA 2017
![Page 41: Introduction to chef](https://reader035.vdocument.in/reader035/viewer/2022081605/58b8a4ce1a28abc06d8b5c21/html5/thumbnails/41.jpg)
(C) DAMITH RUSHIKA KOTHALAWALA 2017
![Page 42: Introduction to chef](https://reader035.vdocument.in/reader035/viewer/2022081605/58b8a4ce1a28abc06d8b5c21/html5/thumbnails/42.jpg)
(C) DAMITH RUSHIKA KOTHALAWALA 2017
![Page 43: Introduction to chef](https://reader035.vdocument.in/reader035/viewer/2022081605/58b8a4ce1a28abc06d8b5c21/html5/thumbnails/43.jpg)
(C) DAMITH RUSHIKA KOTHALAWALA 2017
![Page 44: Introduction to chef](https://reader035.vdocument.in/reader035/viewer/2022081605/58b8a4ce1a28abc06d8b5c21/html5/thumbnails/44.jpg)
(C) DAMITH RUSHIKA KOTHALAWALA 2017
![Page 45: Introduction to chef](https://reader035.vdocument.in/reader035/viewer/2022081605/58b8a4ce1a28abc06d8b5c21/html5/thumbnails/45.jpg)
(C) DAMITH RUSHIKA KOTHALAWALA 2017
![Page 46: Introduction to chef](https://reader035.vdocument.in/reader035/viewer/2022081605/58b8a4ce1a28abc06d8b5c21/html5/thumbnails/46.jpg)
(C) DAMITH RUSHIKA KOTHALAWALA 2017
![Page 47: Introduction to chef](https://reader035.vdocument.in/reader035/viewer/2022081605/58b8a4ce1a28abc06d8b5c21/html5/thumbnails/47.jpg)
(C) DAMITH RUSHIKA KOTHALAWALA 2017
![Page 48: Introduction to chef](https://reader035.vdocument.in/reader035/viewer/2022081605/58b8a4ce1a28abc06d8b5c21/html5/thumbnails/48.jpg)
(C) DAMITH RUSHIKA KOTHALAWALA 2017
![Page 49: Introduction to chef](https://reader035.vdocument.in/reader035/viewer/2022081605/58b8a4ce1a28abc06d8b5c21/html5/thumbnails/49.jpg)
(C) DAMITH RUSHIKA KOTHALAWALA 2017
![Page 50: Introduction to chef](https://reader035.vdocument.in/reader035/viewer/2022081605/58b8a4ce1a28abc06d8b5c21/html5/thumbnails/50.jpg)
(C) DAMITH RUSHIKA KOTHALAWALA 2017
![Page 51: Introduction to chef](https://reader035.vdocument.in/reader035/viewer/2022081605/58b8a4ce1a28abc06d8b5c21/html5/thumbnails/51.jpg)
(C) DAMITH RUSHIKA KOTHALAWALA 2017
![Page 52: Introduction to chef](https://reader035.vdocument.in/reader035/viewer/2022081605/58b8a4ce1a28abc06d8b5c21/html5/thumbnails/52.jpg)
(C) DAMITH RUSHIKA KOTHALAWALA 2017
![Page 53: Introduction to chef](https://reader035.vdocument.in/reader035/viewer/2022081605/58b8a4ce1a28abc06d8b5c21/html5/thumbnails/53.jpg)
(C) DAMITH RUSHIKA KOTHALAWALA 2017
![Page 54: Introduction to chef](https://reader035.vdocument.in/reader035/viewer/2022081605/58b8a4ce1a28abc06d8b5c21/html5/thumbnails/54.jpg)
(C) DAMITH RUSHIKA KOTHALAWALA 2017
![Page 55: Introduction to chef](https://reader035.vdocument.in/reader035/viewer/2022081605/58b8a4ce1a28abc06d8b5c21/html5/thumbnails/55.jpg)
(C) DAMITH RUSHIKA KOTHALAWALA 2017
![Page 56: Introduction to chef](https://reader035.vdocument.in/reader035/viewer/2022081605/58b8a4ce1a28abc06d8b5c21/html5/thumbnails/56.jpg)
(C) DAMITH RUSHIKA KOTHALAWALA 2017
![Page 57: Introduction to chef](https://reader035.vdocument.in/reader035/viewer/2022081605/58b8a4ce1a28abc06d8b5c21/html5/thumbnails/57.jpg)
(C) DAMITH RUSHIKA KOTHALAWALA 2017
![Page 58: Introduction to chef](https://reader035.vdocument.in/reader035/viewer/2022081605/58b8a4ce1a28abc06d8b5c21/html5/thumbnails/58.jpg)
(C) DAMITH RUSHIKA KOTHALAWALA 2017
![Page 59: Introduction to chef](https://reader035.vdocument.in/reader035/viewer/2022081605/58b8a4ce1a28abc06d8b5c21/html5/thumbnails/59.jpg)
(C) DAMITH RUSHIKA KOTHALAWALA 2017
![Page 60: Introduction to chef](https://reader035.vdocument.in/reader035/viewer/2022081605/58b8a4ce1a28abc06d8b5c21/html5/thumbnails/60.jpg)
(C) DAMITH RUSHIKA KOTHALAWALA 2017
![Page 61: Introduction to chef](https://reader035.vdocument.in/reader035/viewer/2022081605/58b8a4ce1a28abc06d8b5c21/html5/thumbnails/61.jpg)
(C) DAMITH RUSHIKA KOTHALAWALA 2017
![Page 62: Introduction to chef](https://reader035.vdocument.in/reader035/viewer/2022081605/58b8a4ce1a28abc06d8b5c21/html5/thumbnails/62.jpg)
(C) DAMITH RUSHIKA KOTHALAWALA 2017
![Page 63: Introduction to chef](https://reader035.vdocument.in/reader035/viewer/2022081605/58b8a4ce1a28abc06d8b5c21/html5/thumbnails/63.jpg)
(C) DAMITH RUSHIKA KOTHALAWALA 2017
![Page 64: Introduction to chef](https://reader035.vdocument.in/reader035/viewer/2022081605/58b8a4ce1a28abc06d8b5c21/html5/thumbnails/64.jpg)
(C) DAMITH RUSHIKA KOTHALAWALA 2017
![Page 65: Introduction to chef](https://reader035.vdocument.in/reader035/viewer/2022081605/58b8a4ce1a28abc06d8b5c21/html5/thumbnails/65.jpg)
(C) DAMITH RUSHIKA KOTHALAWALA 2017
![Page 66: Introduction to chef](https://reader035.vdocument.in/reader035/viewer/2022081605/58b8a4ce1a28abc06d8b5c21/html5/thumbnails/66.jpg)
(C) DAMITH RUSHIKA KOTHALAWALA 2017
![Page 67: Introduction to chef](https://reader035.vdocument.in/reader035/viewer/2022081605/58b8a4ce1a28abc06d8b5c21/html5/thumbnails/67.jpg)
(C) DAMITH RUSHIKA KOTHALAWALA 2017
![Page 68: Introduction to chef](https://reader035.vdocument.in/reader035/viewer/2022081605/58b8a4ce1a28abc06d8b5c21/html5/thumbnails/68.jpg)
(C) DAMITH RUSHIKA KOTHALAWALA 2017
![Page 69: Introduction to chef](https://reader035.vdocument.in/reader035/viewer/2022081605/58b8a4ce1a28abc06d8b5c21/html5/thumbnails/69.jpg)
(C) DAMITH RUSHIKA KOTHALAWALA 2017
![Page 70: Introduction to chef](https://reader035.vdocument.in/reader035/viewer/2022081605/58b8a4ce1a28abc06d8b5c21/html5/thumbnails/70.jpg)
(C) DAMITH RUSHIKA KOTHALAWALA 2017
![Page 71: Introduction to chef](https://reader035.vdocument.in/reader035/viewer/2022081605/58b8a4ce1a28abc06d8b5c21/html5/thumbnails/71.jpg)
(C) DAMITH RUSHIKA KOTHALAWALA 2017
![Page 72: Introduction to chef](https://reader035.vdocument.in/reader035/viewer/2022081605/58b8a4ce1a28abc06d8b5c21/html5/thumbnails/72.jpg)
(C) DAMITH RUSHIKA KOTHALAWALA 2017
![Page 73: Introduction to chef](https://reader035.vdocument.in/reader035/viewer/2022081605/58b8a4ce1a28abc06d8b5c21/html5/thumbnails/73.jpg)
(C) DAMITH RUSHIKA KOTHALAWALA 2017
Let’s Come Back to Food
![Page 74: Introduction to chef](https://reader035.vdocument.in/reader035/viewer/2022081605/58b8a4ce1a28abc06d8b5c21/html5/thumbnails/74.jpg)
A recipe from BBC Food
http://www.bbc.co.uk/food/recipes/roastedtomatoandthym_93625
(C) DAMITH RUSHIKA KOTHALAWALA 2017
![Page 75: Introduction to chef](https://reader035.vdocument.in/reader035/viewer/2022081605/58b8a4ce1a28abc06d8b5c21/html5/thumbnails/75.jpg)
Most of the Recipes Cannot be Customized on the fly
This one serves only 4. What happen if you want to make it for 2 or 10 ?
But what if that recipe got an option to customize as per your requirement ? And adjust the recipe as per those variables
Ex. Please Enter Number of Servings You need 5 baking potatoes
(C) DAMITH RUSHIKA KOTHALAWALA 2017
5
![Page 76: Introduction to chef](https://reader035.vdocument.in/reader035/viewer/2022081605/58b8a4ce1a28abc06d8b5c21/html5/thumbnails/76.jpg)
Let’s Learn About Chef Node Attributes
(C) DAMITH RUSHIKA KOTHALAWALA 2017
![Page 77: Introduction to chef](https://reader035.vdocument.in/reader035/viewer/2022081605/58b8a4ce1a28abc06d8b5c21/html5/thumbnails/77.jpg)
Node Attribute DefinitionAn attribute is a specific detail about a node. Attributes are used by the chef-client to understand: ❑The current state of the node❑What the state of the node was at the end of the previous chef-client run❑What the state of the node should be at the end of the current chef-client run
Attributes are defined by:❑The state of the node itself❑Cookbooks (in attribute files and/or recipes)❑Roles❑Environments
(C) DAMITH RUSHIKA KOTHALAWALA 2017
![Page 78: Introduction to chef](https://reader035.vdocument.in/reader035/viewer/2022081605/58b8a4ce1a28abc06d8b5c21/html5/thumbnails/78.jpg)
Ohai Ohai is a tool that is used to detect attributes on a node, and then provide these attributes to the chef-client at the start of every chef-client run
(C) DAMITH RUSHIKA KOTHALAWALA 2017
![Page 79: Introduction to chef](https://reader035.vdocument.in/reader035/viewer/2022081605/58b8a4ce1a28abc06d8b5c21/html5/thumbnails/79.jpg)
Let’s execute ohai command
(C) DAMITH RUSHIKA KOTHALAWALA 2017
![Page 80: Introduction to chef](https://reader035.vdocument.in/reader035/viewer/2022081605/58b8a4ce1a28abc06d8b5c21/html5/thumbnails/80.jpg)
Details provided by ohai Ohai will gather almost everything about your system and present its collected data in JSON format.
Let's get some selected detail output
ohai memory/total
ohai memory/free
ohai cpu
ohai ipaddress
And etc…
(C) DAMITH RUSHIKA KOTHALAWALA 2017
![Page 81: Introduction to chef](https://reader035.vdocument.in/reader035/viewer/2022081605/58b8a4ce1a28abc06d8b5c21/html5/thumbnails/81.jpg)
Let’s check node variables
(C) DAMITH RUSHIKA KOTHALAWALA 2017
![Page 82: Introduction to chef](https://reader035.vdocument.in/reader035/viewer/2022081605/58b8a4ce1a28abc06d8b5c21/html5/thumbnails/82.jpg)
Let’s check node variables
(C) DAMITH RUSHIKA KOTHALAWALA 2017
![Page 83: Introduction to chef](https://reader035.vdocument.in/reader035/viewer/2022081605/58b8a4ce1a28abc06d8b5c21/html5/thumbnails/83.jpg)
Let’s check node variables
(C) DAMITH RUSHIKA KOTHALAWALA 2017
![Page 84: Introduction to chef](https://reader035.vdocument.in/reader035/viewer/2022081605/58b8a4ce1a28abc06d8b5c21/html5/thumbnails/84.jpg)
Sometimes we may need to customize any given installation/configuration based on the type of your development/deployment or installation requirements.
Examples.
1. Customized installation of a company developed software
2. Configuration files that should be updated on each new application deployment.
(C) DAMITH RUSHIKA KOTHALAWALA 2017
Cookbook specific node attributes
![Page 85: Introduction to chef](https://reader035.vdocument.in/reader035/viewer/2022081605/58b8a4ce1a28abc06d8b5c21/html5/thumbnails/85.jpg)
Let’s try with a new Cookbook
(C) DAMITH RUSHIKA KOTHALAWALA 2017
#make sure to be at your $HOMEcd ~ #create new cookbooks called cmschef generate cookbook cookbooks/cms
#now generate new recipe called defaultchef generate recipe cookbooks/cms default
#Let’s create new attribute filechef generate attribute cookbooks/cms default
![Page 86: Introduction to chef](https://reader035.vdocument.in/reader035/viewer/2022081605/58b8a4ce1a28abc06d8b5c21/html5/thumbnails/86.jpg)
Let’s declare some node variables vim cookbooks/cms/attributes/default.rb
#Normally we define cookbook specific node variables in following way#default[‘cookbookname’][‘var1’]=’value’
default[‘cms’][‘company`]=’cms’
default[‘cms’][‘location’][‘country’]=’Sri Lanka’
default[‘cms’][‘location’][‘city’]=’Colombo 02’
![Page 87: Introduction to chef](https://reader035.vdocument.in/reader035/viewer/2022081605/58b8a4ce1a28abc06d8b5c21/html5/thumbnails/87.jpg)
Now add new recipe as followsvim cookbooks/cms/recipes/default.rb
#note “ <-
file ‘/home/damith/nodeinfo.txt’ docontent “This system is owned by #{node[‘cms’][‘company’]}, #{node[‘cms’]
[‘location’][‘city’]},#{node[‘cms’][‘location’][‘country’]}”end
![Page 88: Introduction to chef](https://reader035.vdocument.in/reader035/viewer/2022081605/58b8a4ce1a28abc06d8b5c21/html5/thumbnails/88.jpg)
Let’s run this cookbook & look at new contentsudo chef-client -zr “recipe[cms]”
cat ~/hostinfo.txt
#and see what is there
![Page 89: Introduction to chef](https://reader035.vdocument.in/reader035/viewer/2022081605/58b8a4ce1a28abc06d8b5c21/html5/thumbnails/89.jpg)
How override node attributes#this is quite simple via json. See following example
vim customer.json
{“cms”: {
“company”: “Pearson”,“location”: {“city”: “Colombo 09”}
}}
![Page 90: Introduction to chef](https://reader035.vdocument.in/reader035/viewer/2022081605/58b8a4ce1a28abc06d8b5c21/html5/thumbnails/90.jpg)
Now run recipe with customer jsonsudo chef-client -zr “recipe[cms]” -j customer.json
cat ~/hostinfo.txt
#and see what is there
![Page 91: Introduction to chef](https://reader035.vdocument.in/reader035/viewer/2022081605/58b8a4ce1a28abc06d8b5c21/html5/thumbnails/91.jpg)
Let’s Add a Template! Adding all the information into the recipe did make it hard to read.
Objectives ❑ Create a template with chef generate ❑ Define the contents of the ERB template ❑ Change the file resource to the template resource Update the cookbook's version ❑
number ❑ Apply the updated recipe and verify the results
![Page 92: Introduction to chef](https://reader035.vdocument.in/reader035/viewer/2022081605/58b8a4ce1a28abc06d8b5c21/html5/thumbnails/92.jpg)
Let’s add new template file#make sure to be at your $HOMEcd ~ #create new cookbooks called cmschef generate cookbook cookbooks/cms
#now generate new recipe called defaultchef generate recipe cookbooks/cms default
#Let’s create new attribute filechef generate attribute cookbooks/cms default
#make sure to be at your $HOMEcd ~
#now generate new template called hostinfochef generate template cookbooks/cms hostinfo
#now check cookbook tree using tree cookbooks/cms
![Page 93: Introduction to chef](https://reader035.vdocument.in/reader035/viewer/2022081605/58b8a4ce1a28abc06d8b5c21/html5/thumbnails/93.jpg)
What is ERB ?An Embedded Ruby (ERB) template allows Ruby code to be embedded inside a text file within specially formatted tags. Ruby code can be embedded using expressions and statements.
Learn more at : https://docs.chef.io/templates.html#variables
![Page 94: Introduction to chef](https://reader035.vdocument.in/reader035/viewer/2022081605/58b8a4ce1a28abc06d8b5c21/html5/thumbnails/94.jpg)
text within an ERB template
vi cookbooks/cms/templates/default/hostinfo.erb~
Host Information================
This system is owned by <%=node[‘cms’][‘company’]%>, <%=node[‘cms’][‘location’][‘city’]%>,<%=node[‘cms’][‘location’][‘country’]%>
![Page 95: Introduction to chef](https://reader035.vdocument.in/reader035/viewer/2022081605/58b8a4ce1a28abc06d8b5c21/html5/thumbnails/95.jpg)
Using Template on Recipevim cookbooks/cms/recipes/default.rb
#note
file ‘/home/damith/nodeinfo.txt’ dosource ‘hostinfo.erb`
end
Use of templates will help us to have more cleaner codes on recipes.
![Page 96: Introduction to chef](https://reader035.vdocument.in/reader035/viewer/2022081605/58b8a4ce1a28abc06d8b5c21/html5/thumbnails/96.jpg)
Q & A
![Page 97: Introduction to chef](https://reader035.vdocument.in/reader035/viewer/2022081605/58b8a4ce1a28abc06d8b5c21/html5/thumbnails/97.jpg)
Next Session Plan
Use of CHEF for CI/CDPractical Session with Amazon OpsWorks
![Page 98: Introduction to chef](https://reader035.vdocument.in/reader035/viewer/2022081605/58b8a4ce1a28abc06d8b5c21/html5/thumbnails/98.jpg)
Further Supporthttps://training.chef.io https://docs.chef.io
Please post all of your questions on.https://www.facebook.com/groups/devops.lkWe are ready to help you
![Page 99: Introduction to chef](https://reader035.vdocument.in/reader035/viewer/2022081605/58b8a4ce1a28abc06d8b5c21/html5/thumbnails/99.jpg)
Thank You
Special Thanks
❏ CMS (Content Management Systems)❏ Sanjeewa Alwis - Senior Manager Application Engineering, Pearson❏ Hirushi Vidyaratna - Intern, Application Engineering - Pearson❏ Chef.IO for Providing Approval to Conduct this Session