Download - Puppet and AWS: Getting the Best of Both Worlds

Transcript
Page 1: Puppet and AWS: Getting the Best of Both Worlds

WELCOME

Puppet and AWSGetting the Best of Both Worlds

Mike Ryan - Epitech BV23

August2013

CONTACT:[email protected]

Saturday, August 24, 13

Page 2: Puppet and AWS: Getting the Best of Both Worlds

EPITECH BV

Hello, I’m Mike2

CONTACT:[email protected]

Sysadmin  with  a  passion  for  automa2on

Londoner  in  Amsterdam

Epitech.nl  -­‐  sysadmin  as  a  service

Saturday, August 24, 13

Page 3: Puppet and AWS: Getting the Best of Both Worlds

EPITECH BV

AWS - A very brief introduction

3

CONTACT:[email protected]

EC2  -­‐  Elas2c  Compute  Cloud

AMI  -­‐  Amazon  Machine  Images

User  Data

Saturday, August 24, 13

Page 4: Puppet and AWS: Getting the Best of Both Worlds

EPITECH BV

EC2 - Auto Scaling4

CONTACT:[email protected]

Saturday, August 24, 13

Page 5: Puppet and AWS: Getting the Best of Both Worlds

EPITECH BV

CloudFormation5

CONTACT:[email protected]

{ "AWSTemplateFormatVersion" : "2010-09-09", "Description" : "EC2 instance", "Resources" : { "MyEC2Instance" : { "Type" : "AWS::EC2::Instance", "Properties" : { "ImageId" : "ami-79fd7eee", "KeyName" : "my-ssh-key", } } }}

Saturday, August 24, 13

Page 6: Puppet and AWS: Getting the Best of Both Worlds

EPITECH BV

6

CONTACT:[email protected]

"Enabled" : "true", "Logging" : { "Bucket" : "webapplication.s3.amazonaws.com", "Prefix" : "webapp-logging/" } } } },

"asgMyAutoScalingGroup": { "Type": "AWS::AutoScaling::AutoScalingGroup", "Properties": { "AvailabilityZones": [ "us-east-1b", "us-east-1c" ], "Cooldown": "300", "DesiredCapacity": "1", "MaxSize": "1", "MinSize": "1", "LaunchConfigurationName": { "Ref": "lcMyLC" }, "LoadBalancerNames": [ { "Ref": "elbMyLB" } ] } }, "s3webapplication": { "Type": "AWS::S3::Bucket" }, "sgwebappsecuritygroup": { "Type": "AWS::EC2::SecurityGroup", "Properties": { "GroupDescription": "for web app", "SecurityGroupIngress": [

Saturday, August 24, 13

Page 8: Puppet and AWS: Getting the Best of Both Worlds

EPITECH BV

8

CONTACT:[email protected]

CloudFormation or Puppet

Saturday, August 24, 13

Page 9: Puppet and AWS: Getting the Best of Both Worlds

EPITECH BV

9

CONTACT:[email protected]

Files, Services and Packages with cfn-init

"Metadata": { "AWS::CloudFormation::Init": { "config": { "sources" : { "/etc/puppet" : "http://example.com/puppet.tar.gz" }, "packages": { "yum": { "puppet-server": [], }, }, "services": { "sysvinit": { "puppetmaster": { "ensureRunning": "true", "enabled": "true"

Saturday, August 24, 13

Page 10: Puppet and AWS: Getting the Best of Both Worlds

EPITECH BV

10

CONTACT:[email protected]

Run a script at launch time with User Data

{ "AWSTemplateFormatVersion" : "2010-09-09", "Description" : "EC2 instance", "Resources" : { "PuppetMasterInstance": { "Type": "AWS::EC2::Instance", "Metadata": { }, "Properties": { "UserData": { "Fn::Base64": { "Fn::Join": [ "", [ "#!/bin/bash\n", "/opt/aws/bin/cfn-init --region ", "\n", "/usr/bin/puppet apply site.pp, "\n" ]...

Saturday, August 24, 13

Page 12: Puppet and AWS: Getting the Best of Both Worlds

EPITECH BV

12

CONTACT:[email protected]

Auto Scale = Autosign

Saturday, August 24, 13

Page 13: Puppet and AWS: Getting the Best of Both Worlds

EPITECH BV

13

CONTACT:[email protected]

The Hostname Issuemike@ip-10-32-34-116:~$ hostname -fip-10-32-34-116.eu-west-1.compute.internal

Saturday, August 24, 13

Page 14: Puppet and AWS: Getting the Best of Both Worlds

EPITECH BV

14

CONTACT:[email protected]

User Data - Web Console

Saturday, August 24, 13

Page 15: Puppet and AWS: Getting the Best of Both Worlds

EPITECH BV

15

CONTACT:[email protected]

User Data - CloudFormation},"UserData": { "Fn::Base64": { "Fn::Join": [ "", [ “{\”role\”: \”web\”, ”, “\”env\”: \”staging\”} ” ] ] }}

Saturday, August 24, 13

Page 16: Puppet and AWS: Getting the Best of Both Worlds

EPITECH BV

16

CONTACT:[email protected]

include stdlibnode default {  $userdata = parsejson($ec2_userdata) $role = userdata[‘role’] $environment = userdata[‘env’]

case $role { ‘web’: { include nginx } ‘db’: { include postgresql } }}

Saturday, August 24, 13

Page 17: Puppet and AWS: Getting the Best of Both Worlds

EPITECH BV

17

CONTACT:[email protected]

Vagrant -> EC2

Saturday, August 24, 13

Page 18: Puppet and AWS: Getting the Best of Both Worlds

EPITECH BV

18

CONTACT:[email protected]

Saturday, August 24, 13

Page 19: Puppet and AWS: Getting the Best of Both Worlds

EPITECH BV

19

CONTACT:[email protected]

Vagrant::Config.run do |config| config.vm.provision :puppet do |puppet| puppet.manifests_path = "../puppet/manifests" puppet.module_path = "../puppet/modules" puppet.manifest_file = "site.pp" puppet.options = "--verbose --debug" puppet.facter = { :ec2_userdata => { :role => "database", :env => "vagrant", }.to_json, :vagrant => "true" } endend

Saturday, August 24, 13

Page 20: Puppet and AWS: Getting the Best of Both Worlds

EPITECH BV

20

CONTACT:[email protected]

Decoupling

Saturday, August 24, 13

Page 21: Puppet and AWS: Getting the Best of Both Worlds

EPITECH BV

21

CONTACT:[email protected]

Broken Puppet Master =Broken Auto Scaling

No

Saturday, August 24, 13

Page 22: Puppet and AWS: Getting the Best of Both Worlds

EPITECH BV

22

CONTACT:[email protected]

#!/bin/bash

/usr/local/bin/update.sh/usr/bin/puppet apply site.pp

/etc/rc.local

Saturday, August 24, 13

Page 23: Puppet and AWS: Getting the Best of Both Worlds

EPITECH BV

23

CONTACT:[email protected]

But you lose...

Puppet  Dashboard

Exported  Resources

Stored  configs

Saturday, August 24, 13

Page 24: Puppet and AWS: Getting the Best of Both Worlds

EPITECH BV

24

CONTACT:[email protected]

env.roledefs = { 'web': ['www1', 'www2', 'www3'], 'db': ['db1', 'db1']}

@roles('db', ‘web’)def run_puppet(): sudo('puppet apply site.pp')

$fab run_puppet #run puppet everywhere$fab run_puppet --roles db # role-specific

Triggering Puppet with Fabric

Saturday, August 24, 13

Page 25: Puppet and AWS: Getting the Best of Both Worlds

EPITECH BV

25

CONTACT:[email protected]

def configure_roles():

 tags = EC2TagManager(AWS_KEY, AWS_SECRET,   regions=['eu-west-1'])

 roles = {}

for role in [‘db’, ‘web’]: roles[role] = tags.get_instances(role=role) return roles

Triggering Puppet with Fabric

https://github.com/mikery/fabric-ec2

Saturday, August 24, 13