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

Machines Dancing Like Marionettes

Machines Dancing Like Marionettes

We talk a lot about the best practices in how we build things, how our front-ends work, how we automate our testing, deployments, project bootstrapping, etc, but for the most part, we neglect the very foundation of our stack, the servers we deploy on, so let's delve into the world of server automation and get those boxes dancing like marionettes as we pull the strings.

Daniel Knell

January 19, 2015
Tweet

More Decks by Daniel Knell

Other Decks in Programming

Transcript

  1. Resources package { "nodejs": ensure => present } file {

    "/etc/motd": ensure => present, content => "HELLO!" } service { "redis-server": ensure => running }
  2. Variables $greeting = "HELLO" $ensure = present file { "/etc/motd":

    ensure => $ensure, content => "${greeting} WORLD!" }
  3. Classes class nodejs ($ensure = present) { package { "nodejs":

    ensure => $ensure } } class { "nodejs": ensure => absent } include nodejs
  4. Nodes node "www.example.com" { include nodejs } node "www01.example.com", "www02.example.com",

    "www03.example.com" { include nodejs } node /^www\d+\.example\.com/ { include nodejs } node "default" { include nodejs }
  5. Files # /etc/puppet/modules/motd/manifests/init.pp class motd { file { "/etc/motd": ensure

    => present, source => “puppet://motd/motd.txt" } } # /etc/puppet/modules/motd/files/motd.txt HELLO WORLD!
  6. Facter $ facter architecture => x86_64 domain => local facterversion

    => 1.6.17 fqdn => Obsidian.local hardwareisa => i386 hardwaremodel => x86_64 hostname => Obsidian id => daniel interfaces => lo0,gif0,stf0,en0,p2p0,vboxnet0,vboxnet1,utun1,utun0 ipaddress => 10.0.1.8 ipaddress6 => fd29:252f:ec95:f2ff:f4ba:3854:6dd:ea40 ipaddress_en0 => 10.0.1.8 ipaddress_lo0 => 127.0.0.1 ipaddress_vboxnet0 => 192.168.33.1 ipaddress_vboxnet1 => 172.16.0.1 is_virtual => false kernel => Darwin kernelmajversion => 12.2 kernelrelease => 12.2.1 kernelversion => 12.2.1
  7. Facts class motd { file { "/etc/motd": ensure => present,

    content => "Welcome to ${::hostname}!" } }
  8. Templates # /etc/puppet/modules/motd/manifests/init.pp class motd { file { "/etc/motd": ensure

    => present, content => template("motd/motd.erb") } } # /etc/puppet/modules/motd/templates/motd.erb Welcome to <%= @hostname %>!
  9. Custom Resource Types # /etc/puppet/modules/nginx/manifests/site.pp define nginx::site ( $aliases )

    { file { "/etc/nginx/conf/sites/${name}": ensure => present, content => template("nginx/site.erb") } file { "/var/www/${name}": ensure => directory } } # /etc/puppet/modules/websites/manifests/init.pp class websites { nginx::site { "www.example.com": aliases => [ "example.com" ] } nginx::site { "www.example.org": aliases => [ "example.org" ] } }
  10. RSpec Puppet # /etc/puppet/modules/ntp/spec/classes/redis_server_spec.rb require 'spec_helper' describe ‘redis’, :type =>

    :class do it { should include_class(‘redis') } it do should contain_file(‘redis::config’).with({ :ensure => 'present', :path => ‘/etc/redis/redis.conf’ }) end context "with ensure => absent" do let(:params) { {:ensure => 'absent'} } it { should contain_package(‘redis-server’).with_ensure(‘absent') } it { should_not contain_service(‘redis-server’) } it { should contain_file(‘redis::config’).with_ensure('absent') } end end
  11. Links •Puppet Labs - http://puppetlabs.com/ •Hiera - http://projects.puppetlabs.com/projects/hiera •Librarian Puppet

    - http://librarian-puppet.com/ •Puppet Forge - http://forge.puppetlabs.com/ •Puppet Lint - http://puppet-lint.com/ •RSpec Puppet - http://rspec-puppet.com/ •Vagrant - http://vagrantup.com/ •Boxen - http://boxen.github.com/