ICT role in 21st century education and its challenges
'Intro to Infrastructure as Code' - DevOps Belfast
1. Infrastructure as Code
And Quick Introduction to Chef
DevOps Belfast
Chef Fundamentals by Chef Software, Inc. is licensed under a
Creative Commons Attribution-ShareAlike 4.0 International License.
2. 14 months working at Chef
>4 years working with Chef
Who Am I?
John Fitzpatrick
johnfitzpatrick
jfitzpatrick@getchef.com
@jhnftzptrck
Belfast, Northern Ireland
Curriculum Development
Training
Community stuff
5. Hello!
• System Administrator?
• Developer?
• Business Person (non-technical)?
6. Hello!
• System Administrator?
• Developer?
• Business Person (non-technical)?
• Experience with Infrastructure as Code or
Configuration Management?
7. Hello!
• System Administrator?
• Developer?
• Business Person (non-technical)?
• Experience with Infrastructure as Code or
Configuration Management?
•Familiar with DevOps?
9. IT is revolutionizing every sector
• All companies in every sector have their own IT Departments
automating their product offerings
• They're each striving for
• Automation
• Faster Speed to Market
• Consistent/Predictable Delivery
• Cost Efficiency
12. Online Retail
• Convenient
• Cheaper than a high
street presence
• Global reach
• Faster time to market
13. IT is revolutionizing every sector
• Accounting
• Advertising
• Aerospace
• Agriculture
• Airline
• Apparel & Accessories
• Automotive
• Banking
• Biotechnology
• Broadcasting
• Brokerage
• Call Centers
• Cargo Handling
• Chemical
• Consulting
• Defense
• Department Stores
• Education
• Electronics
• Energy
• Entertainment & Leisure
• Executive Search
• Financial Services
• Food, Beverage & Tobacco
• Grocery
• Health Care
• Internet Publishing
• Investment Banking
• Legal
• Manufacturing
• Motion Picture & Video
• Music
• Newspaper Publishers
• Online Auctions
• Pension Funds
• Pharmaceuticals
• Private Equity
• Publishing
• Real Estate
• Retail & Wholesale
• Securities & Commodity
Exchanges
• Service
• Telecommunications
• Television
• Transportation
• Trucking
• Venture Capital
14. What about IT industry itself?
• IT is still a manual process
• Stuck in the 1990's
15. IT Sector
• Companies IT departments
have been too busy
providing solutions for their
Companies' core business
• But they've neglected their
own back yard!
Dev QA Prod
• IT industry itself is the bottleneck - no one was attempting to
automate the actual IT environment itself
16. IT Industry
• Software companies provide products that feed
into these IT solutions
• But sometimes they add complexity of solution to be
maintained, and not ease of management
18. Case Study: Online Retail
• You place an order
• Card payment is taken
• Item is packed & shipped
• Meanwhile, stock level is debited, & reordered from suppliers
if it falls below a certain level
• Totally automated – no human intervention!
• However the s/w allowing this takes long development
cycles (maybe months), through planning, development,
testing/QA, and into production
19. High Maintenance
• Herculean task to keep these systems running,
patched, upgraded, etc
20. Waterfall Method – Silos!
Business/Sales Lead
Software Architect
Development Team
QA Team
Sys Admin
28. Integrated Approach
• Historically
• Developers wrote software
• Operations (Sys Admins) installed and maintained it
• Now developers need to consider deploying their
code while writing they're writing it
29. CD Pipeline – Sample Workflow
Automate
dBuild and
Unit Tests
Developmen
t
Release
to
Productio
n
GitHub Automate
d
Acceptanc
e Test
Manual
Code
Review (?)
Feedback Check-in
(Linting)
Feedback
Trigger
Check-in
Feedback
(Linting)
Trigger
Feedback
Trigger
Check-in
Feedback
(Linting)
Feedback
Trigger
Trigger
Trigger Trigger Feedback
Feedback
42. Typical Sys Admin Journey
• Store notes in ~/server.txt
• Move notes to the wiki
43. Typical Sys Admin Journey
• Store notes in ~/server.txt
• Move notes to the wiki
•Write some scripts (setup.sh, fixit.sh, etc.)
44. Typical Sys Admin Journey
• Store notes in ~/server.txt
• Move notes to the wiki
•Write some scripts (setup.sh, fixit.sh, etc.)
• setup.sh.BAK
• fixit.sh.OLD
45. Typical Sys Admin Journey
• Store notes in ~/server.txt
• Move notes to the wiki
•Write some scripts (setup.sh, fixit.sh, etc.)
• setup.sh.BAK
• fixit.sh.OLD
• Golden images and snapshots
50. The Infrastructure Code
• Consistent DSL to manage any configuration
component of a server
• packages
• files
• users
• …
• Platform agnostic
• Complex implementation code abstracted out
51. Treat Infrastructure like any code base
• Infrastructure configuration files stored in version
control, e.g. GitHub
• Infrastructure becomes as testable & repeatable
as the application code you're delivering
52. So what does this code look like?
Lets drill down and look at how Chef implements this
53. What is a Resource?
• 'Resource', n., the basic unit of configuration in Chef
• Represents a piece of the system & its desired state
• A package to be installed
• A service to be running
• A file to be generated
• A user to be managed
• etc
54. Example: 'package' Resource
•Manage software packages
• Install
• Upgrade
• Remove
package "apache2" do
action :install
end
55. Resources – Test and Repair
• Resources use a test and repair model
• Resource currently in the desired state?
• Yes – Do nothing
• No – Bring the resource into the desired state (repair)
56. Example: 'file' Resource
• Create a static file on disk
• Add
• Delete
• Permissions
• etc
file "/var/www/html/index.html" do
content "Hello, Belfast!"
owner "root"
group "root"
end
57. Example: 'template' Resource
• Create a dynamic/templated file on disk
• Install
• Upgrade
• Remove
• etc
template "/etc/apache2/apache2.conf" do
source "apache2.conf.erb"
owner "root"
group "root"
mode "0644"
notifies :restart, "service[httpd]"
variables(
:document_root => node["docroot"],
:port => "80"
)
end
58. Example: 'service' Resource
•Manage services on the machine
• start
• stop
• reload
• etc
service "apache2" do
action [ :enable, :start ]
end
59. Other Resources
• deploy
• cron
• directory
• mount
• user
• group
• dsc_resource
•powershell_script
• registry_key
• remote_directory
• route
• and many more…
• Or build your own!
60. Declarative Interface
• Resources are platform agnostic
• Policy declares what state each resource should be
in, but not how to get there
package "ntp"
• Chef decides how to implement this:-
• OSX: brew install ntp
• RHEL: yum install ntp
• Ubuntu: agt-get install ntp
• …
61. What is a Chef Recipe?
• 'Recipe', n., a file containing one or more
Resources
62. Recipe: An ordered list of resources
package "apache2" do
file "/var/www/html/index.html" do
content "Hello, Belfast!"
end
template "/etc/apache2/apache2.conf" do
source "apache2.conf.erb"
notifies :restart, "service[httpd]"
variables(
:document_root => node["docroot"],
:port => "80"
)
end
action :install
end
service "apache2" do
action [:enable,:start]
end
63. Recipe: An ordered list of resources
package "apache2" do
file "/var/www/html/index.html" do
content "Hello, Belfast!"
end
template "/etc/apache2/apache2.conf" do
source "apache2.conf.erb"
notifies :restart, "service[httpd]"
variables(
:document_root => node["docroot"],
:port => "80"
)
end
action :install
end
service "apache2" do
action [:enable,:start]
end
Order is critical!
64. Chef Provisioning Resources (aka Chef Metal)
• Provision servers in any our multiple locations
with_driver 'aws'
num_nodes = 100
1.upto(num_nodes) do |i|
machine "hadoop#{i}" do
recipe 'hadoop::default'
recipe 'ntp'
converge true
tag 'hadoop'
end
end
65. Chef Provisioning Resources (aka Chef Metal)
• Provision servers in any our multiple locations
with_driver 'aws'
num_nodes = 100
1.upto(num_nodes) do |i|
machine "hadoop#{i}" do
recipe 'hadoop::default'
recipe 'ntp'
converge true
tag 'hadoop'
end
end
• Cloud:
• FOG: EC2, DigitalOcean, OpenStack, etc.
• Virtualization:
• Vagrant: VirtualBox, VMWare Fusion, etc.
• Vsphere
• Containers:
• LXC
• Docker
• Bare Metal:
• SSH
66. Extending the Ruby DSL
• Recipes can include arbitrary Ruby code
search(:node, "ipaddress:10*").each.uniq do|node|
file "node_#{node[ipaddress]}" do
content #{node[user]}
end
end
%w{mysql apache2 ntp}.each do |pkg|
package pkg do
action :install
end
end
1.upto(10) do |i|
file "file#{i}" do
action :create
end
end
67. Extending the Ruby DSL
• Recipes can include arbitrary Ruby code
search(:node, "ipaddress:10*").each.uniq do|node|
file "node_#{node[ipaddress]}" do
content #{node[user]}
end
end
%w{mysql apache2 ntp}.each do |pkg|
package pkg do
action :install
end
end
1.upto(10) do |i|
file "file#{i}" do
action :create
end
end
68. Extending the Ruby DSL
• Recipes can include arbitrary Ruby code
search(:node, "ipaddress:10*").each.uniq do|node|
file "node_#{node[ipaddress]}" do
content #{node[user]}
end
end
%w{mysql apache2 ntp}.each do |pkg|
package pkg do
action :install
end
end
1.upto(10) do |i|
file "file#{i}" do
action :create
end
end
Returns a Ruby array
Std Ruby array methods
69. Extending the Ruby DSL
• Recipes can include arbitrary Ruby code
search(:node, "ipaddress:10*").each.uniq do|node|
file "node_#{node[ipaddress]}" do
content #{node[user]}
end
end
%w{mysql apache2 ntp}.each do |pkg|
package pkg do
action :install
end
end
1.upto(10) do |i|
file "file#{i}" do
action :create
end
end
Declare an array
explicitly
Std Ruby array method
70. Extending the Ruby DSL
• Recipes can include arbitrary Ruby code
search(:node, "ipaddress:10*").each.uniq do|node|
file "node_#{node[ipaddress]}" do
content #{node[user]}
end
end
%w{mysql apache2 ntp}.each do |pkg|
package pkg do
action :install
end
end
1.upto(10) do |i|
file "file#{i}" do
action :create
end
end
Std Ruby array method
71. What is a Cookbook?
• 'Cookbook', n., a collection of recipes & supporting
files
• These supporting files could be
• attributes
• templates
• etc
• Naming convention: 'cookbookname::recipename'
72. What is a run_list?
• 'run_list', n., a list of recipes to be run in a given
'chef-client' run
run_list [
"recipe[ntp::client]"
"recipe[users::default]"
"role[webserver]"
]
73. What is a run_list?
• 'run_list', n., a list of recipes to be run in a given
'chef-client' run
run_list [
"recipe[ntp::client]"
"recipe[users::default]"
"role[webserver]"
]
Order is critical!
cookbook recipe
75. chef–client pulls node runlist from Chef Server
Node
Chef
Server
"recipe[ntp::client]"
"recipe[users::default]"
"role[webserver]"
76. chef-client invokes the runlist
Chef
Server
"recipe[ntp::client]"
"recipe[users::default]"
"role[webserver]"
77. Distributed Architecture
• Highly scalable distributed system
• No processing performed on the Chef Server
• All processing is performed on the node itself
78. What can you manage?
•Nodes represent any infrastructure component
• Physical servers or virtual servers
• Local hardware
•Compute instances in a public or private cloud
• Employee workstations
• Could also be network hardware - switches,
routers, etc
79. Chef Server
• Stores policy files and other configuration data
• Maintains a searchable index of node data
81. Search
• Chef Server maintains a searchable index of
node data
• Recipes can search for other nodes with specific
• Roles
• IP addresses
• Hostnames
• FQDNs
• etc
http://www.flickr.com/photos/kathycsus/2686772625
82. Search for Nodes
pool_members = search("node","role:webserver")
template "/etc/haproxy/haproxy.cfg" do
source "haproxy-app_lb.cfg.erb"
owner "root"
group "root"
mode 0644
variables :pool_members => pool_members.uniq
notifies :restart, "service[haproxy]"
end
Developing super slick software applications, of ever increasing complexity, spanning multiple/many nodes, either in the cloud, or on premise, on bare metal or virtualised environments or a mixture of all.
All sectors are being revolutionised!!
IT has made Manufacturing is unrecognisable
No human intervention can mean 24hr shifts
Similar for finance - Reduction of man power,
Similar for finance - Reduction of man power,
We're all aware of benefits of Online Retail.
Faster time to market, convenience buying
Market trading, Airlines, social media, gaming entertainment
In fact every industry
Every business is a software business!!
IT industry is still stuck in the 1990's
These industries have been focusing on the end goals of their particular sector - IT was a means to an end
The IT industry for its part delivers the building blocks for their applications – Apache, MongoDB, MySQL, Python, etc etc etc.
No one has really looked at how each of these can be deployed together in an automated fashion
The ability for an application to scale is determined by a number of key factors
- Time
- Complextity
- Resources - human
- Resources - servers
This is true to scale both in short term (eg xmas rush), and for longer term growth
Sales orders could be accepted, payment received, and goods shipped automatically, but the s/w allowing this took long development cycles (maybe months), through planning, development, testing/QA, and into production
Everything done at once:-
functional spec
detailed design specs
3-4 mths design development test cycles
Should have smaller releases more often in a continuous way
One problem is a lot of companies use the Waterfall Method - aka Rhythm Method, and we all know how precarious that is - when it goes wrong the consequences can be disastrous
The waterfall method is build of slios
(GRENADE ANALOGY)
But Silos are complex structures – so what do we do?
Better processes, reporting etc
But you're just kicking the ball down the street
There has to be a better way
We're in a new era
Speed is of the essence
There are other options
Implement a DevOps culture withing the organization
DevOps is less about tools – more about mindset, attitude and cross-functional interaction
Change is Constant. DevOps culture stresses communication, collaboration and integration between developers and sysadmin
(Continuous Integration is a step along the way to Continuous Delivery)
And importantly – Automate Everything!!
Automation is key!
Automation is key!
The goal of Continuous Delivery pipline can be achieved by automating all processes – from development, through testing and into production
e.g. Jenkins or Travis-CI, or Bamboo watching the repo and build out the node & kick of tests. Other tools like Test Kitchen, serverspec, chefspec, fodcrtitc, rubucop, etc
<<ToDo: Add speaker notes>>
Earlier I mentioned latterly cross-functional teams
Let devs ssh into production to troubleshoot stuff, while sys admin learn to do their stuff via code
Totally collaborative - Blame-free postmortems!
http://www.troll.me/2011/08/31/ancient-aliens-guy/who-created-mind-fuck-aliens/
Q. Why do we want to automate?
A. So we can reap the benefits of speed, consistency and scale
The first step is to implement automation infrastructure as code
Typically SSH into the machine, install a few packages, pull in some content, edit a few config files, restart apache, etc
The commands can be scripted, but would take a few if/then/else statements to cover different platforms
Log into machine
Install a few packages
Pull in some content
Manipulate directories & content
Re/start services
All commands are manual
They have different syntaxes
They're platform specific (RHEL, Debian, Windows, …)
Its all a bit of a hack
He/she keeps notes in text files
Maintains config steps in a wiki
They automate using bash scripts
With their own version control
And maintain golden images & snapshots
Run the code periodically to ensure node complies with policy, e.g. new user added to AD or LDAP?
In Chef, configurations are in 'cookbooks' and 'recipes'
techy drill down on Chef DSL - Resources, Recipes & Cookbooks…
Just to give a flavour of what we're talking about
Resources are the primitives you use to build out your code
This means
The package should be installed
NOT
Install this package
This file should exist
NOT
create this file
As opposed to Linux (packages, files, services), the holy trinity in the Windows world is more “packages, registry keys, services).
The windows_package resource has a mock URL (MS URLs are dreadfully long). It takes options “/quiet and /restart”. The action is to install.
The windows_registry resource enables Remote Desktop and pokes a firewall hole.
The W3SVC is IIS.
Desired State Configuration (DSC)
Use the route resource to manage the system routing table in a Linux environment.
Windows could be choclately
As well as configuring individual servers, you can use chef to provision multiple servers across any environment,
AMI is defaulted for region here
https://github.com/opscode/chef-provisioning-aws/blob/master/lib/chef/provisioning/aws_driver/driver.rb#L356-379
But can be overwritten using ':image' – see https://github.com/opscode/chef-provisioning-aws/blob/master/lib/chef/provisioning/aws_driver/driver.rb#L205
if you're in AWS, various AWS objects like SNS topics, SQS queues, IAM users, ELBs, etc. can be managed.
As opposed to Linux (packages, files, services), the holy trinity in the Windows world is more “packages, registry keys, services).
The windows_package resource has a mock URL (MS URLs are dreadfully long). It takes options “/quiet and /restart”. The action is to install.
The windows_registry resource enables Remote Desktop and pokes a firewall hole.
The W3SVC is IIS.
As opposed to Linux (packages, files, services), the holy trinity in the Windows world is more “packages, registry keys, services).
The windows_package resource has a mock URL (MS URLs are dreadfully long). It takes options “/quiet and /restart”. The action is to install.
The windows_registry resource enables Remote Desktop and pokes a firewall hole.
The W3SVC is IIS.
Recipes can be extended using Ruby to build out complex recipes
Recipes can be extended using Ruby to build out complex recipes
Recipes can be extended using Ruby to build out complex recipes
Recipes can be extended using Ruby to build out complex recipes
Recipes can be extended using Ruby to build out complex recipes
chef-client pings chef server and for its runlist?
When the chef-server run on the node it asks the chef server what policy should I follow, or what is my run list
Chef server looks at the run_list and sends the appropriate cookbooks to the node
Chef-client then executes the resources on the run list
Chef is a highly scalable distributed system
No processing performed on the Chef Server
All processing is performed on the node itself
All the heavy lifting is done on the node!! the server is quite light weight!
network device support for some vendors Arista, Juniper, Cisco
Chef is a highly scalable distributed system
No processing performed on the Chef Server
All processing is performed on the node itself
Chef Server is Open Source.
Free for up to 25 nodes:
Management Console
HA and Replication
Analytics Platform
Skip this and move to Demo if running short on time
Chef Search is one of its killer features. It enables you to do a lot of heavy lifting easily.
Search for nodes by their roles, or other attributes (you assign, or assume via cookbooks).
Infrastructure as code allows you to automatically build an infrastructre and deploy your code on any platform (Ubuntu, RHEL, Windows), and in any environment – ec2, RAX, OpenStack, vmware, bare metal, etc
Stop for a minute and think about what we're saying here. Think about how freeing this can be. The next configuration change you need to make in production starts with a commit to your version control system. You can re-provision your infrastructure with another service provider; move from the data center to the clould and back again.How will this impact the way you run operations in your organization?What questions do you have?
Chef Server is All Open Source
The following are free for up to 25 nodes:
Management Console
HA and Replication
Analytics Platform
AMI is defaulted for region here
https://github.com/opscode/chef-provisioning-aws/blob/master/lib/chef/provisioning/aws_driver/driver.rb#L356-379
But can be overwritten using ':image' – see https://github.com/opscode/chef-provisioning-aws/blob/master/lib/chef/provisioning/aws_driver/driver.rb#L205