SlideShare une entreprise Scribd logo
1  sur  26
Télécharger pour lire hors ligne
Chef
Smart infrastructure automation
Who am I
•

Johannes Skov Frandsen

•

Works primarily with Open
Source

•

Open Source enthusiast since
2000

•

Mostly into web development
og process automation.
What is devops
•

Your software product is not
only the application itself but
also the platform it is running
on

•

Methods used for software
development that can be
valuable in the field of
operations

•

“Missing link” between
developers and sysadmins
What are we trying to solve?
•

Differences in configuration of each environment
Famous: „Works for me”

•

Big amount of time required to configure new
environment

•

Manual configuration changes are prone to errors

•

Lack of local development environment encapsulation

•

Lack of version control for configuration
How are we trying to solve it
•

Make tasks repeatable
•

•

Make tasks rapid
•

•

No manual steps and idempotent.

Fast to build, deploy and restore

Make systems resilient
•

Automated reconfiguration
Devops working areas
•

Configuration management

•

Deployment automation (not todays topic)

•

Build automation (not todays topic)
Configuration management
•

The two biggest contenders are Puppet and
Chef

•

Both a written in Ruby

•

Chef used Ruby as a DSL, Puppet use resource
declaration files.

•

If you are more “Dev” than “Ops”, Chef is
probably your best fit and vice versa.
Chef : http://www.getchef.com/chef/
Puppet : http://puppetlabs.com/
•

•

•

A systems and cloud
infrastructure automation
framework
Makes it easy to deploy
servers and applications to
any physical, virtual, or cloud
location
No matter the size of the
infrastructure
How to use Chef
•

Use it to configure a single machine (chef-solo)

•

Or your entire infrastructure (chef client-server)

•

Use it on-site or in the cloud (build in to amazon
and Rackspace)

•

Use in you local development environment.
Chef in general
Chef is used to describe abstract definitions as
code, defining how you want individual parts of
you infrastructure constructed.

Provisioning

Configuring

Integration
Chef provisioning
•
•
•

Chef can administrate machines via a REST API.
Chef supports Kickstart on Linux, Jumpstart on Solaris and
NIM on AIX.
In virtualised environments, Chef integrates with libvirt and
hypervisors like XEN, KVM, VMware. Chef works well with
VirtualBox.

Provisioning
Configuration
•

Chef is a complete configuration handling tool where recipes
and roles are used to describe how servers are configured.

•

You can describe which packages must be installed, what
services that needs to run, and which configuration files that
needs to be edited.

•

Chef can ensure that all resources are correct installed and
will only make changes to the system if needed.

•

Chef works well in tandem with existing configurations scripts
like shell or perl scripts.
Configuring
Integration
•

Chef can handle separation of configuration logic and
configuration data.

•

As an example, with Chef, when you install a new load
balancer, you can search for installed http servers and
automatically add them to you configuration.

•

Likewise, if you install a new memcached server, you can
advertise this to services that need memcached and
automatically add the new server to their configuration.
Integration
Chef terms
•

Cookbooks
•

•

Environments
•

•

Roles work much the same way as environments, but instead defines a node role. This allows a
cookbook to be used on different nodes with different configurations. When a cookbook is provisioned
in a role, the attributes specified in the cookbook is overridden by those specified in the role.

Nodes
•

•

Different environments can be specifies to distinguish groups of node from others. When a cookbook is
provisioned in a environments, the attributes specified in the cookbook is overridden by those specified
in the environment.

Roles
•

•

Cookbooks describes how to install an individual pieces of software in a generic way across any
number of nodes. Configuration options and settings are specified as attributes with sensible defaults.

Nodes are the finest level of granularity in Chef. The node names a specific instance in the setup and its
configuration can override any attribute define either cookbook, environment or role. Chef server uses
node configurations for provisioning Chef clients.

Data Bags
•

A global variable that is stored as JSON data and is accessible from a Chef Server. The contents of a
data bag include sensitive information and is encrypted.
Solo or Client/Server
•

Chef Solo
•

•

Chef Server
•

•

In cases where you can't use the client server model, Chef solo can be
used to provision the nodes locally. This is handy for provisioning the chef
server itself or for testing new recipes before they are deployed to the Chef
server.

The Chef server manages a repository of all the cookbooks, environments,
roles and nodes in your setup. The Chef server monitors all the node it
manages.

Chef Client
•

The Chef client request its configuration from the Chef server, download the
required software and configures it self.
Show me some code
Chef “Hello World” recipe
package "logrotate" do	
action :install	
end

Chef php cookbook
Recipe
...	
if platform?("redhat")	
node[:php5][:packages][:redhat].each do |pkg|	
package pkg do	
action :install	
end	
end	
end	
if platform?("suse")	
node[:php5][:packages][:suse].each do |pkg|	
package pkg do	
action :install	
end	
end	
end	
...

Attributes
default.php5.packages.redhat = [	
"php", "php-gd", "php-mysql", "php-odbc", "phppdo", "php-soap", "php-xml",	
"php-xmlrpc", "php-mbstring", "php-mcrypt"	
]	

!

default.php5.packages.suse = [	
"php5", "apache2-mod_php5", "php5-calendar",
"php5-ctype", "php5-curl", "php5-dom",	
"php5-exif"	
]
Templates and scripts
Recipe
...	
template "/etc/php5/conf.d/memcache.ini" do	
source "extension"	
mode 0644	
owner "root"	
group "root"	
variables({:extension => "memcache.so"})	
notifies :restart, "service[apache2]"	
end	
...

Template
extension=<%= @extension %>

Recipe
...	
cookbook_file "/tmp/install_memcache.exp" do	
source "install_memcache.exp"	
mode 0600	
owner "root"	
group "root"	
end	
script "install_pecl_memcache" do	
interpreter "bash"	
user "root"	
cwd "/tmp"	
code <<-EOH	
cat /tmp/install_memcache.exp | expect --	
rm /tmp/install_memcache.exp	
EOH	
end	
...

Script
#!/usr/bin/expect	
spawn pecl install memcache	

!
set timeout -1	
!

expect "Enable memcache session handler support?"	
send "yesr"	

!

expect eof
Providers
Recipe

Providers

...	
service "apache2" do	
action :stop	
end	

action :create do	
execute "cp #{new_resource.file}
#{new_resource.file}.#{new_resource.extens
ion}" do	
not_if {::File.exists?
("#{new_resource.file}.#{new_resource.exte
nsion}")}	
only_if {::File.exists?
("#{new_resource.file}")}	
end	
end

!

package "apache2" do	
action :install	
end	

!

# make backup of /etc/apache2/listen.conf	
backup "/etc/apache2/listen.conf"	

!

# change listening port	
sed "/etc/apache2/listen.conf" do	
action :replace	
search "^Listen [0-9]{1,5}"	
replace "Listen #{node[:apache2][:port]}"
end	

!

	

#Allow named virtual hosts	
sed "/etc/apache2/listen.conf" do	
action :replace	
search "^#NameVirtualHost *:[0-9]{1,5}"	
replace "NameVirtualHost *:#{node[:apache2][:port]}"	
end	
...

action :replace do	
execute "sed -e "s|
#{new_resource.search}|
#{new_resource.replace}|g" -i
#{new_resource.file}"	
end	
...
Role skeleton

Roles

Role alfresco

{	

{	

"name": "alfresco",	
"default_attributes": {},	
"override_attributes": {},	
"json_class": "Chef::Role",	
"description": "This installs a alfresco server.",	
"chef_type": "role",	
"run_list": [	
"recipe[networking]",	
	 “recipe[base]",	
	 "recipe[alfresco]",	
	 "recipe[alfresco::ssh]",	
	 "recipe[alfresco::backup]"	
]	

"name": "skeleton",	
"default_attributes": {},	
"override_attributes": {},	
"json_class": "Chef::Role",	
"description": "This installs a skeleton server.",	
"chef_type": "role",	
"run_list": [	
	 "recipe[networking]",	
	 "recipe[base]"	
]	
}

}
Environments

Default

Production

{	

{	

"name": "production",	
"description": “Production environment", 	
"cookbook_versions": {	
"app-master" : "1.1.3",	
"app-slave" : "1.1.3",	
"db-master" : "1.1.3",	
"db-slave" : "1.1.3"	
}, 	
"json_class": "Chef::Environment",	
"chef_type": "environment",	
"default_attributes": {	
"postfix": {	
"aliases": {	
"root": "someone@example.com"	
}	
} }, 	
"override_attributes": {	
"apache2": {	
"admin": "someone@example.com""	
},	
"mysql": {	
"config": {	
"innodb_buffer_pool_size": "6144M"	
},	
"replication": {	
"master": "db-master"	
}	
},	
"backup": {	
"server": “files.example.com"	
}	
}	

"name": "_default",	
"description": "The default Chef environment",	
"cookbook_versions": {	
},	
"json_class": "Chef::Environment",	
"chef_type": "environment",	
"default_attributes": {	
},	
"override_attributes": {	
}	
}

Because you can version
your cookbooks, different
environments can run
different versions.
}
Structure
Lets try it with VirtualBox/
Vagrant
VAGRANTFILE_API_VERSION = "2"

!

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "ubuntu"
config.vm.box_url = "https://ubuntu-server13.10.box"
config.vm.network :forwarded_port, guest: 80, host: 8080
config.ssh.forward_agent = true
config.ssh.shell = "bash -c 'BASH_ENV=/etc/profile exec bash'"
config.vm.synced_folder "www/", "/var/www", :create => true

!

config.vm.provision :chef_solo do |chef|
chef.recipe_url = "https://cookbooks.tar.gz"
chef.add_recipe "apache2"
chef.add_recipe "php5"
end
end

VirtualBox : https://www.virtualbox.org/
Vagrant : http://www.vagrantup.com/
Experience
•

Latest project was running ~50 servers with Chef.

•

All developer was using vagrant to get a local
development environment auto configured.

•

Provisioning and configuration of servers takes
minutes… not days.

•

There are tons of free cookbooks available online
but in our experience you will mostly use them for
inspiration and write your own.
Questions
Anything that is in the world when you're born
is normal and ordinary
and is just natural part of the way the world works.

Anything that's invented between
when you're fifteen and thirty-five
is new and exciting and revolutionary
and you can probably get a career in it.

Thanks
Get the slide at http://www.slideshare.net/localgod

Contenu connexe

Tendances

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.
 
Environments - Fundamentals Webinar Series Week 5
Environments - Fundamentals Webinar Series Week 5Environments - Fundamentals Webinar Series Week 5
Environments - Fundamentals Webinar Series Week 5
Chef
 

Tendances (20)

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...
 
Introduction to Chef - Techsuperwomen Summit
Introduction to Chef - Techsuperwomen SummitIntroduction to Chef - Techsuperwomen Summit
Introduction to Chef - Techsuperwomen Summit
 
Introduction to Chef - April 22 2015
Introduction to Chef - April 22 2015Introduction to Chef - April 22 2015
Introduction to Chef - April 22 2015
 
Introduction to Chef
Introduction to ChefIntroduction to Chef
Introduction to Chef
 
Automating your infrastructure with Chef
Automating your infrastructure with ChefAutomating your infrastructure with Chef
Automating your infrastructure with Chef
 
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 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 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...
 
The unintended benefits of Chef
The unintended benefits of ChefThe unintended benefits of Chef
The unintended benefits of Chef
 
Infrastructure Automation with Chef
Infrastructure Automation with ChefInfrastructure Automation with Chef
Infrastructure Automation with Chef
 
Automating Infrastructure with Chef
Automating Infrastructure with ChefAutomating Infrastructure with Chef
Automating Infrastructure with Chef
 
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
 
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
 
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
 
Introduction to Cooking with Chef
Introduction to Cooking with ChefIntroduction to Cooking with Chef
Introduction to Cooking with Chef
 
Understand Chef
Understand ChefUnderstand Chef
Understand Chef
 
Introduction to Chef
Introduction to ChefIntroduction to Chef
Introduction to Chef
 
Introduction to chef
Introduction to chefIntroduction to chef
Introduction to chef
 
Environments - Fundamentals Webinar Series Week 5
Environments - Fundamentals Webinar Series Week 5Environments - Fundamentals Webinar Series Week 5
Environments - Fundamentals Webinar Series Week 5
 
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
 

En vedette

En vedette (7)

Infrastructure Automation How to Use Chef For DevOps Success
Infrastructure Automation How to Use Chef For DevOps SuccessInfrastructure Automation How to Use Chef For DevOps Success
Infrastructure Automation How to Use Chef For DevOps Success
 
CIRCUIT 2015 - AEM Infrastructure Automation with Chef Cookbooks
CIRCUIT 2015 - AEM Infrastructure Automation with Chef CookbooksCIRCUIT 2015 - AEM Infrastructure Automation with Chef Cookbooks
CIRCUIT 2015 - AEM Infrastructure Automation with Chef Cookbooks
 
Chef Cookbook Testing and Continuous Integration
Chef Cookbook Testing and Continuous IntegrationChef Cookbook Testing and Continuous Integration
Chef Cookbook Testing and Continuous Integration
 
Master Chef class: learn how to quickly cook delightful CQ/AEM infrastructures
Master Chef class: learn how to quickly cook delightful CQ/AEM infrastructuresMaster Chef class: learn how to quickly cook delightful CQ/AEM infrastructures
Master Chef class: learn how to quickly cook delightful CQ/AEM infrastructures
 
Chef for DevOps - an Introduction
Chef for DevOps - an IntroductionChef for DevOps - an Introduction
Chef for DevOps - an Introduction
 
Jenkins and Chef: Infrastructure CI and Automated Deployment
Jenkins and Chef: Infrastructure CI and Automated DeploymentJenkins and Chef: Infrastructure CI and Automated Deployment
Jenkins and Chef: Infrastructure CI and Automated Deployment
 
Infrastructure Automation with Chef
Infrastructure Automation with ChefInfrastructure Automation with Chef
Infrastructure Automation with Chef
 

Similaire à Chef: Smart infrastructure automation

Chef for Openstack
Chef for OpenstackChef for Openstack
Chef for Openstack
Mohit Sethi
 
Avoiding surprises with Chef and Vagrant
Avoiding surprises with Chef and VagrantAvoiding surprises with Chef and Vagrant
Avoiding surprises with Chef and Vagrant
andygale
 

Similaire à Chef: Smart infrastructure automation (20)

Chef for Openstack
Chef for OpenstackChef for Openstack
Chef for Openstack
 
Chef for openstack
Chef for openstackChef for openstack
Chef for openstack
 
Learning chef
Learning chefLearning chef
Learning chef
 
AWS OpsWorks for Chef Automate
AWS OpsWorks for Chef AutomateAWS OpsWorks for Chef Automate
AWS OpsWorks for Chef Automate
 
Introduction to OpsWorks for Chef Automate
Introduction to OpsWorks for Chef AutomateIntroduction to OpsWorks for Chef Automate
Introduction to OpsWorks for Chef Automate
 
Chef fundamentals
Chef fundamentalsChef fundamentals
Chef fundamentals
 
AWS re:Invent 2016: Configuration Management in the Cloud (DEV305)
AWS re:Invent 2016: Configuration Management in the Cloud (DEV305)AWS re:Invent 2016: Configuration Management in the Cloud (DEV305)
AWS re:Invent 2016: Configuration Management in the Cloud (DEV305)
 
Introduction to Infrastructure as Code & Automation / Introduction to Chef
Introduction to Infrastructure as Code & Automation / Introduction to ChefIntroduction to Infrastructure as Code & Automation / Introduction to Chef
Introduction to Infrastructure as Code & Automation / Introduction to Chef
 
Chef
ChefChef
Chef
 
Configuration Management in the Cloud - AWS Online Tech Talks
Configuration Management in the Cloud - AWS Online Tech TalksConfiguration Management in the Cloud - AWS Online Tech Talks
Configuration Management in the Cloud - AWS Online Tech Talks
 
Introduction to chef
Introduction to chefIntroduction to chef
Introduction to chef
 
Introduction to Chef
Introduction to ChefIntroduction to Chef
Introduction to Chef
 
DevOps and Chef improve your life
DevOps and Chef improve your life DevOps and Chef improve your life
DevOps and Chef improve your life
 
Chef, Vagrant and Friends
Chef, Vagrant and FriendsChef, Vagrant and Friends
Chef, Vagrant and Friends
 
Avoiding surprises with Chef and Vagrant
Avoiding surprises with Chef and VagrantAvoiding surprises with Chef and Vagrant
Avoiding surprises with Chef and Vagrant
 
Chef onlinuxonpower
Chef onlinuxonpowerChef onlinuxonpower
Chef onlinuxonpower
 
What is Chef and how we use it at tripsta
What is Chef and how we use it at tripstaWhat is Chef and how we use it at tripsta
What is Chef and how we use it at tripsta
 
Configuration Management with AWS OpsWorks for Chef Automate
Configuration Management with AWS OpsWorks for Chef AutomateConfiguration Management with AWS OpsWorks for Chef Automate
Configuration Management with AWS OpsWorks for Chef Automate
 
CHEF - by Scott Russel
CHEF - by Scott RusselCHEF - by Scott Russel
CHEF - by Scott Russel
 
Cook Infrastructure with chef -- Justeat.IN
Cook Infrastructure with chef  -- Justeat.INCook Infrastructure with chef  -- Justeat.IN
Cook Infrastructure with chef -- Justeat.IN
 

Dernier

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 

Dernier (20)

EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 

Chef: Smart infrastructure automation

  • 2. Who am I • Johannes Skov Frandsen • Works primarily with Open Source • Open Source enthusiast since 2000 • Mostly into web development og process automation.
  • 3. What is devops • Your software product is not only the application itself but also the platform it is running on • Methods used for software development that can be valuable in the field of operations • “Missing link” between developers and sysadmins
  • 4. What are we trying to solve? • Differences in configuration of each environment Famous: „Works for me” • Big amount of time required to configure new environment • Manual configuration changes are prone to errors • Lack of local development environment encapsulation • Lack of version control for configuration
  • 5. How are we trying to solve it • Make tasks repeatable • • Make tasks rapid • • No manual steps and idempotent. Fast to build, deploy and restore Make systems resilient • Automated reconfiguration
  • 6. Devops working areas • Configuration management • Deployment automation (not todays topic) • Build automation (not todays topic)
  • 7. Configuration management • The two biggest contenders are Puppet and Chef • Both a written in Ruby • Chef used Ruby as a DSL, Puppet use resource declaration files. • If you are more “Dev” than “Ops”, Chef is probably your best fit and vice versa. Chef : http://www.getchef.com/chef/ Puppet : http://puppetlabs.com/
  • 8. • • • A systems and cloud infrastructure automation framework Makes it easy to deploy servers and applications to any physical, virtual, or cloud location No matter the size of the infrastructure
  • 9. How to use Chef • Use it to configure a single machine (chef-solo) • Or your entire infrastructure (chef client-server) • Use it on-site or in the cloud (build in to amazon and Rackspace) • Use in you local development environment.
  • 10. Chef in general Chef is used to describe abstract definitions as code, defining how you want individual parts of you infrastructure constructed. Provisioning Configuring Integration
  • 11. Chef provisioning • • • Chef can administrate machines via a REST API. Chef supports Kickstart on Linux, Jumpstart on Solaris and NIM on AIX. In virtualised environments, Chef integrates with libvirt and hypervisors like XEN, KVM, VMware. Chef works well with VirtualBox. Provisioning
  • 12. Configuration • Chef is a complete configuration handling tool where recipes and roles are used to describe how servers are configured. • You can describe which packages must be installed, what services that needs to run, and which configuration files that needs to be edited. • Chef can ensure that all resources are correct installed and will only make changes to the system if needed. • Chef works well in tandem with existing configurations scripts like shell or perl scripts. Configuring
  • 13. Integration • Chef can handle separation of configuration logic and configuration data. • As an example, with Chef, when you install a new load balancer, you can search for installed http servers and automatically add them to you configuration. • Likewise, if you install a new memcached server, you can advertise this to services that need memcached and automatically add the new server to their configuration. Integration
  • 14. Chef terms • Cookbooks • • Environments • • Roles work much the same way as environments, but instead defines a node role. This allows a cookbook to be used on different nodes with different configurations. When a cookbook is provisioned in a role, the attributes specified in the cookbook is overridden by those specified in the role. Nodes • • Different environments can be specifies to distinguish groups of node from others. When a cookbook is provisioned in a environments, the attributes specified in the cookbook is overridden by those specified in the environment. Roles • • Cookbooks describes how to install an individual pieces of software in a generic way across any number of nodes. Configuration options and settings are specified as attributes with sensible defaults. Nodes are the finest level of granularity in Chef. The node names a specific instance in the setup and its configuration can override any attribute define either cookbook, environment or role. Chef server uses node configurations for provisioning Chef clients. Data Bags • A global variable that is stored as JSON data and is accessible from a Chef Server. The contents of a data bag include sensitive information and is encrypted.
  • 15. Solo or Client/Server • Chef Solo • • Chef Server • • In cases where you can't use the client server model, Chef solo can be used to provision the nodes locally. This is handy for provisioning the chef server itself or for testing new recipes before they are deployed to the Chef server. The Chef server manages a repository of all the cookbooks, environments, roles and nodes in your setup. The Chef server monitors all the node it manages. Chef Client • The Chef client request its configuration from the Chef server, download the required software and configures it self.
  • 16. Show me some code Chef “Hello World” recipe package "logrotate" do action :install end Chef php cookbook Recipe ... if platform?("redhat") node[:php5][:packages][:redhat].each do |pkg| package pkg do action :install end end end if platform?("suse") node[:php5][:packages][:suse].each do |pkg| package pkg do action :install end end end ... Attributes default.php5.packages.redhat = [ "php", "php-gd", "php-mysql", "php-odbc", "phppdo", "php-soap", "php-xml", "php-xmlrpc", "php-mbstring", "php-mcrypt" ] ! default.php5.packages.suse = [ "php5", "apache2-mod_php5", "php5-calendar", "php5-ctype", "php5-curl", "php5-dom", "php5-exif" ]
  • 17. Templates and scripts Recipe ... template "/etc/php5/conf.d/memcache.ini" do source "extension" mode 0644 owner "root" group "root" variables({:extension => "memcache.so"}) notifies :restart, "service[apache2]" end ... Template extension=<%= @extension %> Recipe ... cookbook_file "/tmp/install_memcache.exp" do source "install_memcache.exp" mode 0600 owner "root" group "root" end script "install_pecl_memcache" do interpreter "bash" user "root" cwd "/tmp" code <<-EOH cat /tmp/install_memcache.exp | expect -- rm /tmp/install_memcache.exp EOH end ... Script #!/usr/bin/expect spawn pecl install memcache ! set timeout -1 ! expect "Enable memcache session handler support?" send "yesr" ! expect eof
  • 18. Providers Recipe Providers ... service "apache2" do action :stop end action :create do execute "cp #{new_resource.file} #{new_resource.file}.#{new_resource.extens ion}" do not_if {::File.exists? ("#{new_resource.file}.#{new_resource.exte nsion}")} only_if {::File.exists? ("#{new_resource.file}")} end end ! package "apache2" do action :install end ! # make backup of /etc/apache2/listen.conf backup "/etc/apache2/listen.conf" ! # change listening port sed "/etc/apache2/listen.conf" do action :replace search "^Listen [0-9]{1,5}" replace "Listen #{node[:apache2][:port]}" end ! #Allow named virtual hosts sed "/etc/apache2/listen.conf" do action :replace search "^#NameVirtualHost *:[0-9]{1,5}" replace "NameVirtualHost *:#{node[:apache2][:port]}" end ... action :replace do execute "sed -e "s| #{new_resource.search}| #{new_resource.replace}|g" -i #{new_resource.file}" end ...
  • 19. Role skeleton Roles Role alfresco { { "name": "alfresco", "default_attributes": {}, "override_attributes": {}, "json_class": "Chef::Role", "description": "This installs a alfresco server.", "chef_type": "role", "run_list": [ "recipe[networking]", “recipe[base]", "recipe[alfresco]", "recipe[alfresco::ssh]", "recipe[alfresco::backup]" ] "name": "skeleton", "default_attributes": {}, "override_attributes": {}, "json_class": "Chef::Role", "description": "This installs a skeleton server.", "chef_type": "role", "run_list": [ "recipe[networking]", "recipe[base]" ] } }
  • 20. Environments Default Production { { "name": "production", "description": “Production environment", "cookbook_versions": { "app-master" : "1.1.3", "app-slave" : "1.1.3", "db-master" : "1.1.3", "db-slave" : "1.1.3" }, "json_class": "Chef::Environment", "chef_type": "environment", "default_attributes": { "postfix": { "aliases": { "root": "someone@example.com" } } }, "override_attributes": { "apache2": { "admin": "someone@example.com"" }, "mysql": { "config": { "innodb_buffer_pool_size": "6144M" }, "replication": { "master": "db-master" } }, "backup": { "server": “files.example.com" } } "name": "_default", "description": "The default Chef environment", "cookbook_versions": { }, "json_class": "Chef::Environment", "chef_type": "environment", "default_attributes": { }, "override_attributes": { } } Because you can version your cookbooks, different environments can run different versions. }
  • 22. Lets try it with VirtualBox/ Vagrant VAGRANTFILE_API_VERSION = "2" ! Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| config.vm.box = "ubuntu" config.vm.box_url = "https://ubuntu-server13.10.box" config.vm.network :forwarded_port, guest: 80, host: 8080 config.ssh.forward_agent = true config.ssh.shell = "bash -c 'BASH_ENV=/etc/profile exec bash'" config.vm.synced_folder "www/", "/var/www", :create => true ! config.vm.provision :chef_solo do |chef| chef.recipe_url = "https://cookbooks.tar.gz" chef.add_recipe "apache2" chef.add_recipe "php5" end end VirtualBox : https://www.virtualbox.org/ Vagrant : http://www.vagrantup.com/
  • 23.
  • 24. Experience • Latest project was running ~50 servers with Chef. • All developer was using vagrant to get a local development environment auto configured. • Provisioning and configuration of servers takes minutes… not days. • There are tons of free cookbooks available online but in our experience you will mostly use them for inspiration and write your own.
  • 26. Anything that is in the world when you're born is normal and ordinary and is just natural part of the way the world works. Anything that's invented between when you're fifteen and thirty-five is new and exciting and revolutionary and you can probably get a career in it. Thanks Get the slide at http://www.slideshare.net/localgod