SlideShare une entreprise Scribd logo
1  sur  55
Télécharger pour lire hors ligne
Chef Resources
Chef's Fundamental Building Blocks
Slide 1 of 55
After completing this module, you should be able to:
Use Chef to install packages on your virtual
workstation
Use the chef-apply command
Create a basic Chef recipe file
Define Chef Resources
Objectives
Slide 2 of 55
Choose an Editor
You'll need to choose an editor to edit files:
emacs
nano
vi / vim
Slide 3 of 55
Linux Editor Reference
Tips for using these editors can be found below:
Nano: (usually touted as the easiest editor to get started with editing
through the command-line.)
OPEN FILE $ nano FILENAME
WRITE (When exiting) ctrl+x, y, ENTER
EXIT ctrl+x
VIM: (Vim, like vi, is more complex because of its different modes. )
OPEN FILE $ vim FILENAME
START EDITING i
WRITE FILE ESC, :w
EXIT ESC, :q
EXIT (don't write) ESC, :q!
Slide 4 of 55
Group Exercise: Find an Editor
How about Nano?
$whichnano
/usr/bin/which:nonanoin(/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/chef/bin)
Slide 5 of 55
Group Exercise: Find an Editor
How about Nano?
$whichnano
/usr/bin/which:nonanoin(/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/chef/bin)
How about vim?
$whichvim
/usr/bin/which:novimin(/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/chef/bin)
Slide 6 of 55
Group Exercise: Find an Editor
How about Nano?
$whichnano
/usr/bin/which:nonanoin(/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/chef/bin)
How about vim?
$whichvim
/usr/bin/which:novimin(/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/chef/bin)
How about Emacs?
$whichemacs
/usr/bin/which:noemacsin(/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/chef/bin)
Slide 7 of 55
Learning Chef
Slide 8 of 55
One of the best ways to learn a technology is to apply
the technology in every situation that it can be
applied.
Learning Chef
Slide 9 of 55
One of the best ways to learn a technology is to apply
the technology in every situation that it can be
applied.
A number of Chef tools are installed on the system so
lets put them to use.
Learning Chef
Slide 10 of 55
What is chef-apply?
Slide 11 of 55
What is chef-apply?
chef-apply is a command-line application that allows us to work with
resources and recipes files.
Slide 12 of 55
What can chef-apply do?
$sudochef-apply--help
Usage:chef-apply[RECIPE_FILE|-eRECIPE_TEXT|-s][OPTIONS]
--[no-]color Usecoloredoutput,defaultstoenabled
-e,--executeRECIPE_TEXT Executeresourcessuppliedinastring
--force-formatter Useformatteroutputinsteadofloggeroutput
--force-logger Useloggeroutputinsteadofformatteroutput
-F,--formatFORMATTER outputformattouse
-jJSON_ATTRIBS, LoadattributesfromaJSONfileorURL
--json-attributes
-l,--log_levelLEVEL Settheloglevel(debug,info,warn,error,fatal)
--minimal-ohai Onlyrunthebareminimumohaipluginschefneedstofunction
--[no-]profile-ruby DumpcompleteRubycallgraphstackofentireChefrun(expertonly)
-s,--stdin ExecuteresourcesreadfromSTDIN
-v,--version Showchefversion
-W,--why-run Enablewhyrunmode
-h,--help Showthismessage
Slide 13 of 55
Resources
Slide 14 of 55
A resource is a statement of configuration policy.
Resources
Slide 15 of 55
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.
Resources
https://docs.chef.io/resources.html
Slide 16 of 55
package'httpd'
The package named httpdis installed.
Example: Package
https://docs.chef.io/resource_package.html
Slide 17 of 55
service'ntp'do
action[:enable,:start]
end
The service named ntp is enabled (start on reboot) and
started.
Example: Service
https://docs.chef.io/resource_service.html
Slide 18 of 55
file'/etc/motd'do
content'Thiscomputeristheproperty...'
end
The file name /etc/motdis created with content 'This
company is the property ...'
Example: File
https://docs.chef.io/resource_file.html
Slide 19 of 55
file'/etc/php.ini.default'do
action:delete
end
The file name /etc/php.ini.defaultis deleted.
Example: File
https://docs.chef.io/resource_file.html
Slide 20 of 55
Group Exercise: Using the –e Execute Option
$sudochef-apply--help
Usage:chef-apply[RECIPE_FILE|-eRECIPE_TEXT|-s][OPTIONS]
--[no-]color Usecoloredoutput,defaultstoenabled
-e,--executeRECIPE_TEXT Executeresourcessuppliedinastring
--force-formatter Useformatteroutputinsteadofloggeroutput
--force-logger Useloggeroutputinsteadofformatteroutput
-F,--formatFORMATTER outputformattouse
-jJSON_ATTRIBS, LoadattributesfromaJSONfileorURL
--json-attributes
-l,--log_levelLEVEL Settheloglevel(debug,info,warn,error,fatal)
--minimal-ohai Onlyrunthebareminimumohaipluginschefneedstofunction
--[no-]profile-ruby DumpcompleteRubycallgraphstackofentireChefrun(expertonly)
-s,--stdin ExecuteresourcesreadfromSTDIN
-v,--version Showchefversion
-W,--why-run Enablewhyrunmode
-h,--help Showthismessage
Slide 21 of 55
Group Exercise: Install nano, emacs or vim
$sudochef-apply-e"package'nano'"
Recipe:(chef-applycookbook)::(chef-applyrecipe)
*yum_package[nano]actioninstall
-installversion2.0.9-7.el6ofpackagenano
Slide 22 of 55
Group Exercise: Did I install my editor?
$whichnano
/bin/nano
Slide 23 of 55
What would happen if you ran the installation
command again?
Group Exercise: Test and Repair
Slide 24 of 55
What would happen if you ran the installation
command again?
What would happen if the package were to become
uninstalled?
Group Exercise: Test and Repair
Slide 25 of 55
chef-apply takes action only when it needs to. Think of
it as test and repair.
Chef looks at the current state of each resource and
takes action only when that resource is out of policy.
Test and Repair
Slide 26 of 55
Slide 27 of 55
"I heard Chef is written in Ruby. If that's the case its
required that we write a quick "Hello, world!"
application."
Group Exercise: Hello, World?
Slide 28 of 55
"I heard Chef is written in Ruby. If that's the case its
required that we write a quick "Hello, world!"
application."
Objective:
Create a recipe file that defines the policy,
The file named hello.txtis created with the content
"Hello, world!".
Group Exercise: Hello, World?
Slide 29 of 55
Group Exercise: Create and Open a Recipe File
$cd~
$nanohello.rb
Slide 30 of 55
Group Exercise: Create a Recipe File Named hello.rb
Edit ~/hello.rb
file'hello.txt'do
content'Hello,world!'
end
The file named hello.txtis created with the content 'Hello, world!'
https://docs.chef.io/resources.html
Slide 31 of 55
Group Exercise: Can chef-apply Run a Recipe File?
$sudochef-apply--help
Usage:chef-apply[RECIPE_FILE|-eRECIPE_TEXT|-s][OPTIONS]
--[no-]color Usecoloredoutput,defaultstoenabled
-e,--executeRECIPE_TEXT Executeresourcessuppliedinastring
--force-formatter Useformatteroutputinsteadofloggeroutput
--force-logger Useloggeroutputinsteadofformatteroutput
-F,--formatFORMATTER outputformattouse
-jJSON_ATTRIBS, LoadattributesfromaJSONfileorURL
--json-attributes
-l,--log_levelLEVEL Settheloglevel(debug,info,warn,error,fatal)
--minimal-ohai Onlyrunthebareminimumohaipluginschefneedstofunction
--[no-]profile-ruby DumpcompleteRubycallgraphstackofentireChefrun(expertonly)
-s,--stdin ExecuteresourcesreadfromSTDIN
-v,--version Showchefversion
-W,--why-run Enablewhyrunmode
-h,--help Showthismessage
Slide 32 of 55
Group Exercise: Apply a recipe file
$sudochef-applyhello.rb
Recipe:(chef-applycookbook)::(chef-applyrecipe)
*file[hello.txt]actioncreate
-createnewfilehello.txt
-updatecontentinfilehello.txtfromnoneto315f5b
---hello.txt 2016-04-1115:01:29.875000726+0000
+++./.hello.txt20160411-7152-1d3f0yn 2016-04-1115:01:29.875000726+0000
@@-1+1,2@@
+Hello,world!
Slide 33 of 55
Group Exercise: What does hello.txtsay?
$cathello.txt
Hello,world!
Slide 34 of 55
What would happen if you ran the command again?
Group Exercise: Test and Repair
Slide 35 of 55
What would happen if you ran the command again?
What would happen if the file contents were
modified?
Group Exercise: Test and Repair
Slide 36 of 55
What would happen if you ran the command again?
What would happen if the file contents were
modified?
What would happen if the file were removed?
Group Exercise: Test and Repair
Slide 37 of 55
What would happen if you ran the command again?
What would happen if the file contents were
modified?
What would happen if the file were removed?
What would happen if the file permissions (mode),
owner, or group changed?
Have we defined a policy for these attributes?
Group Exercise: Test and Repair
Slide 38 of 55
file'hello.txt'do
content'Hello,world!'
end
The TYPE named NAME should be ACTION'd with
ATTRIBUTES
Resource Definition
Slide 39 of 55
file'hello.txt'do
content'Hello,world!'
end
The TYPE named NAME should be ACTION'd with
ATTRIBUTES
Resource Definition
Slide 40 of 55
file'hello.txt'do
content'Hello,world!'
end
The TYPE named NAME should be ACTION'd with
ATTRIBUTES
Example Resource Types:
cron, directory, dsc_resource, dsc_script, env, file, git,
group, ifconfig, link, log, mdadm, mount, package, reboot,
registry_key, remote_directory, remote_file, route, script,
service, template, user, windows_package,
windows_service and more...
Resource Definition
Slide 41 of 55
file'hello.txt'do
content'Hello,world!'
end
The TYPE named NAME should be ACTION'd with
ATTRIBUTES
Resource Definition
Slide 42 of 55
file'hello.txt'do
content'Hello,world!'
end
The TYPE named NAME should be ACTION'd with
ATTRIBUTES
Resource Definition
Slide 43 of 55
file'hello.txt'do
content'Hello,world!'
end
The TYPE named NAME should be ACTION'd with
ATTRIBUTES
SO WHAT IS ACTION'd?
Resource Definition
Slide 44 of 55
Read https://docs.chef.io/resource_file.html
Discover the file resource's:
default action.
default values for mode, owner, and group.
Update the file policy in hello.rbas follows:
The file named 'hello.txt' should be created with...
the content set to 'Hello, world!',
the mode set to '0644',
the owner is 'root',
and the group is 'root'.
Lab 2.1: The file Resource
Slide 45 of 55
Lab 2.1: The Updated file Resource
~/hello.rb
file'hello.txt'do
content'Hello,world!'
mode'0644'
owner'root'
group'root'
action:create
end
The default mode is set by the POSIX Access Control Lists.
The default owner is the current user (could change).
The default group is the POSIX group (if available).
The default action is to create (not necessary to define it).
Slide 46 of 55
Create a recipe file named setup.rbthat defines the policy:
The package named nano is installed.
The package named tree is installed.
The file named /etc/motdis created with the content
'Property of ...'.
Use chef-apply to apply the recipe file named setup.rb
Lab 2.2: workstation Setup Recipe
Slide 47 of 55
Lab 2.2: workstation Setup Recipe File
~/setup.rb
package'nano'
package'vim'
package'emacs'
package'tree'
file'/etc/motd'do
content'Propertyof...'
end
The package named nano is installed.
The package named tree is installed.
The file named /etc/motdis created with the content 'Property of ...'.
Slide 48 of 55
Lab 2.2: Apply the Setup Recipe
$sudochef-applysetup.rb
Recipe:(chef-applycookbook)::(chef-applyrecipe)
*yum_package[nano]actioninstall
-installversion2.0.9-7.el6ofpackagenano
*yum_package[vim]actioninstall
-installversion7.4.629-5.el6ofpackagevim-enhanced
*yum_package[emacs]actioninstall
-installversion23.1-28.el6ofpackageemacs
*yum_package[tree]actioninstall
-installversion1.5.3-3.el6ofpackagetree
*file[/etc/motd]actioncreate
-updatecontentinfile/etc/motdfrome3b0c4tod100eb
---/etc/motd 2013-06-0709:31:32.000000000-0500
+++/etc/.chef-motd20160404-20599-3b66qa 2016-04-0408:01:19.673005668-0500
@@-1+1,2@@
+Propertyof...
Slide 49 of 55
What is a resource?
Discussion
Slide 50 of 55
What is a resource?
What are some other possible examples of resources?
Discussion
Slide 51 of 55
What is a resource?
What are some other possible examples of resources?
How did the example resources we wrote describe the
desired state of an element of our infrastructure?
Discussion
Slide 52 of 55
What is a resource?
What are some other possible examples of resources?
How did the example resources we wrote describe the
desired state of an element of our infrastructure?
What does it mean for a resource to be a statement of
configuration policy?
Discussion
Slide 53 of 55
What questions can we answer for you?
chef-apply
Resources
Resource - default actions and default attributes
Test and Repair
Q&A
Slide 54 of 55
On to Module 3
Slide 55 of 55

Contenu connexe

Tendances

Test kitchen 1.0 - Fletcher Nichol
Test kitchen 1.0 - Fletcher NicholTest kitchen 1.0 - Fletcher Nichol
Test kitchen 1.0 - Fletcher Nichol
Devopsdays
 

Tendances (20)

Compliance Automation Workshop
Compliance Automation WorkshopCompliance Automation Workshop
Compliance Automation Workshop
 
Community Cookbooks & further resources - Fundamentals Webinar Series Part 6
Community Cookbooks & further resources - Fundamentals Webinar Series Part 6Community Cookbooks & further resources - Fundamentals Webinar Series Part 6
Community Cookbooks & further resources - Fundamentals Webinar Series Part 6
 
How to Write Chef Cookbook
How to Write Chef CookbookHow to Write Chef Cookbook
How to Write Chef Cookbook
 
Lessons from Etsy: Avoiding Kitchen Nightmares - #ChefConf 2012
Lessons from Etsy: Avoiding Kitchen Nightmares - #ChefConf 2012Lessons from Etsy: Avoiding Kitchen Nightmares - #ChefConf 2012
Lessons from Etsy: Avoiding Kitchen Nightmares - #ChefConf 2012
 
Using Test Kitchen for testing Chef cookbooks
Using Test Kitchen for testing Chef cookbooksUsing Test Kitchen for testing Chef cookbooks
Using Test Kitchen for testing Chef cookbooks
 
Common configuration with Data Bags - Fundamentals Webinar Series Part 4
Common configuration with Data Bags - Fundamentals Webinar Series Part 4Common configuration with Data Bags - Fundamentals Webinar Series Part 4
Common configuration with Data Bags - Fundamentals Webinar Series Part 4
 
What Makes a Good Chef Cookbook? (May 2014 Edition)
What Makes a Good Chef Cookbook? (May 2014 Edition)What Makes a Good Chef Cookbook? (May 2014 Edition)
What Makes a Good Chef Cookbook? (May 2014 Edition)
 
Making TDD [Somewhat] Bearable on OpenStack
Making TDD [Somewhat] Bearable on OpenStackMaking TDD [Somewhat] Bearable on OpenStack
Making TDD [Somewhat] Bearable on OpenStack
 
Node setup, resource, and recipes - Fundamentals Webinar Series Part 2
Node setup, resource, and recipes - Fundamentals Webinar Series Part 2Node setup, resource, and recipes - Fundamentals Webinar Series Part 2
Node setup, resource, and recipes - Fundamentals Webinar Series Part 2
 
Testable Infrastructure with Chef, Test Kitchen, and Docker
Testable Infrastructure with Chef, Test Kitchen, and DockerTestable Infrastructure with Chef, Test Kitchen, and Docker
Testable Infrastructure with Chef, Test Kitchen, and Docker
 
Chef training Day4
Chef training Day4Chef training Day4
Chef training Day4
 
Chef training Day5
Chef training Day5Chef training Day5
Chef training Day5
 
Chef training - Day3
Chef training - Day3Chef training - Day3
Chef training - Day3
 
Node object and roles - Fundamentals Webinar Series Part 3
Node object and roles - Fundamentals Webinar Series Part 3Node object and roles - Fundamentals Webinar Series Part 3
Node object and roles - Fundamentals Webinar Series Part 3
 
Test driven infrastructure
Test driven infrastructureTest driven infrastructure
Test driven infrastructure
 
Chef training - Day2
Chef training - Day2Chef training - Day2
Chef training - Day2
 
IT Automation with Chef
IT Automation with ChefIT Automation with Chef
IT Automation with Chef
 
Test kitchen 1.0 - Fletcher Nichol
Test kitchen 1.0 - Fletcher NicholTest kitchen 1.0 - Fletcher Nichol
Test kitchen 1.0 - Fletcher Nichol
 
Configuration Management in a Containerized World
Configuration Management in a Containerized WorldConfiguration Management in a Containerized World
Configuration Management in a Containerized World
 
Test Driven Development with Chef
Test Driven Development with ChefTest Driven Development with Chef
Test Driven Development with Chef
 

En vedette

Chef Fundamentals Training Series Module 4: The Chef Client Run and Expanding...
Chef Fundamentals Training Series Module 4: The Chef Client Run and Expanding...Chef Fundamentals Training Series Module 4: The Chef Client Run and Expanding...
Chef Fundamentals Training Series Module 4: The Chef Client Run and Expanding...
Chef Software, Inc.
 
Chef Fundamentals Training Series Module 1: Overview of Chef
Chef Fundamentals Training Series Module 1: Overview of ChefChef Fundamentals Training Series Module 1: Overview of Chef
Chef Fundamentals Training Series Module 1: Overview of Chef
Chef Software, Inc.
 
Standard operating procedure
Standard operating procedureStandard operating procedure
Standard operating procedure
UMP
 
Commercial cooking-learning-module
Commercial cooking-learning-moduleCommercial cooking-learning-module
Commercial cooking-learning-module
Bogs De Castro
 

En vedette (11)

Chef Fundamentals Training Series Module 4: The Chef Client Run and Expanding...
Chef Fundamentals Training Series Module 4: The Chef Client Run and Expanding...Chef Fundamentals Training Series Module 4: The Chef Client Run and Expanding...
Chef Fundamentals Training Series Module 4: The Chef Client Run and Expanding...
 
Chef Fundamentals Training Series Module 3: Setting up Nodes and Cookbook Aut...
Chef Fundamentals Training Series Module 3: Setting up Nodes and Cookbook Aut...Chef Fundamentals Training Series Module 3: Setting up Nodes and Cookbook Aut...
Chef Fundamentals Training Series Module 3: Setting up Nodes and Cookbook Aut...
 
Chef Fundamentals Training Series Module 2: Workstation Setup
Chef Fundamentals Training Series Module 2: Workstation SetupChef Fundamentals Training Series Module 2: Workstation Setup
Chef Fundamentals Training Series Module 2: Workstation Setup
 
Chef Fundamentals Training Series Module 6: Roles, Environments, Community Co...
Chef Fundamentals Training Series Module 6: Roles, Environments, Community Co...Chef Fundamentals Training Series Module 6: Roles, Environments, Community Co...
Chef Fundamentals Training Series Module 6: Roles, Environments, Community Co...
 
Chef Fundamentals Training Series Module 1: Overview of Chef
Chef Fundamentals Training Series Module 1: Overview of ChefChef Fundamentals Training Series Module 1: Overview of Chef
Chef Fundamentals Training Series Module 1: Overview of Chef
 
Overview of Chef - Fundamentals Webinar Series Part 1
Overview of Chef - Fundamentals Webinar Series Part 1Overview of Chef - Fundamentals Webinar Series Part 1
Overview of Chef - Fundamentals Webinar Series Part 1
 
Introduction to Chef: Automate Your Infrastructure by Modeling It In Code
Introduction to Chef: Automate Your Infrastructure by Modeling It In CodeIntroduction to Chef: Automate Your Infrastructure by Modeling It In Code
Introduction to Chef: Automate Your Infrastructure by Modeling It In Code
 
Chef for DevOps - an Introduction
Chef for DevOps - an IntroductionChef for DevOps - an Introduction
Chef for DevOps - an Introduction
 
Infrastructure Automation with Chef
Infrastructure Automation with ChefInfrastructure Automation with Chef
Infrastructure Automation with Chef
 
Standard operating procedure
Standard operating procedureStandard operating procedure
Standard operating procedure
 
Commercial cooking-learning-module
Commercial cooking-learning-moduleCommercial cooking-learning-module
Commercial cooking-learning-module
 

Similaire à Chef for beginners module 2

ZopeSkel & Buildout packages
ZopeSkel & Buildout packagesZopeSkel & Buildout packages
ZopeSkel & Buildout packages
Quintagroup
 
20100730 phpstudy
20100730 phpstudy20100730 phpstudy
20100730 phpstudy
Yusuke Ando
 

Similaire à Chef for beginners module 2 (20)

PuppetConf 2016: Puppet 4.x: The Low WAT-tage Edition – Nick Fagerlund, Puppet
PuppetConf 2016: Puppet 4.x: The Low WAT-tage Edition – Nick Fagerlund, PuppetPuppetConf 2016: Puppet 4.x: The Low WAT-tage Edition – Nick Fagerlund, Puppet
PuppetConf 2016: Puppet 4.x: The Low WAT-tage Edition – Nick Fagerlund, Puppet
 
Make PHP Extension
Make PHP ExtensionMake PHP Extension
Make PHP Extension
 
Linux advanced privilege escalation
Linux advanced privilege escalationLinux advanced privilege escalation
Linux advanced privilege escalation
 
Experiences with backend user rights in TYPO3
Experiences with backend user rights in TYPO3Experiences with backend user rights in TYPO3
Experiences with backend user rights in TYPO3
 
CEIS106_Final_Project.pptx.pdf
CEIS106_Final_Project.pptx.pdfCEIS106_Final_Project.pptx.pdf
CEIS106_Final_Project.pptx.pdf
 
Becoming a Git Master - Nicola Paolucci
Becoming a Git Master - Nicola PaolucciBecoming a Git Master - Nicola Paolucci
Becoming a Git Master - Nicola Paolucci
 
OpenWRT guide and memo
OpenWRT guide and memoOpenWRT guide and memo
OpenWRT guide and memo
 
Test-Driven Puppet Development - PuppetConf 2014
Test-Driven Puppet Development - PuppetConf 2014Test-Driven Puppet Development - PuppetConf 2014
Test-Driven Puppet Development - PuppetConf 2014
 
Oracle applications 11i dba faq
Oracle applications 11i dba faqOracle applications 11i dba faq
Oracle applications 11i dba faq
 
Operating System Practice : Meeting 7- working with bash shell-a-slide
Operating System Practice : Meeting 7- working with bash shell-a-slideOperating System Practice : Meeting 7- working with bash shell-a-slide
Operating System Practice : Meeting 7- working with bash shell-a-slide
 
Automate with Ansible basic (2/e, English)
Automate with Ansible basic (2/e, English)Automate with Ansible basic (2/e, English)
Automate with Ansible basic (2/e, English)
 
Sandy Report
Sandy ReportSandy Report
Sandy Report
 
Sandy Report
Sandy ReportSandy Report
Sandy Report
 
Head in the Clouds: Testing Infra as Code - Config Management 2020
Head in the Clouds: Testing Infra as Code - Config Management 2020Head in the Clouds: Testing Infra as Code - Config Management 2020
Head in the Clouds: Testing Infra as Code - Config Management 2020
 
ZopeSkel & Buildout packages
ZopeSkel & Buildout packagesZopeSkel & Buildout packages
ZopeSkel & Buildout packages
 
Introduction to PowerShell
Introduction to PowerShellIntroduction to PowerShell
Introduction to PowerShell
 
Mahout Workshop on Google Cloud Platform
Mahout Workshop on Google Cloud PlatformMahout Workshop on Google Cloud Platform
Mahout Workshop on Google Cloud Platform
 
20100730 phpstudy
20100730 phpstudy20100730 phpstudy
20100730 phpstudy
 
Zero Downtime Deployment with Ansible
Zero Downtime Deployment with AnsibleZero Downtime Deployment with Ansible
Zero Downtime Deployment with Ansible
 
CICON2010: Adam Griffiths - CodeIgniter 2
CICON2010: Adam Griffiths - CodeIgniter 2CICON2010: Adam Griffiths - CodeIgniter 2
CICON2010: Adam Griffiths - CodeIgniter 2
 

Plus de Chef

Plus de Chef (20)

Habitat Managed Chef
Habitat Managed ChefHabitat Managed Chef
Habitat Managed Chef
 
Automation, Audits, and Apps Tour
Automation, Audits, and Apps TourAutomation, Audits, and Apps Tour
Automation, Audits, and Apps Tour
 
Automation, Audits, and Apps Tour
Automation, Audits, and Apps TourAutomation, Audits, and Apps Tour
Automation, Audits, and Apps Tour
 
London Community Summit 2016 - Adopting Chef Compliance
London Community Summit 2016 - Adopting Chef ComplianceLondon Community Summit 2016 - Adopting Chef Compliance
London Community Summit 2016 - Adopting Chef Compliance
 
Learning from Configuration Management
Learning from Configuration Management Learning from Configuration Management
Learning from Configuration Management
 
London Community Summit 2016 - Fresh New Chef Stuff
London Community Summit 2016 - Fresh New Chef StuffLondon Community Summit 2016 - Fresh New Chef Stuff
London Community Summit 2016 - Fresh New Chef Stuff
 
London Community Summit - Chef at SkyBet
London Community Summit - Chef at SkyBetLondon Community Summit - Chef at SkyBet
London Community Summit - Chef at SkyBet
 
London Community Summit - From Contribution to Authorship
London Community Summit - From Contribution to AuthorshipLondon Community Summit - From Contribution to Authorship
London Community Summit - From Contribution to Authorship
 
London Community Summit 2016 - Chef Automate
London Community Summit 2016 - Chef AutomateLondon Community Summit 2016 - Chef Automate
London Community Summit 2016 - Chef Automate
 
London Community Summit 2016 - Community Update
London Community Summit 2016 - Community UpdateLondon Community Summit 2016 - Community Update
London Community Summit 2016 - Community Update
 
London Community Summit 2016 - Habitat
London Community Summit 2016 -  HabitatLondon Community Summit 2016 -  Habitat
London Community Summit 2016 - Habitat
 
Compliance Automation with Inspec Part 4
Compliance Automation with Inspec Part 4Compliance Automation with Inspec Part 4
Compliance Automation with Inspec Part 4
 
Compliance Automation with Inspec Part 3
Compliance Automation with Inspec Part 3Compliance Automation with Inspec Part 3
Compliance Automation with Inspec Part 3
 
Compliance Automation with Inspec Part 2
Compliance Automation with Inspec Part 2Compliance Automation with Inspec Part 2
Compliance Automation with Inspec Part 2
 
Compliance Automation with Inspec Part 1
Compliance Automation with Inspec Part 1Compliance Automation with Inspec Part 1
Compliance Automation with Inspec Part 1
 
Application Automation with Habitat
Application Automation with HabitatApplication Automation with Habitat
Application Automation with Habitat
 
Achieving DevOps Success with Chef Automate
Achieving DevOps Success with Chef AutomateAchieving DevOps Success with Chef Automate
Achieving DevOps Success with Chef Automate
 
Nike pop up habitat
Nike pop up   habitatNike pop up   habitat
Nike pop up habitat
 
Nike popup compliance workshop
Nike popup compliance workshopNike popup compliance workshop
Nike popup compliance workshop
 
Chef Automate Workflow Demo
Chef Automate Workflow DemoChef Automate Workflow Demo
Chef Automate Workflow Demo
 

Dernier

+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
Health
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
masabamasaba
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
VictorSzoltysek
 

Dernier (20)

%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg
 
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdfThe Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
SHRMPro HRMS Software Solutions Presentation
SHRMPro HRMS Software Solutions PresentationSHRMPro HRMS Software Solutions Presentation
SHRMPro HRMS Software Solutions Presentation
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare
 
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
 

Chef for beginners module 2

  • 1. Chef Resources Chef's Fundamental Building Blocks Slide 1 of 55
  • 2. After completing this module, you should be able to: Use Chef to install packages on your virtual workstation Use the chef-apply command Create a basic Chef recipe file Define Chef Resources Objectives Slide 2 of 55
  • 3. Choose an Editor You'll need to choose an editor to edit files: emacs nano vi / vim Slide 3 of 55
  • 4. Linux Editor Reference Tips for using these editors can be found below: Nano: (usually touted as the easiest editor to get started with editing through the command-line.) OPEN FILE $ nano FILENAME WRITE (When exiting) ctrl+x, y, ENTER EXIT ctrl+x VIM: (Vim, like vi, is more complex because of its different modes. ) OPEN FILE $ vim FILENAME START EDITING i WRITE FILE ESC, :w EXIT ESC, :q EXIT (don't write) ESC, :q! Slide 4 of 55
  • 5. Group Exercise: Find an Editor How about Nano? $whichnano /usr/bin/which:nonanoin(/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/chef/bin) Slide 5 of 55
  • 6. Group Exercise: Find an Editor How about Nano? $whichnano /usr/bin/which:nonanoin(/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/chef/bin) How about vim? $whichvim /usr/bin/which:novimin(/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/chef/bin) Slide 6 of 55
  • 7. Group Exercise: Find an Editor How about Nano? $whichnano /usr/bin/which:nonanoin(/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/chef/bin) How about vim? $whichvim /usr/bin/which:novimin(/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/chef/bin) How about Emacs? $whichemacs /usr/bin/which:noemacsin(/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/chef/bin) Slide 7 of 55
  • 9. One of the best ways to learn a technology is to apply the technology in every situation that it can be applied. Learning Chef Slide 9 of 55
  • 10. One of the best ways to learn a technology is to apply the technology in every situation that it can be applied. A number of Chef tools are installed on the system so lets put them to use. Learning Chef Slide 10 of 55
  • 12. What is chef-apply? chef-apply is a command-line application that allows us to work with resources and recipes files. Slide 12 of 55
  • 13. What can chef-apply do? $sudochef-apply--help Usage:chef-apply[RECIPE_FILE|-eRECIPE_TEXT|-s][OPTIONS] --[no-]color Usecoloredoutput,defaultstoenabled -e,--executeRECIPE_TEXT Executeresourcessuppliedinastring --force-formatter Useformatteroutputinsteadofloggeroutput --force-logger Useloggeroutputinsteadofformatteroutput -F,--formatFORMATTER outputformattouse -jJSON_ATTRIBS, LoadattributesfromaJSONfileorURL --json-attributes -l,--log_levelLEVEL Settheloglevel(debug,info,warn,error,fatal) --minimal-ohai Onlyrunthebareminimumohaipluginschefneedstofunction --[no-]profile-ruby DumpcompleteRubycallgraphstackofentireChefrun(expertonly) -s,--stdin ExecuteresourcesreadfromSTDIN -v,--version Showchefversion -W,--why-run Enablewhyrunmode -h,--help Showthismessage Slide 13 of 55
  • 15. A resource is a statement of configuration policy. Resources Slide 15 of 55
  • 16. 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. Resources https://docs.chef.io/resources.html Slide 16 of 55
  • 17. package'httpd' The package named httpdis installed. Example: Package https://docs.chef.io/resource_package.html Slide 17 of 55
  • 18. service'ntp'do action[:enable,:start] end The service named ntp is enabled (start on reboot) and started. Example: Service https://docs.chef.io/resource_service.html Slide 18 of 55
  • 19. file'/etc/motd'do content'Thiscomputeristheproperty...' end The file name /etc/motdis created with content 'This company is the property ...' Example: File https://docs.chef.io/resource_file.html Slide 19 of 55
  • 20. file'/etc/php.ini.default'do action:delete end The file name /etc/php.ini.defaultis deleted. Example: File https://docs.chef.io/resource_file.html Slide 20 of 55
  • 21. Group Exercise: Using the –e Execute Option $sudochef-apply--help Usage:chef-apply[RECIPE_FILE|-eRECIPE_TEXT|-s][OPTIONS] --[no-]color Usecoloredoutput,defaultstoenabled -e,--executeRECIPE_TEXT Executeresourcessuppliedinastring --force-formatter Useformatteroutputinsteadofloggeroutput --force-logger Useloggeroutputinsteadofformatteroutput -F,--formatFORMATTER outputformattouse -jJSON_ATTRIBS, LoadattributesfromaJSONfileorURL --json-attributes -l,--log_levelLEVEL Settheloglevel(debug,info,warn,error,fatal) --minimal-ohai Onlyrunthebareminimumohaipluginschefneedstofunction --[no-]profile-ruby DumpcompleteRubycallgraphstackofentireChefrun(expertonly) -s,--stdin ExecuteresourcesreadfromSTDIN -v,--version Showchefversion -W,--why-run Enablewhyrunmode -h,--help Showthismessage Slide 21 of 55
  • 22. Group Exercise: Install nano, emacs or vim $sudochef-apply-e"package'nano'" Recipe:(chef-applycookbook)::(chef-applyrecipe) *yum_package[nano]actioninstall -installversion2.0.9-7.el6ofpackagenano Slide 22 of 55
  • 23. Group Exercise: Did I install my editor? $whichnano /bin/nano Slide 23 of 55
  • 24. What would happen if you ran the installation command again? Group Exercise: Test and Repair Slide 24 of 55
  • 25. What would happen if you ran the installation command again? What would happen if the package were to become uninstalled? Group Exercise: Test and Repair Slide 25 of 55
  • 26. chef-apply takes action only when it needs to. Think of it as test and repair. Chef looks at the current state of each resource and takes action only when that resource is out of policy. Test and Repair Slide 26 of 55
  • 28. "I heard Chef is written in Ruby. If that's the case its required that we write a quick "Hello, world!" application." Group Exercise: Hello, World? Slide 28 of 55
  • 29. "I heard Chef is written in Ruby. If that's the case its required that we write a quick "Hello, world!" application." Objective: Create a recipe file that defines the policy, The file named hello.txtis created with the content "Hello, world!". Group Exercise: Hello, World? Slide 29 of 55
  • 30. Group Exercise: Create and Open a Recipe File $cd~ $nanohello.rb Slide 30 of 55
  • 31. Group Exercise: Create a Recipe File Named hello.rb Edit ~/hello.rb file'hello.txt'do content'Hello,world!' end The file named hello.txtis created with the content 'Hello, world!' https://docs.chef.io/resources.html Slide 31 of 55
  • 32. Group Exercise: Can chef-apply Run a Recipe File? $sudochef-apply--help Usage:chef-apply[RECIPE_FILE|-eRECIPE_TEXT|-s][OPTIONS] --[no-]color Usecoloredoutput,defaultstoenabled -e,--executeRECIPE_TEXT Executeresourcessuppliedinastring --force-formatter Useformatteroutputinsteadofloggeroutput --force-logger Useloggeroutputinsteadofformatteroutput -F,--formatFORMATTER outputformattouse -jJSON_ATTRIBS, LoadattributesfromaJSONfileorURL --json-attributes -l,--log_levelLEVEL Settheloglevel(debug,info,warn,error,fatal) --minimal-ohai Onlyrunthebareminimumohaipluginschefneedstofunction --[no-]profile-ruby DumpcompleteRubycallgraphstackofentireChefrun(expertonly) -s,--stdin ExecuteresourcesreadfromSTDIN -v,--version Showchefversion -W,--why-run Enablewhyrunmode -h,--help Showthismessage Slide 32 of 55
  • 33. Group Exercise: Apply a recipe file $sudochef-applyhello.rb Recipe:(chef-applycookbook)::(chef-applyrecipe) *file[hello.txt]actioncreate -createnewfilehello.txt -updatecontentinfilehello.txtfromnoneto315f5b ---hello.txt 2016-04-1115:01:29.875000726+0000 +++./.hello.txt20160411-7152-1d3f0yn 2016-04-1115:01:29.875000726+0000 @@-1+1,2@@ +Hello,world! Slide 33 of 55
  • 34. Group Exercise: What does hello.txtsay? $cathello.txt Hello,world! Slide 34 of 55
  • 35. What would happen if you ran the command again? Group Exercise: Test and Repair Slide 35 of 55
  • 36. What would happen if you ran the command again? What would happen if the file contents were modified? Group Exercise: Test and Repair Slide 36 of 55
  • 37. What would happen if you ran the command again? What would happen if the file contents were modified? What would happen if the file were removed? Group Exercise: Test and Repair Slide 37 of 55
  • 38. What would happen if you ran the command again? What would happen if the file contents were modified? What would happen if the file were removed? What would happen if the file permissions (mode), owner, or group changed? Have we defined a policy for these attributes? Group Exercise: Test and Repair Slide 38 of 55
  • 39. file'hello.txt'do content'Hello,world!' end The TYPE named NAME should be ACTION'd with ATTRIBUTES Resource Definition Slide 39 of 55
  • 40. file'hello.txt'do content'Hello,world!' end The TYPE named NAME should be ACTION'd with ATTRIBUTES Resource Definition Slide 40 of 55
  • 41. file'hello.txt'do content'Hello,world!' end The TYPE named NAME should be ACTION'd with ATTRIBUTES Example Resource Types: cron, directory, dsc_resource, dsc_script, env, file, git, group, ifconfig, link, log, mdadm, mount, package, reboot, registry_key, remote_directory, remote_file, route, script, service, template, user, windows_package, windows_service and more... Resource Definition Slide 41 of 55
  • 42. file'hello.txt'do content'Hello,world!' end The TYPE named NAME should be ACTION'd with ATTRIBUTES Resource Definition Slide 42 of 55
  • 43. file'hello.txt'do content'Hello,world!' end The TYPE named NAME should be ACTION'd with ATTRIBUTES Resource Definition Slide 43 of 55
  • 44. file'hello.txt'do content'Hello,world!' end The TYPE named NAME should be ACTION'd with ATTRIBUTES SO WHAT IS ACTION'd? Resource Definition Slide 44 of 55
  • 45. Read https://docs.chef.io/resource_file.html Discover the file resource's: default action. default values for mode, owner, and group. Update the file policy in hello.rbas follows: The file named 'hello.txt' should be created with... the content set to 'Hello, world!', the mode set to '0644', the owner is 'root', and the group is 'root'. Lab 2.1: The file Resource Slide 45 of 55
  • 46. Lab 2.1: The Updated file Resource ~/hello.rb file'hello.txt'do content'Hello,world!' mode'0644' owner'root' group'root' action:create end The default mode is set by the POSIX Access Control Lists. The default owner is the current user (could change). The default group is the POSIX group (if available). The default action is to create (not necessary to define it). Slide 46 of 55
  • 47. Create a recipe file named setup.rbthat defines the policy: The package named nano is installed. The package named tree is installed. The file named /etc/motdis created with the content 'Property of ...'. Use chef-apply to apply the recipe file named setup.rb Lab 2.2: workstation Setup Recipe Slide 47 of 55
  • 48. Lab 2.2: workstation Setup Recipe File ~/setup.rb package'nano' package'vim' package'emacs' package'tree' file'/etc/motd'do content'Propertyof...' end The package named nano is installed. The package named tree is installed. The file named /etc/motdis created with the content 'Property of ...'. Slide 48 of 55
  • 49. Lab 2.2: Apply the Setup Recipe $sudochef-applysetup.rb Recipe:(chef-applycookbook)::(chef-applyrecipe) *yum_package[nano]actioninstall -installversion2.0.9-7.el6ofpackagenano *yum_package[vim]actioninstall -installversion7.4.629-5.el6ofpackagevim-enhanced *yum_package[emacs]actioninstall -installversion23.1-28.el6ofpackageemacs *yum_package[tree]actioninstall -installversion1.5.3-3.el6ofpackagetree *file[/etc/motd]actioncreate -updatecontentinfile/etc/motdfrome3b0c4tod100eb ---/etc/motd 2013-06-0709:31:32.000000000-0500 +++/etc/.chef-motd20160404-20599-3b66qa 2016-04-0408:01:19.673005668-0500 @@-1+1,2@@ +Propertyof... Slide 49 of 55
  • 50. What is a resource? Discussion Slide 50 of 55
  • 51. What is a resource? What are some other possible examples of resources? Discussion Slide 51 of 55
  • 52. What is a resource? What are some other possible examples of resources? How did the example resources we wrote describe the desired state of an element of our infrastructure? Discussion Slide 52 of 55
  • 53. What is a resource? What are some other possible examples of resources? How did the example resources we wrote describe the desired state of an element of our infrastructure? What does it mean for a resource to be a statement of configuration policy? Discussion Slide 53 of 55
  • 54. What questions can we answer for you? chef-apply Resources Resource - default actions and default attributes Test and Repair Q&A Slide 54 of 55
  • 55. On to Module 3 Slide 55 of 55