Share
Embed
Automating your Infrastructure with Chef
Interested in speeding up time to production when developing an application? Want to understand how to minimize risk associated with changes? Come learn about infrastructure automation with Chef. In this beginner level workshop, I will teach you the core set of skills needed to implement Chef in your environment whether for work or personal projects. I will cover the basic architecture of Chef and the associated tools that will help you improve your application workflow from design to production.
Jennifer Davis
September 19, 2014
Transcript
197 slides
-
Automating your Infrastructure with Chef Beyond the Code - September
2014 Jennifer Davis, Chef Inc 1 -
Twitter: @sigje Email: [email protected] Introductions Name Current Job Role Previous
Job Experience Experience with Infrastructure Automation Favorite Text Editor 4 -
Twitter: @sigje Email: [email protected] Objectives Describe Infrastructure Automation Describe Chef
architecture, tools Read Chef Recipes 8 -
Twitter: @sigje Email: [email protected] Application of Learning Knowledge of your
environment, business needs Chef - Framework to solve infrastructure automation 9 -
Twitter: @sigje Email: [email protected] Chef Fluency 10 20% 80% Training
Practice Fundamentals Training - 16 hours -
Twitter: @sigje Email: [email protected] Additional Resources 11 Fundamentals Training, Intermediate
Training Learn Chef Google Forum -
Twitter: @sigje Email: [email protected] Workshop Fundamentals Objectives at the beginning.
Ask questions. Ask for help. Answer questions. Slides will be available after the class. 12 -
Twitter: @sigje Email: [email protected] Setting Expectations Experience Level: Beginner Flexible
content based on class It’s OK to leave (and come back). Minimize disruptions. 13 -
Twitter: @sigje Email: [email protected] Agenda Overview of Infrastructure Automation Intro
to Resources, Recipes, Cookbooks Working with the Node Object Introduction to Community Cookbooks 15 -
Twitter: @sigje Email: [email protected] Objectives: Overview of Infrastructure Automation Describe
Infrastructure Automation. Describe how Chef treats Infrastructure Automation. Define Node. 17 -
Twitter: @sigje Email: [email protected] Complexity in Applications 22 Single service
== multiple applications. Single application == a component of service. -
Twitter: @sigje Email: [email protected] Complexity in Configurations 24 Multiple services
using same software with different configurations. Different Operating Systems requiring same software (and user experience). -
Twitter: @sigje Email: [email protected] Complexity in Access Control 26 Different
users access to different systems. External versus internal. Compliance. -
Twitter: @sigje Email: [email protected] Data 27 Tweets. Profiles. Emails. Specific
to your organization. -
Twitter: @sigje Email: [email protected] Servers 28 physical hardware cloud services
AWS Digital Ocean virtual VMWare OpenStack VirtualBox -
Twitter: @sigje Email: [email protected] Complexity in Servers 29 Specialization in
hardware. Lack of standardization. -
Twitter: @sigje Email: [email protected] Automation 34 automaton acting of one’s
own will Antikythera mechanism 150-100BC calculate positions of astronomical objects "NAMA Machine d'Anticythère 1". Licensed under Creative Commons Attribution 2.5 via Wikimedia Commons - http://commons.wikimedia.org/wiki/ -
Twitter: @sigje Email: [email protected] Automation 35 reduce labor, energy, and
materials improve quality, precision, accuracy -
Infrastructure Automation is creating control systems that reduce the burden
on people to manage services and increase the quality, accuracy and precision of a service to the consumers of the service. 37 -
Twitter: @sigje Email: [email protected] Infrastructure as Code 39 Programmatically provision
and configure components. -
Twitter: @sigje Email: [email protected] Infrastructure as Code 40 Treat infrastructure
code like the rest of the code. -
Twitter: @sigje Email: [email protected] Infrastructure as Code 41 Reconstruct business
from code repository, data backups, and compute resources. -
Twitter: @sigje Email: [email protected] Chef Tenets of Infrastructure as Code
42 1. Programmatically provision and configure components. 2. Treat infrastructure code like the rest of the code. 3. Reconstruct business from code repository, data backups, and compute resources. -
Twitter: @sigje Email: [email protected] Nodes 44 any physical, virtual, or
cloud machine that is configured to be maintained by a chef-client. -
Twitter: @sigje Email: [email protected] Physical Node 45 server virtual machine
any active device attached to a network that can run a chef-client. -
Twitter: @sigje Email: [email protected] Network Node 46 any active network
device attached to a network that can run a chef-client. -
Twitter: @sigje Email: [email protected] Cloud Node 47 Amazon Virtual Private
Cloud OpenStack Rackspace Google Compute Engine Linode Microsoft Azure -
Twitter: @sigje Email: [email protected] Virtual Node 48 a machine that
runs only as a software implementation, but otherwise behaves much like a physical machine. -
Twitter: @sigje Email: [email protected] Containers 49 a single operating system
to host many working configurations, with each working configuration running as a process that is isolated from all other processes, including even the host operating system -
Twitter: @sigje Email: [email protected] chef-client 50 agent - special software
installed on the server -
Twitter: @sigje Email: [email protected] hostname vs node name 51 host
name - network addressable label assigned to a server node name - unique identifier RECOMMENDATION: hostname == node name -
Twitter: @sigje Email: [email protected] Lesson 1: Set up your cloud
node http://opscode- cheflab.herokuapp.com/labs/ chefdk/centos/attend/ Fill in the form! 52 -
Twitter: @sigje Email: [email protected] Lesson 1: Set up your cloud
node http://opscode- cheflab.herokuapp.com/labs/ chefdk/centos/attend/ Click on “Create user” 53 -
Twitter: @sigje Email: [email protected] Lesson 1: Set up your cloud
node ! Wait until you see “Environment is Ready” Click on “Start Using This Environment” 54 -
Twitter: @sigje Email: [email protected] Lesson 1: Set up your cloud
node 55 ! SUCCESS! Server has been created. -
Twitter: @sigje Email: [email protected] Lesson 2: Identify your cloud node
! Click on “More details” 56 -
Twitter: @sigje Email: [email protected] Lesson 2: Identify your cloud node
! External Address Host Name 57 -
Twitter: @sigje Email: [email protected] Lesson 2: Identify your cloud node
! Click on “show password” 58 -
Twitter: @sigje Email: [email protected] Lesson 2: Identify your cloud node
! Click on “show password” Password will be in the clear. Note it down. 59 -
Twitter: @sigje Email: [email protected] Lesson 3: Connect to your cloud
node ! 2 choices. ssh available? GUI (may be a little slower) 60 -
Twitter: @sigje Email: [email protected] Lesson 3: Connect to your cloud
node with SSH ! Remember this is YOUR hostname Remember this is YOUR root password ssh $HOSTNAME -l root 61 -
Twitter: @sigje Email: [email protected] Lesson 3: Connect to your cloud
node with SSH ! at command prompt type cd chef-repo 62 -
Twitter: @sigje Email: [email protected] Lesson 3: Connect to your cloud
node with GUI ! Click on “View VM” 63 -
Twitter: @sigje Email: [email protected] Lesson 3: Connect to your cloud
node with GUI ! Click anywhere in the white box. 64 -
Twitter: @sigje Email: [email protected] Lesson 4: Verify chef-dk install !
At command prompt type chef verify 65 -
Twitter: @sigje Email: [email protected] Chef Development Kit chef Berkshelf 3.0
Test Kitchen ChefSpec Foodcritic chef-client knife ohai Chef Zero 66 -
Twitter: @sigje Email: [email protected] Verify Installation $ chef verify verifies
that all applications are installed as appropriate 68 -
Twitter: @sigje Email: [email protected] Objectives: Intro to Resources, Recipes, Cookbooks
Define resources. Explain what a recipe is. Define cookbooks. 70 -
Twitter: @sigje Email: [email protected] Answer: What is Infrastructure? application configuration
access control data servers people 73 -
Twitter: @sigje Email: [email protected] Infrastructure Elements the individual components or
building blocks we have access to automate. 74 -
Twitter: @sigje Email: [email protected] Infrastructure Elements files directories symlinks mounts
users groups software packages external services filesystems 75 -
Twitter: @sigje Email: [email protected] Lesson 5: Use docs to find
info about resources Open up a browser window to http://docs.getchef.com/ 78 -
Twitter: @sigje Email: [email protected] Lesson 5: Use docs to find
info about resources Click on “Search the Docs” 79 -
Twitter: @sigje Email: [email protected] Lesson 5: Use docs to find
info about resources Click on “Search the Docs” 80 -
Twitter: @sigje Email: [email protected] Lesson 5: Use docs to find
info about resources enter the word resources into the search box 81 -
Twitter: @sigje Email: [email protected] Lesson 5: Use docs to find
info about resources click on “Resources and Providers Reference - Chef Single-page Topics” 82 -
Twitter: @sigje Email: [email protected] Lesson 5: Use docs to find
info about resources Scroll down the “Table of Contents” on the right hand side Find and click on “Resources” 83 -
Twitter: @sigje Email: [email protected] Lesson 5: Use docs to find
info about resources Success! 84 -
Twitter: @sigje Email: [email protected] Lesson 6: Create a file resource.
GUI users: if the node isn’t available, click on “Reconnect” 85 -
Twitter: @sigje Email: [email protected] Lesson 6: Create a file resource.
create a file named hello.rb. SSH users vi hello.rb GUI vi hello.rb or gedit hello.rb & 86 -
Twitter: @sigje Email: [email protected] Lesson 6: Create a file resource.
create a file named hello.rb. GUI gedit users Opens a graphical window Click on the window to type in it. 87 -
Twitter: @sigje Email: [email protected] Lesson 6: Create a file resource.
create a file named hello.rb. add content. 88 -
Twitter: @sigje Email: [email protected] Lesson 6: Create a file resource.
create a file named hello.rb. add content. 89 -
Twitter: @sigje Email: [email protected] Lesson 6: Create a file resource.
create a file named hello.rb. add content. GUI gedit users Click on “File” 90 -
Twitter: @sigje Email: [email protected] Lesson 6: Create a file resource.
create a file named hello.rb. add content. GUI gedit users Click on “Save” 91 -
Twitter: @sigje Email: [email protected] Lesson 6: Create a file resource.
create a file named hello.rb. add content. SSH and GUI - vi users type “i” to go into insert mode enter text 92 -
Twitter: @sigje Email: [email protected] Lesson 6: Create a file resource.
create a file named hello.rb. add content. vi users Click “esc” key (Command mode) Enter “:x” and click return 93 -
Twitter: @sigje Email: [email protected] Lesson 6: Create a file resource.
create a file named hello.rb. add content. save the file. 94 -
Twitter: @sigje Email: [email protected] Lesson 7: Apply the resource. At
command prompt type: chef-apply hello.rb 95 -
Twitter: @sigje Email: [email protected] Lesson 8: Verify that the file
was created. At command prompt type: cat motd 96 -
Twitter: @sigje Email: [email protected] Lesson 9: Update the resource. At
command prompt type: chef-apply hello.rb 97 -
Twitter: @sigje Email: [email protected] Lesson 10: Modify the resource. Edit
your resource to make your message personal! Edit the file. Modify ‘hello world’. 98 -
Twitter: @sigje Email: [email protected] Lesson 11: Update the resource. At
command prompt type: chef-apply hello.rb 99 -
Twitter: @sigje Email: [email protected] Lesson 11: Update the resource. At
command prompt type: chef-apply hello.rb 100 -
Twitter: @sigje Email: [email protected] Lesson 12: Verify the file changed.
At command prompt type: cat motd 101 -
Twitter: @sigje Email: [email protected] Lesson 13: Modify the file by
hand. Edit the motd file to have a new message. 102 -
Twitter: @sigje Email: [email protected] Lesson 14: Update the resource. 103
At command prompt type: chef-apply hello.rb -
Twitter: @sigje Email: [email protected] Lesson 14: Update the resource. 104
At command prompt type: chef-apply hello.rb -
Twitter: @sigje Email: [email protected] Lesson 15: Delete a file resource.
create a file named goodbye.rb. add content. file ‘motd’ do action :delete end save file. 106 -
Twitter: @sigje Email: [email protected] Lesson 15: Apply the resource. 107
At command prompt type: ????? -
Twitter: @sigje Email: [email protected] Lesson 15: Apply the resource. 108
At command prompt type: chef-apply goodbye.rb -
Twitter: @sigje Email: [email protected] Lesson 15: Apply the resource. 109
At command prompt type: chef-apply goodbye.rb -
Twitter: @sigje Email: [email protected] Lesson 16: Verify the file was
deleted. 110 At command prompt type: cat motd -
A resource represents an element or component of the system.
A resource describes what the element should be not how to achieve that state of being. 111 -
Twitter: @sigje Email: [email protected] Review Created hello.rb and goodbye.rb Created
file resource. Ran chef commands to create and update resource. 112 -
Twitter: @sigje Email: [email protected] Review 113 File Resource File Resource
We created a File resource. -
Twitter: @sigje Email: [email protected] There are a number of different
resources that are defined in the documentation. package "apache2" Review 114 Package Resource -
Twitter: @sigje Email: [email protected] There are a number of different
resources that are defined in the documentation. Review 115 Template Resource template "/etc/apache2/apache2.conf" do source "apache2.conf.erb" owner "root" group "root" mode "0644" variables(:allow_override => "All") notifies :reload, "service[apache2]" end -
Twitter: @sigje Email: [email protected] There are a number of different
resources that are defined in the documentation. Review 116 service "apache2" do action [:enable,:start] supports :reload => true end Service Resource -
A recipe is a file that describes resources and their
desired state. 119 -
Twitter: @sigje Email: [email protected] Review 120 RECIPE RECIPE We created
a hello recipe and a goodbye recipe. -
Twitter: @sigje Email: [email protected] hello recipe should contain all the
resources required to create motd. Review 121 -
Twitter: @sigje Email: [email protected] goodbye recipe should contain all the
resources required to clean up any resources we created for hello. Review 122 -
Twitter: @sigje Email: [email protected] Lesson 17: Create a webserver recipe.
create a file named webserver.rb. add content. save file. 124 -
Twitter: @sigje Email: [email protected] Lesson 17: Create a webserver recipe.
create a file named webserver.rb. add content. package resource install apache server save file. 125 package 'httpd' -
Twitter: @sigje Email: [email protected] Lesson 18: Apply the resource. 127
At command prompt type: chef-apply webserver.rb -
Twitter: @sigje Email: [email protected] Lesson 18: Apply the resource. 128
At command prompt type: chef-apply webserver.rb -
Twitter: @sigje Email: [email protected] Lesson 19: Re-run chef-apply. 129 At
command prompt type: chef-apply webserver.rb -
Twitter: @sigje Email: [email protected] Lesson 20: Modify recipe to start
Apache. edit webserver.rb. add content. service resource starts and enables httpd service save file. 130 package ‘httpd’ ! service 'httpd' do action [:start, :enable] end -
Twitter: @sigje Email: [email protected] Lesson 21: Apply the resource. 132
At command prompt type: chef-apply webserver.rb -
Twitter: @sigje Email: [email protected] Review 133 We created a web
server recipe to install, start, and enable Apache on boot. -
Twitter: @sigje Email: [email protected] Lesson 22: Verify webserver running. Open
a browser. 134 Click on the Firefox Icon to open the browser. -
Twitter: @sigje Email: [email protected] Lesson 22: Verify webserver running. Open
a browser. localhost in the URL field. 135 localhost -
Twitter: @sigje Email: [email protected] Lesson 23: Modify recipe to add
index.html. edit webserver.rb. add content. service file save file. 136 file '/var/www/html/index.html' do content '<html> <body> <h1>hello world</h1> </body> </html>' end -
Twitter: @sigje Email: [email protected] Lesson 24: Apply the resource. 138
At command prompt type: chef-apply webserver.rb -
Twitter: @sigje Email: [email protected] Lesson 25: Reload webpage. Open a
browser. Shift + Click on reload. 139 Shift +Click -
Twitter: @sigje Email: [email protected] Review 140 We created a personalized
index.html. HTML code is embedded in the recipe, our infrastructure code. -
Twitter: @sigje Email: [email protected] Lesson 26: Create a working directory.
142 At command prompt type: mkdir cookbooks cd cookbooks -
Twitter: @sigje Email: [email protected] Lesson 27: Create a webserver cookbook.
145 At command prompt type: chef generate cookbook webserver -
Twitter: @sigje Email: [email protected] Lesson 28: Examine cookbook. 146 At
command prompt type: tree -
Twitter: @sigje Email: [email protected] Lesson 29: Create template file. 147
At command prompt type: chef generate template webserver index.html -
Twitter: @sigje Email: [email protected] Lesson 28: Examine cookbook. 148 At
command prompt type: tree -
Twitter: @sigje Email: [email protected] Lesson 29: Edit index.html.erb file. 149
edit index.html.erb EDITOR webserver/templates/default/ index.html.erb add content. save file. <html> <body> <h1>hello world</h1> </body> </html> -
Twitter: @sigje Email: [email protected] Lesson 30: Edit default recipe. 150
edit default.rb EDITOR webserver/recipes/default.rb add content. package, service, template resources save file. package 'httpd' ! service 'httpd' do action [:start, :enable] end ! template '/var/www/html/index.html' do source 'index.html.erb' end -
Twitter: @sigje Email: [email protected] Lesson 30: Edit default recipe. 151
edit default.rb EDITOR webserver/recipes/default.rb add content. package, service, template resources save file. package 'httpd' ! service 'httpd' do action [:start, :enable] end ! template '/var/www/html/index.html' do source 'index.html.erb' end -
Twitter: @sigje Email: [email protected] Lesson 31: Use our cookbook. 154
At command prompt type: chef-client --local-mode --runlist webserver -
Twitter: @sigje Email: [email protected] Lesson 32: Reload webpage. Open a
browser. Shift + Click on reload. 155 Shift +Click -
Twitter: @sigje Email: [email protected] Review 156 separation of our web
code and infrastructure code. -
Twitter: @sigje Email: [email protected] Review 157 chef-apply - single recipe
chef-client - multiple recipes local-mode — not using chef server runlist — specify the ordered set of recipes to run. -
Twitter: @sigje Email: [email protected] Objectives: Working with the Node Object
Explain what the node object is in Chef. Show details about a node. Describe node attributes. 160 -
Twitter: @sigje Email: [email protected] Node Object 161 A node is
any physical, virtual, or cloud machine that is configured to be maintained by a chef-client. The node object is representation of that node within chef (e.g. in JSON). Available when you are writing recipes. -
Twitter: @sigje Email: [email protected] Lesson 33: Set PATH variable. 162
At command prompt type: export PATH=$PATH:/opt/chef/embedded/bin:/opt/chefdk/embedded/bin -
Twitter: @sigje Email: [email protected] Lesson 34: Run Ohai 163 At
command prompt type: ohai To page through the output: ohai | less -
Twitter: @sigje Email: [email protected] Node Attributes 164 Ohai populates automatically
discovered attributes of the node. -
Twitter: @sigje Email: [email protected] Node Attributes 165 Ability to programmatically
add additional attributes in recipes and cookbooks node.default["apache"]["dir"] = "/etc/apache2" attribute name attribute value -
Twitter: @sigje Email: [email protected] Lesson 35: Create the attribute file.
At command prompt type: chef generate attribute webserver default 166 -
Twitter: @sigje Email: [email protected] Lesson 36: Examine cookbook. 167 At
command prompt type: tree -
Twitter: @sigje Email: [email protected] Lesson 37: Edit the attribute file.
168 edit default.rb EDITOR webserver/attributes/default.rb add content. save file. default["apache"]["indexfile"] = "index.html" -
Twitter: @sigje Email: [email protected] Objectives: Intro to Community Cookbooks Find,
preview, download cookbooks from the community. Use knife to work with the Supermarket API. Download, extract, examine, and implement cookbooks from the Supermarket. 170 -
Twitter: @sigje Email: [email protected] Chef 171 Company Open Source Software
Command Line tool Community -
Twitter: @sigje Email: [email protected] Supermarket tools and cookbooks created and
shared by the community 173 -
Twitter: @sigje Email: [email protected] Lesson 38: Browse the Supermarket website.
Open a browser. supermarket.getchef.com 174 -
Twitter: @sigje Email: [email protected] Lesson 38: Browse the Supermarket website.
type “apache” in the search box. 175 -
Twitter: @sigje Email: [email protected] Lesson 39: Inspect the apache cookbook.
Click on “apache” 177 -
Twitter: @sigje Email: [email protected] Lesson 39: Inspect the apache cookbook.
180 Recent Activity -
Twitter: @sigje Email: [email protected] Lesson 40: Search Supermarket from command
line 181 At command prompt type: knife cookbook site search chef-client -
Twitter: @sigje Email: [email protected] Lesson 40: Search Supermarket from command
line 182 At command prompt type: knife cookbook site show chef-client -
Twitter: @sigje Email: [email protected] Lesson 40: Search Supermarket from command
line 183 At command prompt type: knife cookbook site show chef-client -
Twitter: @sigje Email: [email protected] Lesson 41: Download chef-client cookbook. 184
At command prompt type: knife cookbook site download chef-client -
Twitter: @sigje Email: [email protected] Review 185 Searched Supermarket site for
a cookbook. Downloaded cookbook. -
Twitter: @sigje Email: [email protected] Review 186 Downloaded cookbook. Code. Root.
Examine before using. -
Twitter: @sigje Email: [email protected] Lesson 42: Extract chef-client cookbook. 187
At command prompt type: tar zxvf chef-client-3.8.0.tar.gz -
Twitter: @sigje Email: [email protected] Lesson 42: Read the chef-client cookbook.
188 Examine the README.md cat chef-client/README.md -
Twitter: @sigje Email: [email protected] Lesson 42: Read the chef-client cookbook.
189 Examine the README.md Expectations of the cookbook, platform, data Recipes Usage Notes -
Twitter: @sigje Email: [email protected] Lesson 43: Use the chef-client cookbook.
190 At command prompt type: chef-client --local-mode --runlist webserver,chef-client This will fail because we haven’t set up an org in hosted chef. -
Twitter: @sigje Email: [email protected] Review Overview of Infrastructure Automation Intro
to Resources, Recipes, Cookbooks Working with the Node Object Introduction to Community Cookbooks 192 -
Twitter: @sigje Email: [email protected] Objectives Describe Infrastructure Automation Describe Chef
architecture, tools Read Chef Recipes 193 -
Twitter: @sigje Email: [email protected] Resources: O’Reilly Books Learning Chef -
Mischa Taylor and Seth Vargo Experience Level: Beginner to Chef Customizing Chef - Jon Cowie Experience Level: Intermediate to Chef Sekret code: (ONLY AVAILABLE TO ATTENDEES) 50% print discount, 40% ebook discount 194 -
Twitter: @sigje Email: [email protected] Additional Resources 195 Fundamentals Training, Intermediate
Training Learn Chef Fundamentals videos Google Forum Sign up for Virtual Office Hours -
Twitter: @sigje Email: [email protected] THANK YOU Shirts Knife Reference Guides
Give me your business card (or email me contact details) and I’ll send you DRAFT version of Learning Chef ebook (potential spelling mistakes..) 196