Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Infrastructure as Code

Infrastructure as Code

An introductory talk about using configuration management tools and API to manage web infrastructure. Given at CloudEast 28th June 2012

Gareth Rushgrove

July 01, 2012
Tweet

More Decks by Gareth Rushgrove

Other Decks in Technology

Transcript

  1. Me

  2. gareth rushgrove | morethanseven.net Code code /kōd/ A system of

    symbols and rules used to represent instructions to a computer; a computer program.
  3. gareth rushgrove | morethanseven.net (Yes, I know about shUnit) #!/bin/sh

    testEquality() { assertEquals 1 1 } . ../src/shell/shunit2
  4. gareth rushgrove | morethanseven.net Not new - 1993 CFEngine -

    2003 Puppet - 2006 Amazon EC2 - 2009 Chef
  5. gareth rushgrove | morethanseven.net CFEngine code example bundle agent test

    { packages: redhat:: "wget" package_policy => "addupdate", package_method => yum, package_select => ">=", package_version => "1.11.4-2.el5_4.1", package_architectures => { "x86_64" }; }
  6. gareth rushgrove | morethanseven.net Puppet code example package { 'web-facter':

    ensure => latest, provider => gem, } service { 'web-facter': ensure => running, provider => upstart, require => Package['web-facter'] }
  7. gareth rushgrove | morethanseven.net Chef code example cookbook_file "#{home_dir}/.ssh/authorized_keys" do

    source "authorized_keys" mode "0600" owner username group username end group "sysadmin" do members ["garethr"] end
  8. gareth rushgrove | morethanseven.net Pallet code example (use 'pallet.crate.java) (defnode

    webserver {} :configure (phase (java :openjdk))) (converge {webserver 10} :compute service)
  9. gareth rushgrove | morethanseven.net Rspec-puppet require_relative '../../spec_helper' describe 'development', :type

    => :class do let(:facts) { { :govuk_class => "development" } } it { should create_package("nginx") } it { should_not raise_error(Puppet::ParseError) } end
  10. gareth rushgrove | morethanseven.net Rspec-puppet results govuk should include Class[puppet]

    should include Class[cron] should not raise Puppet::ParseError puppet should contain File[/etc/puppet/puppet.conf] should schedule regular puppet updates Finished in 3.42 seconds 12 examples, 0 failures
  11. gareth rushgrove | morethanseven.net Puppet lint Evaluating manifests/classes/development.pp 14:double_quoted_strings:WARNING:double quoted

    string containing no variables 37:arrow_alignment:WARNING:=> on line isn't properly aligned for resource
  12. gareth rushgrove | morethanseven.net Puppet cloud provisioner puppet node_aws create

    \ --image ami-2d4aa444 \ --type m1.small \ --keypair puppetlabs.admin
  13. knife ec2 server create \ -r "role[webserver]" \ -I ami-2d4aa444

    \ --flavor m1.small gareth rushgrove | morethanseven.net Chef Knife EC2
  14. { "Description" : "Create an EC2 instance running Amazon Linux

    32" "Parameters" : { "KeyPair" : { "Description" : "The EC2 Key Pair to allow SSH access", "Type" : "String" } }, "Resources" : { "Ec2Instance" : { "Type" : "AWS::EC2::Instance", "Properties" : { "KeyName" : { "Ref" : "KeyPair" }, "ImageId" : "ami-75g0061f" } } }, "Outputs" : { "InstanceId" : { "Description" : "The InstanceId of the created EC2 instance", "Value" : { "Ref" : "Ec2Instance" } } }, "AWSTemplateFormatVersion" : "2010-09-09" } gareth rushgrove | morethanseven.net Amazon CloudFormation
  15. gareth rushgrove | morethanseven.net Under the hood - Create Apache

    Virtual host - Setup Ruby web application server - Reload Apache if needed - Setup monitoring checks in Nagios - Send log files to Ganglia and Greylog
  16. gareth rushgrove | morethanseven.net Bootstrap new machines 1. Bring up

    new instance using Fog 2. Install Ruby and Puppet 3. Let instance know what type of node it is 4. Register new instance with puppet master 5. Let Puppet install the rest of required software 6. Collected puppet resources add monitoring
  17. { "role": "client", "platform": "preview", "class": "frontend", "security_groups": ["preview-frontend", "preview"],

    "key": "preview.pem", "flavor": "m1.large", "image": "ami-5c417128", "master": "puppet.example.com", "debug": true, "log_level": 0 } gareth rushgrove | morethanseven.net Describe machine types
  18. { "role": "client", "platform": "preview", "class": "frontend", "security_groups": ["preview-frontend", "preview"],

    "key": "preview.pem", "flavor": "m1.large", "image": "ami-5c417128", "master": "puppet.example.com", "debug": true, "log_level": 0 } gareth rushgrove | morethanseven.net Used by Puppet
  19. gareth rushgrove | morethanseven.net Infrastructure can be described in code

    - Domain specific - Readable - Reviewable - Testable - Reusable
  20. gareth rushgrove | morethanseven.net It’s easy, just start simple -

    Just manage users - Just manage cron jobs - Just manage the web server - Just manage your database configuration
  21. gareth rushgrove | morethanseven.net Talk to people (on IRC) -

    #puppet - #chef - #cfengine - #infratalk all on irc.freenode.net