using puppet in small infrastructures

70
Puppet & Small Infrastructures Rachel Andrew @rachelandrew

Upload: rachel-andrew

Post on 01-Jul-2015

797 views

Category:

Technology


2 download

DESCRIPTION

I presented these slides at Puppet Camp in London on November 17th and then at our local DevOps meetup in Bristol on November 19th 2014.

TRANSCRIPT

Page 1: Using Puppet in Small Infrastructures

Puppet & Small Infrastructures

Rachel Andrew

@rachelandrew

Page 2: Using Puppet in Small Infrastructures

edgeofmyseat.com

Page 3: Using Puppet in Small Infrastructures

grabaperch.com

Page 4: Using Puppet in Small Infrastructures

Why would a small business use Puppet?

Page 5: Using Puppet in Small Infrastructures

• My background

• Learning Puppet and initial challenges

• Our current use of Puppet

• Why Puppet for small businesses with a handful of servers?

Page 6: Using Puppet in Small Infrastructures

This is my job.

• writer

• tech support person

• bookkeeper

• HR

• filler in of baffling forms from the government

• PHP developer

• front-end web developer

• marketer

• sales person

• public speaker

• … ops person.

Page 7: Using Puppet in Small Infrastructures

Back in my day …

Page 8: Using Puppet in Small Infrastructures

Pre-Puppet

• Infrastructure consisted of a bunch of VPS boxes hosted at Memset

• Configured at different times

• Some set up by me, some by Drew

• Neither of us understood the setups done by the other

• No real handle on what was installed where

Page 9: Using Puppet in Small Infrastructures

Initial setup would be documented but configuration would drift over time as we updated, installed and

fixed things.

Page 10: Using Puppet in Small Infrastructures

“If it ain’t broke, don’t fix it”

Page 11: Using Puppet in Small Infrastructures
Page 12: Using Puppet in Small Infrastructures

Getting Started with Puppet

Page 13: Using Puppet in Small Infrastructures

Puppet or Chef?

Page 14: Using Puppet in Small Infrastructures

https://docs.puppetlabs.com/learning/

Page 15: Using Puppet in Small Infrastructures

https://puppetlabs.com/learn

Page 16: Using Puppet in Small Infrastructures

http://puppetlabs.com/blog/get-more-agile-learn-how-to-automate-one-small-thing-with-puppet-enterprise

“By starting small and getting good at automating one discrete task, you can establish a foundation for bigger automation projects.”

Page 17: Using Puppet in Small Infrastructures

Ideas for small tasks

• cron jobs

• users

• ssh keys

• vhosts

• specific config files - for example a common php.ini

• packages or settings you configure on all servers as standard

Page 18: Using Puppet in Small Infrastructures

Installing packages

package { "sudo": ensure => "installed" }

Page 19: Using Puppet in Small Infrastructures

Using Puppet to create cron jobs.

cron {‘my_cron_job’: command => "php /home/sites/mysite/public_html/perch/core/scheduled/run.php secret", user => root, minute => [1,31], }

Page 20: Using Puppet in Small Infrastructures

Adding standard files.

file {'/etc/php5/apache2/php.ini': ensure => file, source => 'puppet:///modules/hosting/php.ini', notify => Service["apache2"], }

Page 21: Using Puppet in Small Infrastructures

Don’t wait until you have time to rebuild everything. Who ever has

time to rebuild everything?

Page 22: Using Puppet in Small Infrastructures

Not Invented Here.

Page 23: Using Puppet in Small Infrastructures

Is there an existing, well supported module that does this job?

Page 24: Using Puppet in Small Infrastructures

https://forge.puppetlabs.com/supported

Page 25: Using Puppet in Small Infrastructures

Managing Third Party Modules

Page 26: Using Puppet in Small Infrastructures

Dependencies will bite you.

Page 27: Using Puppet in Small Infrastructures

http://garylarizza.com/blog/2014/10/19/on-dependencies-and-order/

“Puppet describes the end-state of the machine, and NOT the order that it’s (Puppet) going to take you to that state”

Page 28: Using Puppet in Small Infrastructures

Where we are now.

Page 29: Using Puppet in Small Infrastructures

• A Puppet Master, PuppetDB is on the same box

• Three webservers

• The “demo server”, also a webserver but of interesting configuration

• PuppetBoard and Scout to see what is happening in Puppet and for monitoring

Page 30: Using Puppet in Small Infrastructures

Webservers

• Puppetlabs Apache, MySQL

• modules/hosting = a module I’ve written than wraps up standard things used on webservers

• make use of hiera for site, database and user values

Page 31: Using Puppet in Small Infrastructures

Discovering Hiera made Puppet make sense to me.

Page 32: Using Puppet in Small Infrastructures

A common.yaml file holds information common to all servers. For example user accounts.

--- users: rachel: comment: "Rachel Andrew" shell: "/bin/bash" home: "/home/rachel" managehome: "true" groups: ['admin','www-admin'] drew: comment: "Drew McLellan" shell: "/bin/bash" home: "/home/drew" managehome: "true" groups: ['admin','www-admin'] ssh_keys: rachel_ssh: user: "rachel" type: "rsa" key: "AAAABB[...]" drew_ssh: user: "drew" type: "rsa" key: "AAAABB[...]"

Page 33: Using Puppet in Small Infrastructures

Information specific to one server is held in node specific YAML files.

eg: vhosts and MySQL databases.

--- apache_vhosts: example.co.uk: port: '8080' docroot: '/home/sites/example/public_html' docroot_group: 'www-admin' servername: 'example.co.uk' serveraliases: ['example.com'] test.co.uk: port: '8080' docroot: '/home/sites/test/public_html' docroot_group: 'www-admin' servername: 'test.co.uk' serveraliases: ['test.com']

mysql_db: db_a: user: 'user_a' password: 'xxxxx' grant: ['all'] db_b: user: 'user_b' password: 'xxxxx' grant: ['all']

Page 34: Using Puppet in Small Infrastructures

The hiera.yaml file.

--- :backends: - yaml

:logger: console :yaml: :datadir: /etc/puppet/hiera

:hierarchy: - "%{::fqdn}" - common

Page 35: Using Puppet in Small Infrastructures

hiera_hash gives an array of users, hosts and databases from the node specific YAML.

I can use that in create_resources within manifests.

$sites = hiera_hash('apache_vhosts')

create_resources('apache::vhost',$sites)

$db = hiera_hash('mysql_db')

create_resources('mysql::db',$db)

Page 36: Using Puppet in Small Infrastructures

http://garylarizza.com/blog/2014/10/24/puppet-workflows-4-using-hiera-in-anger/

“When you come up with a solution using create_resources(), I challenge you to draw up another solution using Puppet code in a Puppet manifest”

Page 37: Using Puppet in Small Infrastructures

Hiera and the demo server.

Page 38: Using Puppet in Small Infrastructures

Standard CMS demos allow everyone access to one install

which is “refreshed” periodically.

Page 39: Using Puppet in Small Infrastructures

We wanted to give everyone a clean demo all of their own.

Page 40: Using Puppet in Small Infrastructures
Page 41: Using Puppet in Small Infrastructures

Hiera can have multiple backends defined.

Hiera can use json as well as YAML.

--- :backends: - yaml - json

:logger: console :yaml: :datadir: /etc/puppet/hiera :json: :datadir: /etc/puppet/hiera

:hierarchy: - '%{fqdn}' - common

Page 42: Using Puppet in Small Infrastructures

deploy.pp

• create a home directory

• grab the site files tarball and untar into the home directory

• get the relevant SQL dump

• grab the config file and replace out db details

• create a database using the import file

• create a vhost

• execute a script to notify Air Traffic Control the site is ready

Page 43: Using Puppet in Small Infrastructures

• json Hiera backend is the source of truth for Puppet as to what sites should be running

• could deploy to multiple servers by writing multiple json files one for each node

• can deploy different versions of Perch - for example to allow someone to try out a beta

• currently deploying and tearing down 50 or 60 sites per day. It just works.

Page 44: Using Puppet in Small Infrastructures

Start small with Puppet, but be aware of non-obvious problems

that Puppet can help solve.

Page 45: Using Puppet in Small Infrastructures

I use Vagrant and Puppet to test and build the site packages locally.

Page 46: Using Puppet in Small Infrastructures

Why should small business and small infrastructures consider

Puppet?

Page 47: Using Puppet in Small Infrastructures

Disaster Recovery

Page 48: Using Puppet in Small Infrastructures

Small companies

• often don’t need hugely redundant infrastructures

• having sites offline for a few hours not critical

• … as long as everything can be restored.

Page 49: Using Puppet in Small Infrastructures

Before Puppet

• Rebuilding our infrastructure would have involved us “trying to remember” what went where.

• Just getting servers reinstalled would have taken a long time.

• Then we would have had to reconfigure every site, every SSH key, one at a time.

Page 50: Using Puppet in Small Infrastructures

With Puppet

• Configuration for each server is held in code, and in an external git repo

• Checkout the modules onto a new Puppet Master

• Spin up new servers and run Puppet which would create all resources - sites, keys etc.

• We could then import any data such as MySQL backups

Page 51: Using Puppet in Small Infrastructures

A good test - can you restore any of your servers into a local VM?

Page 52: Using Puppet in Small Infrastructures

How do we do that thing again?

Page 53: Using Puppet in Small Infrastructures

Puppet allows us to document processes by way of manifests.

Page 54: Using Puppet in Small Infrastructures

The git commit history gives me additional information as to why

something is configured that way.

Page 55: Using Puppet in Small Infrastructures

Please look after this server.

Page 56: Using Puppet in Small Infrastructures

Get an expert up to speed quickly

Page 57: Using Puppet in Small Infrastructures

Ensure knowledge isn’t lost when someone leaves the company

Page 58: Using Puppet in Small Infrastructures

Small businesses are often far more exposed than large ones to

losing knowledge when a key person leaves.

Page 59: Using Puppet in Small Infrastructures

Easier audits and compliance

Page 60: Using Puppet in Small Infrastructures

http://blog.bluemalkin.net/pci-compliance-tips-for-sys-admins/

“It is generally acceptable to show the Puppet modules to the auditor to demonstrate what settings are applied to the PCI servers.”

Page 61: Using Puppet in Small Infrastructures

Speed of setting up new servers

Page 62: Using Puppet in Small Infrastructures

Puppet means I don’t need to spend time and energy remembering how

to do things on our servers.

Page 63: Using Puppet in Small Infrastructures

Moving hosting or to new servers within a hosting company

Page 64: Using Puppet in Small Infrastructures

Getting “stuck” on terrible hosting is a real issue for small businesses

Page 65: Using Puppet in Small Infrastructures

Being Puppetized makes moving the entire infrastructure seem far

less scary.

Page 66: Using Puppet in Small Infrastructures

Modules from the Forge

Page 67: Using Puppet in Small Infrastructures

Modules show best practice ways of achieving tasks.

Page 68: Using Puppet in Small Infrastructures

The Puppet Community

Page 69: Using Puppet in Small Infrastructures

https://docs.puppetlabs.com/community/community_guidelines.html

“We like nice people way better than mean ones!”

Page 70: Using Puppet in Small Infrastructures

Thank you

http://rachelandrew.co.uk/presentations/puppet

@rachelandrew