82
© 2014 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified, or distributed in whole or in part without the express consent of Amazon.com, Inc. Infrastructure as code Thomas Metschke, AWS May 15, 2014

Infrastructure as code - Amazon Web Servicesaws-de-media.s3.amazonaws.com/images/summit-berlin...Infrastructure as code Thomas Metschke, AWS May 15, 2014 . Management services Convenience

  • Upload
    others

  • View
    7

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Infrastructure as code - Amazon Web Servicesaws-de-media.s3.amazonaws.com/images/summit-berlin...Infrastructure as code Thomas Metschke, AWS May 15, 2014 . Management services Convenience

© 2014 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified, or distributed in whole or in part without the express consent of Amazon.com, Inc.

Infrastructure as code Thomas Metschke, AWS

May 15, 2014

Page 2: Infrastructure as code - Amazon Web Servicesaws-de-media.s3.amazonaws.com/images/summit-berlin...Infrastructure as code Thomas Metschke, AWS May 15, 2014 . Management services Convenience
Page 3: Infrastructure as code - Amazon Web Servicesaws-de-media.s3.amazonaws.com/images/summit-berlin...Infrastructure as code Thomas Metschke, AWS May 15, 2014 . Management services Convenience

Management services

Convenience Control

Page 4: Infrastructure as code - Amazon Web Servicesaws-de-media.s3.amazonaws.com/images/summit-berlin...Infrastructure as code Thomas Metschke, AWS May 15, 2014 . Management services Convenience

AWS Elastic Beanstalk as well as AWS OpsWorks can be controlled via AWS CloudFormation.

AWS CloudFormation integration

Page 5: Infrastructure as code - Amazon Web Servicesaws-de-media.s3.amazonaws.com/images/summit-berlin...Infrastructure as code Thomas Metschke, AWS May 15, 2014 . Management services Convenience

AWS CloudFormation integration

Page 6: Infrastructure as code - Amazon Web Servicesaws-de-media.s3.amazonaws.com/images/summit-berlin...Infrastructure as code Thomas Metschke, AWS May 15, 2014 . Management services Convenience
Page 7: Infrastructure as code - Amazon Web Servicesaws-de-media.s3.amazonaws.com/images/summit-berlin...Infrastructure as code Thomas Metschke, AWS May 15, 2014 . Management services Convenience

Stack

Page 8: Infrastructure as code - Amazon Web Servicesaws-de-media.s3.amazonaws.com/images/summit-berlin...Infrastructure as code Thomas Metschke, AWS May 15, 2014 . Management services Convenience

Layer / Services

Page 9: Infrastructure as code - Amazon Web Servicesaws-de-media.s3.amazonaws.com/images/summit-berlin...Infrastructure as code Thomas Metschke, AWS May 15, 2014 . Management services Convenience

Instances

Page 10: Infrastructure as code - Amazon Web Servicesaws-de-media.s3.amazonaws.com/images/summit-berlin...Infrastructure as code Thomas Metschke, AWS May 15, 2014 . Management services Convenience

Agent §  Installed on every instance § Can execute different commands on an instance § Sends keep alive messages for auto healing § And 14 host level metrics every minute

Page 11: Infrastructure as code - Amazon Web Servicesaws-de-media.s3.amazonaws.com/images/summit-berlin...Infrastructure as code Thomas Metschke, AWS May 15, 2014 . Management services Convenience

Lifecycle events

Page 12: Infrastructure as code - Amazon Web Servicesaws-de-media.s3.amazonaws.com/images/summit-berlin...Infrastructure as code Thomas Metschke, AWS May 15, 2014 . Management services Convenience
Page 13: Infrastructure as code - Amazon Web Servicesaws-de-media.s3.amazonaws.com/images/summit-berlin...Infrastructure as code Thomas Metschke, AWS May 15, 2014 . Management services Convenience

Launch first instance

Page 14: Infrastructure as code - Amazon Web Servicesaws-de-media.s3.amazonaws.com/images/summit-berlin...Infrastructure as code Thomas Metschke, AWS May 15, 2014 . Management services Convenience

Setup triggers configure event

Page 15: Infrastructure as code - Amazon Web Servicesaws-de-media.s3.amazonaws.com/images/summit-berlin...Infrastructure as code Thomas Metschke, AWS May 15, 2014 . Management services Convenience

Deploy the static App

Page 16: Infrastructure as code - Amazon Web Servicesaws-de-media.s3.amazonaws.com/images/summit-berlin...Infrastructure as code Thomas Metschke, AWS May 15, 2014 . Management services Convenience

Add a database instance

Page 17: Infrastructure as code - Amazon Web Servicesaws-de-media.s3.amazonaws.com/images/summit-berlin...Infrastructure as code Thomas Metschke, AWS May 15, 2014 . Management services Convenience

Reconfigure Stack

Page 18: Infrastructure as code - Amazon Web Servicesaws-de-media.s3.amazonaws.com/images/summit-berlin...Infrastructure as code Thomas Metschke, AWS May 15, 2014 . Management services Convenience

Deploy and migrate database

Page 19: Infrastructure as code - Amazon Web Servicesaws-de-media.s3.amazonaws.com/images/summit-berlin...Infrastructure as code Thomas Metschke, AWS May 15, 2014 . Management services Convenience

Add more instances

Page 20: Infrastructure as code - Amazon Web Servicesaws-de-media.s3.amazonaws.com/images/summit-berlin...Infrastructure as code Thomas Metschke, AWS May 15, 2014 . Management services Convenience

Configure Stack

Page 21: Infrastructure as code - Amazon Web Servicesaws-de-media.s3.amazonaws.com/images/summit-berlin...Infrastructure as code Thomas Metschke, AWS May 15, 2014 . Management services Convenience

Execute recipes – any time

Page 22: Infrastructure as code - Amazon Web Servicesaws-de-media.s3.amazonaws.com/images/summit-berlin...Infrastructure as code Thomas Metschke, AWS May 15, 2014 . Management services Convenience

Stop instance

Page 23: Infrastructure as code - Amazon Web Servicesaws-de-media.s3.amazonaws.com/images/summit-berlin...Infrastructure as code Thomas Metschke, AWS May 15, 2014 . Management services Convenience

Configure Stack

Page 24: Infrastructure as code - Amazon Web Servicesaws-de-media.s3.amazonaws.com/images/summit-berlin...Infrastructure as code Thomas Metschke, AWS May 15, 2014 . Management services Convenience

§ Open Source § Configuration as code

Documented Versioned Testable Reusable

§ Cookbooks & recipes

Chef

Page 25: Infrastructure as code - Amazon Web Servicesaws-de-media.s3.amazonaws.com/images/summit-berlin...Infrastructure as code Thomas Metschke, AWS May 15, 2014 . Management services Convenience

Basic cookbook folder structure ▾ apache2 ▸  attributes ▸  recipes ▸  templates – CHANGELOG.md – metadata.rb – README.md

Page 26: Infrastructure as code - Amazon Web Servicesaws-de-media.s3.amazonaws.com/images/summit-berlin...Infrastructure as code Thomas Metschke, AWS May 15, 2014 . Management services Convenience

§ Cookbook description § Maintainer contact §  License § Version § Dependencies § Conflicting cookbooks § Supported platforms

Cookbook metadata.rb ▾ apache2 ▸  attributes ▸  recipes ▸  templates – CHANGELOG.md – metadata.rb – README.md

Page 27: Infrastructure as code - Amazon Web Servicesaws-de-media.s3.amazonaws.com/images/summit-berlin...Infrastructure as code Thomas Metschke, AWS May 15, 2014 . Management services Convenience

Cookbook metadata.rb name 'apache2' !maintainer 'Darth Vader' !license 'Death Star Commons 2.0' !description 'Installs and configures apache2' !version '0.0.1' !recipe 'apache2', 'Apache setup' !!supports 'amazon' !supports 'ubuntu' !

metadata.rb

Page 28: Infrastructure as code - Amazon Web Servicesaws-de-media.s3.amazonaws.com/images/summit-berlin...Infrastructure as code Thomas Metschke, AWS May 15, 2014 . Management services Convenience

Environment data; the node object

Ohai Attributes Node Object

Page 29: Infrastructure as code - Amazon Web Servicesaws-de-media.s3.amazonaws.com/images/summit-berlin...Infrastructure as code Thomas Metschke, AWS May 15, 2014 . Management services Convenience

§ Runs on the instance

§ Detects host attributes

§ Adds them to the node object

{ ! "platform": "amazon", ! "platform_version": "2013.09", ! "os": "linux", ! "counters": { ! "network": { ! "interfaces": { ! "eth0": { ! ... ! "kernel": { ! "os": "GNU/Linux", ! "name": "Linux", ! "modules": { !... !} !

Ohai

Page 30: Infrastructure as code - Amazon Web Servicesaws-de-media.s3.amazonaws.com/images/summit-berlin...Infrastructure as code Thomas Metschke, AWS May 15, 2014 . Management services Convenience

§ Define variations or properties

§ Everything that may be subject to change over time or due to use case

Cookbook – attributes ▾ apache2 ▸  attributes

default.rb ▸  recipes ▸  templates – CHANGELOG.md – metadata.rb – README.md

Page 31: Infrastructure as code - Amazon Web Servicesaws-de-media.s3.amazonaws.com/images/summit-berlin...Infrastructure as code Thomas Metschke, AWS May 15, 2014 . Management services Convenience

Attributes default.rb case node[:platform] !when 'redhat','centos','fedora','amazon' ! default[:apache][:dir] = '/etc/httpd' ! default[:apache][:user] = 'apache' ! default[:apache][:group] = 'apache' ! default[:apache][:document_root] = '/var/www/html' !when 'debian','ubuntu' ! default[:apache][:dir] = '/etc/apache2' ! default[:apache][:user] = 'www-data' ! default[:apache][:group] = 'www-data' ! default[:apache][:document_root] = '/var/www' !else ! raise 'Unknown platform' !end !

apache2 / attributes / default.rb

Page 32: Infrastructure as code - Amazon Web Servicesaws-de-media.s3.amazonaws.com/images/summit-berlin...Infrastructure as code Thomas Metschke, AWS May 15, 2014 . Management services Convenience

Attributes default.rb case node[:platform] !when 'redhat','centos','fedora','amazon' ! default[:apache][:dir] = '/etc/httpd' ! default[:apache][:user] = 'apache' ! default[:apache][:group] = 'apache' ! default[:apache][:document_root] = '/var/www/html' !when 'debian','ubuntu' ! default[:apache][:dir] = '/etc/apache2' ! default[:apache][:user] = 'www-data' ! default[:apache][:group] = 'www-data' ! default[:apache][:document_root] = '/var/www' !else ! raise 'Unknown platform' !end !

apache2 / attributes / default.rb

Page 33: Infrastructure as code - Amazon Web Servicesaws-de-media.s3.amazonaws.com/images/summit-berlin...Infrastructure as code Thomas Metschke, AWS May 15, 2014 . Management services Convenience

§ Scripts that get executed on the instances

§ Referenced as apache2 !apache2::setup !based on metadata.rb

Cookbook – recipes ▾ apache2 ▸  attributes ▾  recipes

default.rb setup.rb configure.rb service.rb

▸  templates

Page 34: Infrastructure as code - Amazon Web Servicesaws-de-media.s3.amazonaws.com/images/summit-berlin...Infrastructure as code Thomas Metschke, AWS May 15, 2014 . Management services Convenience

§  setup.rb §  Idea is to create all

necessary steps to install Apache on a vanilla OS

Cookbook – setup.rb recipe ▾ apache2 ▸  attributes ▾  recipes

default.rb setup.rb configure.rb service.rb

▸  templates

Page 35: Infrastructure as code - Amazon Web Servicesaws-de-media.s3.amazonaws.com/images/summit-berlin...Infrastructure as code Thomas Metschke, AWS May 15, 2014 . Management services Convenience

Recipe setup.rb package 'apache2'!

apache2 / recipes / setup.rb

Page 36: Infrastructure as code - Amazon Web Servicesaws-de-media.s3.amazonaws.com/images/summit-berlin...Infrastructure as code Thomas Metschke, AWS May 15, 2014 . Management services Convenience

package !template !service !!cron!log !group / user !

link !directory / remote_directory!file / remote_file!!ruby / perl / python / bash !execute / ruby_block!deploy !

Chef resources

Page 37: Infrastructure as code - Amazon Web Servicesaws-de-media.s3.amazonaws.com/images/summit-berlin...Infrastructure as code Thomas Metschke, AWS May 15, 2014 . Management services Convenience

Resources describe what to do or define the desired state Resources have §  attributes §  actions

cron "daily_report" do ! minute "0" ! hour "0" ! day "*" ! command "/daily_report" ! action :create !end !

Chef resources

Page 38: Infrastructure as code - Amazon Web Servicesaws-de-media.s3.amazonaws.com/images/summit-berlin...Infrastructure as code Thomas Metschke, AWS May 15, 2014 . Management services Convenience

Recipe setup.rb package 'apache2' do !"action :install !

end !

apache2 / recipes / setup.rb

Page 39: Infrastructure as code - Amazon Web Servicesaws-de-media.s3.amazonaws.com/images/summit-berlin...Infrastructure as code Thomas Metschke, AWS May 15, 2014 . Management services Convenience

Recipe setup.rb package 'apache2' do ! case node[:platform] ! when 'centos','redhat','fedora','amazon' ! package_name 'httpd' ! when 'debian','ubuntu' ! package_name 'apache2' ! end ! action :install !end !

apache2 / recipes / setup.rb

Page 40: Infrastructure as code - Amazon Web Servicesaws-de-media.s3.amazonaws.com/images/summit-berlin...Infrastructure as code Thomas Metschke, AWS May 15, 2014 . Management services Convenience

Recipe setup.rb package 'apache2' do ! #case node[:platform] ! ... !end !!include_recipe 'apache2::configure' !

apache2 / recipes / setup.rb

Page 41: Infrastructure as code - Amazon Web Servicesaws-de-media.s3.amazonaws.com/images/summit-berlin...Infrastructure as code Thomas Metschke, AWS May 15, 2014 . Management services Convenience

§ Create or change Apache configuration

§  Included by the setup recipe

Cookbook – configure.rb recipe ▾ apache2 ▸  attributes ▾  recipes

default.rb setup.rb configure.rb service.rb

▸  templates

Page 42: Infrastructure as code - Amazon Web Servicesaws-de-media.s3.amazonaws.com/images/summit-berlin...Infrastructure as code Thomas Metschke, AWS May 15, 2014 . Management services Convenience

Recipe configure.rb template 'apache2.conf' do ! source 'apache2.conf.erb' !end "!

apache2 / recipes / configure.rb

Page 43: Infrastructure as code - Amazon Web Servicesaws-de-media.s3.amazonaws.com/images/summit-berlin...Infrastructure as code Thomas Metschke, AWS May 15, 2014 . Management services Convenience

Recipe configure.rb template 'apache2.conf' do ! case node[:platform] ! when 'centos','redhat','fedora','amazon' ! path "#{node[:apache][:dir]}/conf/httpd.conf" ! when 'debian','ubuntu' ! path "#{node[:apache][:dir]}/apache2.conf" ! end ! source 'apache2.conf.erb' !end "!

apache2 / recipes / configure.rb

Page 44: Infrastructure as code - Amazon Web Servicesaws-de-media.s3.amazonaws.com/images/summit-berlin...Infrastructure as code Thomas Metschke, AWS May 15, 2014 . Management services Convenience

§  Embedded Ruby (ERB) §  Variable substitution

and flow control (conditionals or loops)

§  Used for parameterized file generation (configurations, scripts)

Cookbook – templates ▾ apache2 ▸  attributes ▸  recipes ▾  templates ▾  default

apache2.conf.erb

Page 45: Infrastructure as code - Amazon Web Servicesaws-de-media.s3.amazonaws.com/images/summit-berlin...Infrastructure as code Thomas Metschke, AWS May 15, 2014 . Management services Convenience

§ Can be fundamentally different per platform and platform version

§ Rendering is triggered via calling the template resource

Cookbook – templates per platform ▾ apache2 ▸  attributes ▸  recipes ▾  templates ▾  default

apache2.conf.erb ▾  centos-5.7

apache2.conf.erb

Page 46: Infrastructure as code - Amazon Web Servicesaws-de-media.s3.amazonaws.com/images/summit-berlin...Infrastructure as code Thomas Metschke, AWS May 15, 2014 . Management services Convenience

Template apache2.conf.erb ServerName 127.0.0.1 !Listen *:80 !DocumentRoot "<%= node[:apache][:document_root] %>" !!User <%= node[:apache][:user] %> !Group <%= node[:apache][:user] %> !ServerRoot "<%= node[:apache][:dir] %>" !!... !

apache2 / templates / default / apache2.conf.erb

Page 47: Infrastructure as code - Amazon Web Servicesaws-de-media.s3.amazonaws.com/images/summit-berlin...Infrastructure as code Thomas Metschke, AWS May 15, 2014 . Management services Convenience

§ Apache service definition

§ How does start, stop, restart, reload, enable, disable of the service work

Cookbook ▾ apache2 ▸  attributes ▾  recipes

default.rb setup.rb configure.rb service.rb

▸  templates

Page 48: Infrastructure as code - Amazon Web Servicesaws-de-media.s3.amazonaws.com/images/summit-berlin...Infrastructure as code Thomas Metschke, AWS May 15, 2014 . Management services Convenience

Recipe service.rb service 'apache2' do ! #need to add cases for different platforms ! service_name 'httpd' ! restart_command '/sbin/service httpd restart' ! reload_command '/sbin/service httpd reload' !! supports [:restart, :reload, :status] ! action [:nothing] !end !

apache2 / recipes / service.rb

Page 49: Infrastructure as code - Amazon Web Servicesaws-de-media.s3.amazonaws.com/images/summit-berlin...Infrastructure as code Thomas Metschke, AWS May 15, 2014 . Management services Convenience

Recipe configure.rb template 'apache2.conf' do ! case node[:platform] ! ... ! end ! source 'apache2.conf.erb' ! notifies :reload, 'service[apache2]' !end "!

apache2 / recipes / configure.rb

Page 50: Infrastructure as code - Amazon Web Servicesaws-de-media.s3.amazonaws.com/images/summit-berlin...Infrastructure as code Thomas Metschke, AWS May 15, 2014 . Management services Convenience

§ Provide the cookbook source for the Stack (git, svn, http, S3)

§ Assign the recipes to the lifecycle events

Use the cookbook in OpsWorks

Page 51: Infrastructure as code - Amazon Web Servicesaws-de-media.s3.amazonaws.com/images/summit-berlin...Infrastructure as code Thomas Metschke, AWS May 15, 2014 . Management services Convenience

Setup event Configure event

1.  Base recipes are run 2.  Apache configure recipe is

run, without any change on the instance

OpsWorks events breakdown

1.  Base recipes are run 2.  Apache setup recipes

installs the package 3.  Apache configure recipe

writes configuration 4.  Notify Apache service

recipe to start Apache

Page 52: Infrastructure as code - Amazon Web Servicesaws-de-media.s3.amazonaws.com/images/summit-berlin...Infrastructure as code Thomas Metschke, AWS May 15, 2014 . Management services Convenience

¢

Page 53: Infrastructure as code - Amazon Web Servicesaws-de-media.s3.amazonaws.com/images/summit-berlin...Infrastructure as code Thomas Metschke, AWS May 15, 2014 . Management services Convenience

Community cookbooks http://community.opscode.com/search § Close to 1.500 cookbooks § Ratings and descriptions § Versions history § Will be reworked soon

Page 54: Infrastructure as code - Amazon Web Servicesaws-de-media.s3.amazonaws.com/images/summit-berlin...Infrastructure as code Thomas Metschke, AWS May 15, 2014 . Management services Convenience

Community cookbooks https://github.com/search?q=cookbook § Search returns over 10.000 repositories § Not all of them are Chef cookbooks though § Not all of the cookbooks are perfect, check issues,

stars, watchers, forks, number of contributors, …

Page 55: Infrastructure as code - Amazon Web Servicesaws-de-media.s3.amazonaws.com/images/summit-berlin...Infrastructure as code Thomas Metschke, AWS May 15, 2014 . Management services Convenience

Berkshelf support § Version 2 and 3 § Be aware of different syntax between versions § Manage cookbook dependencies § Put your Berksfile in your root folder

Page 56: Infrastructure as code - Amazon Web Servicesaws-de-media.s3.amazonaws.com/images/summit-berlin...Infrastructure as code Thomas Metschke, AWS May 15, 2014 . Management services Convenience

Berkshelf support source "https://api.berkshelf.com" !#metadata !!#cookbook {name}, {version_constraint}, {options} !cookbook "mysql" !cookbook "nginx", "~> 2.6" !cookbook "mysql", ! git: "https://github.com/mystuff/mysql.git", ! branch: "master-master_v2" !

Page 57: Infrastructure as code - Amazon Web Servicesaws-de-media.s3.amazonaws.com/images/summit-berlin...Infrastructure as code Thomas Metschke, AWS May 15, 2014 . Management services Convenience

Precedence with Chef 11.10 1.  Ohai 2.  Deployment JSON 3.  Custom JSON 4.  Your Cookbooks 5.  Berkshelf Cookbooks 6.  Built-in Cookbooks

Page 58: Infrastructure as code - Amazon Web Servicesaws-de-media.s3.amazonaws.com/images/summit-berlin...Infrastructure as code Thomas Metschke, AWS May 15, 2014 . Management services Convenience

Precedence of attributes 1.  Ohai 2.  Deployment JSON 3.  Custom JSON 4.  Your Cookbooks 5.  Berkshelf Cookbooks 6.  Built-in Cookbooks

Page 59: Infrastructure as code - Amazon Web Servicesaws-de-media.s3.amazonaws.com/images/summit-berlin...Infrastructure as code Thomas Metschke, AWS May 15, 2014 . Management services Convenience

Search §  Includes all attributes § Adds Ohai data from the instance itself § Your are not able to search for Ohai data

of other instances in the Stack

Page 60: Infrastructure as code - Amazon Web Servicesaws-de-media.s3.amazonaws.com/images/summit-berlin...Infrastructure as code Thomas Metschke, AWS May 15, 2014 . Management services Convenience

Recipe hosts.rb template '/etc/hosts' do ! source "hosts.erb" ! mode "0644" ! variables( ! :nodes => search(:node, "name:*") ! ) !end !

Page 61: Infrastructure as code - Amazon Web Servicesaws-de-media.s3.amazonaws.com/images/summit-berlin...Infrastructure as code Thomas Metschke, AWS May 15, 2014 . Management services Convenience

Template hosts.erb ... !!<% @nodes.each do |node| -%> <%= ! node.attributes.private_ip %> <%= ! node.hostname %> <%= ! node.name %> !<% end -%> !!... !

Page 62: Infrastructure as code - Amazon Web Servicesaws-de-media.s3.amazonaws.com/images/summit-berlin...Infrastructure as code Thomas Metschke, AWS May 15, 2014 . Management services Convenience

Example result hosts ... !!10.95.180.186 cupcake cupcake.localdomain!10.92.124.141 croissant croissant.localdomain!10.143.21.126 french-toast french-toast.localdomain!10.195.180.64 cheesecake cheesecake.localdomain!10.35.203.124 pie pie.localdomain!!... !

Page 63: Infrastructure as code - Amazon Web Servicesaws-de-media.s3.amazonaws.com/images/summit-berlin...Infrastructure as code Thomas Metschke, AWS May 15, 2014 . Management services Convenience

Another example # Retrieve the master node !master = search(:node, "role:layer_shortname").first !!# Show the private IP of it in the Chef log !Chef::Log.info("Private IP: #{master[:private_ip]}") !!!

Page 64: Infrastructure as code - Amazon Web Servicesaws-de-media.s3.amazonaws.com/images/summit-berlin...Infrastructure as code Thomas Metschke, AWS May 15, 2014 . Management services Convenience

Logging Chef::Log.info('something useful') !# [timestamp] INFO: something useful !!Chef::Log.error('something hit the fan') !# [timestamp] ERROR: something hit the fan !!Chef::Log.info("Node object: #{node.to_json}") !# [timestamp] INFO: Node object: {...} !!

Page 65: Infrastructure as code - Amazon Web Servicesaws-de-media.s3.amazonaws.com/images/summit-berlin...Infrastructure as code Thomas Metschke, AWS May 15, 2014 . Management services Convenience

Node object snippets { "normal": { ! "opsworks": {"activity": "setup", ... }, ... } ! "automatic": { ! "languages": { ... }, ! "ec2": { "ami_id": "", "iam": {}, ... }, ! "cpu": { ... }, ! "memory": { ... }, ! "filesystem": { ... }, ! "uptime_seconds" => 250217 }, ... } !

Page 66: Infrastructure as code - Amazon Web Servicesaws-de-media.s3.amazonaws.com/images/summit-berlin...Infrastructure as code Thomas Metschke, AWS May 15, 2014 . Management services Convenience

Foodcritic § A linting tool for your Chef cookbooks § Comes with a set of rules § Choose which to use and add your own § Run with foodcritic [cookbook_path] !

Page 67: Infrastructure as code - Amazon Web Servicesaws-de-media.s3.amazonaws.com/images/summit-berlin...Infrastructure as code Thomas Metschke, AWS May 15, 2014 . Management services Convenience

Example rule FC007 § Ensures recipe dependencies are reflected in

cookbook metadata files § You use include_recipe "apache2::default"

in a recipe § But you miss depends "apache2"

in the metadata.rb!

Page 68: Infrastructure as code - Amazon Web Servicesaws-de-media.s3.amazonaws.com/images/summit-berlin...Infrastructure as code Thomas Metschke, AWS May 15, 2014 . Management services Convenience

Kitchen CI Run infrastructure tests with different § Drivers (OpsWorks, EC2, Vagrant, Docker, …) § Platforms (like Ubuntu, Amazon Linux, …) § Suites (what to test)

§ Test your logic not Chef base functionality!

Page 69: Infrastructure as code - Amazon Web Servicesaws-de-media.s3.amazonaws.com/images/summit-berlin...Infrastructure as code Thomas Metschke, AWS May 15, 2014 . Management services Convenience

Kitchen CI .kitchen.yml driver: ! name: vagrant !!provisioner: ! name: chef_zero!!platforms: ! - name: ubuntu-13.04 ! - name: centos-6.5 !

Page 70: Infrastructure as code - Amazon Web Servicesaws-de-media.s3.amazonaws.com/images/summit-berlin...Infrastructure as code Thomas Metschke, AWS May 15, 2014 . Management services Convenience

Kitchen CI .kitchen.yml suites: ! - name: client ! run_list: ! - recipe[postgresql::client] ! - name: server ! run_list: ! - recipe[postgresql::server] !

Page 71: Infrastructure as code - Amazon Web Servicesaws-de-media.s3.amazonaws.com/images/summit-berlin...Infrastructure as code Thomas Metschke, AWS May 15, 2014 . Management services Convenience

Run Kitchen CI # destroy, create, converge, setup, verify, destroy !kitchen test !!kitchen verify [NAME|REGEXP|all]"# run all 'tests' !kitchen verify ubuntu " " " "# only ubuntus!kitchen verify client " " " "# only client tests !kitchen verify -c 2 " " " " "# concurrency !!# Talk by Nichol Fletcher http://youtu.be/YzlCHAbJ7KM !!

Page 72: Infrastructure as code - Amazon Web Servicesaws-de-media.s3.amazonaws.com/images/summit-berlin...Infrastructure as code Thomas Metschke, AWS May 15, 2014 . Management services Convenience

§ Explains vagrant setup and configuration

§ Follows along user OpsWorks guide

§ Development and deployment covered

AWS OpsWorks with Vagrant

http://pixelcog.com/blog/2014/virtualizing-aws-opsworks-with-vagrant/

Page 73: Infrastructure as code - Amazon Web Servicesaws-de-media.s3.amazonaws.com/images/summit-berlin...Infrastructure as code Thomas Metschke, AWS May 15, 2014 . Management services Convenience

Develop on a live instance opsworks-agent-cli commands that can help you develop your cookbooks !

list_commands list the commands get_json show the JSON used run_command re-run a command show_log show the current or old log

Page 74: Infrastructure as code - Amazon Web Servicesaws-de-media.s3.amazonaws.com/images/summit-berlin...Infrastructure as code Thomas Metschke, AWS May 15, 2014 . Management services Convenience

Agent CLI – list what happened # list event history (up to 10 events) ![root@pie thomas]# opsworks-agent-cli list !2014-05-06T10:26:58 setup !2014-05-06T10:55:13 configure !2014-05-06T14:59:05 execute_recipes!2014-05-07T18:25:53 " " "deploy !2014-05-07T18:34:11 configure !2014-05-08T10:05:23 configure !2014-05-08T14:43:43 configure !

Page 75: Infrastructure as code - Amazon Web Servicesaws-de-media.s3.amazonaws.com/images/summit-berlin...Infrastructure as code Thomas Metschke, AWS May 15, 2014 . Management services Convenience

Make a change to your cookbooks # list current agent folder and cookbooks ![root@pie thomas]# ls /opt/aws/opsworks/current!!cookbooks " " " " "# OpsWorks cookbooks!berkshelf-cookbooks " "# Cookbooks from Bershelf !site-cookbooks" " " "# Your cookbooks!merged-cookbooks " " "# Resulting cookbooks for run !... !

Page 76: Infrastructure as code - Amazon Web Servicesaws-de-media.s3.amazonaws.com/images/summit-berlin...Infrastructure as code Thomas Metschke, AWS May 15, 2014 . Management services Convenience

Agent CLI – re-run an event # run last setup event (changed cookbooks, same JSON) ![root@pie thomas]# opsworks-agent-cli run setup !!# or select specific date ![root@pie thomas]# opsworks-agent-cli run timestamp!# [2014-05-12 13:06:41] INFO ! [opsworks-agent(17817)]: About to re-run 'setup' ! from 2014-05-08T14:43:43 ! ... !

Page 77: Infrastructure as code - Amazon Web Servicesaws-de-media.s3.amazonaws.com/images/summit-berlin...Infrastructure as code Thomas Metschke, AWS May 15, 2014 . Management services Convenience

Agent CLI – show the current/last log # show the latest event ![root@pie thomas]# opsworks-agent-cli show !!# show the last setup event![root@pie thomas]# opsworks-agent-cli show setup !!# show a specific event based on a timestamp![root@pie thomas]# opsworks-agent-cli show timestamp !!

Page 78: Infrastructure as code - Amazon Web Servicesaws-de-media.s3.amazonaws.com/images/summit-berlin...Infrastructure as code Thomas Metschke, AWS May 15, 2014 . Management services Convenience

Agent CLI – get the JSON to debug # show JSON events (latest or by type/timestamp) ![root@pie thomas]# opsworks-agent-cli get !{ ! "ssh_users": { ! "2066": { ! "name": "thomas", ! "public_key": "ssh-rsa AAAAB3NzaC1...", ! "sudoer": true !... !

Page 79: Infrastructure as code - Amazon Web Servicesaws-de-media.s3.amazonaws.com/images/summit-berlin...Infrastructure as code Thomas Metschke, AWS May 15, 2014 . Management services Convenience

Interesting topics I didn't touch today § Github hooks § Continuous Integration § Docker or any other technology XYZ § Use (encrypted) databags in AWS OpsWorks § Silver AMI to reduce boot times § Chef profiler – chef-handler-profiler

Page 80: Infrastructure as code - Amazon Web Servicesaws-de-media.s3.amazonaws.com/images/summit-berlin...Infrastructure as code Thomas Metschke, AWS May 15, 2014 . Management services Convenience

Keep in touch

@AWSOpsWorks on twitter blogs.aws.amazon.com/application-management

Page 81: Infrastructure as code - Amazon Web Servicesaws-de-media.s3.amazonaws.com/images/summit-berlin...Infrastructure as code Thomas Metschke, AWS May 15, 2014 . Management services Convenience

Send us feedback

Page 82: Infrastructure as code - Amazon Web Servicesaws-de-media.s3.amazonaws.com/images/summit-berlin...Infrastructure as code Thomas Metschke, AWS May 15, 2014 . Management services Convenience

Send us feedback