Skip to content

Instantly share code, notes, and snippets.

@garethr
Last active August 29, 2015 14:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save garethr/ab1cc3508c15d7805cec to your computer and use it in GitHub Desktop.
Save garethr/ab1cc3508c15d7805cec to your computer and use it in GitHub Desktop.
Puppet in 6 code examples

Manage packages, files, services, users and groups

package { 'nginx':
  ensure => present,
}

service { 'nginx':
  ensure => running,
}







Manage higher level resources too

class { 'docker':
  version => 'latest',
}

docker::run { 'hellocambridge':
  image   => 'base',
  command => '/bin/sh -c "while true; do echo hello cambridge; sleep 1; done"',
}







Windows and Unix, as well as Linux

iis::manage_app_pool {'my_application_pool':
  enable_32_bit           => true,
  managed_runtime_version => 'v4.0',
}
iis::manage_site {'www.mysite.com':
  site_path   => 'C:\inetpub\wwwroot\mysite',
  port        => '80',
  ip_address  => '*',
  host_header => 'www.mysite.com',
  app_pool    => 'my_application_pool'
  }







Not just host level resources, infrastructure as a service and network devices too

ec2_instance { 'webserver':
  ensure            => present,
  region            => 'eu-west-1',
  image_id          => 'ami-123456',
  instance_type     => 't1.micro',
}







Create a model for your infrastructure

node /^webserver/ {
  include roles::web
}

class roles::web {
  include profiles::base
  include profiles::users
  include profiles::webserver
}







Tooling support; unit testing, code coverage, syntax highlighting

be rake spec
...
docker::run
  on Archlinux
    with an invalid title
      should contain Service[docker-sample]
    with an invalid image name
      should contain Service[docker-sample]
    with an invalid running value
      should contain Service[docker-sample]
    with an invalid memory value
      should contain Service[docker-sample]
    with a missing memory unit
      should contain Service[docker-sample]

Finished in 30.97 seconds
348 examples, 0 failures

Total resources:   87
Touched resources: 39
Resource coverage: 44.83%
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment