+ All Categories
Home > Documents > Beeing a puppet master

Beeing a puppet master

Date post: 14-Feb-2017
Category:
Upload: vutuyen
View: 229 times
Download: 1 times
Share this document with a friend
34
Being a puppet master More money, more time, more happiness, less work Thomas Merkel <[email protected]> http://www.flickr.com/photos/serenaseblu/5062987760/
Transcript
Page 1: Beeing a puppet master

Being a puppet master

More money, more time, more happiness, less work

Thomas Merkel <[email protected]>

http://www.flickr.com/photos/serenaseblu/5062987760/

Page 2: Beeing a puppet master

Agenda• Overview

• Organize the master

• Modules

• Resources types

• Syntax (if, else, switch, case, class)

• Example

• Tools (facter, hiera, mcollective)

• Demo and recommendation

• It’s working time now :-)

2

Page 3: Beeing a puppet master

http://www.flickr.com/photos/oarranzli/8020469583/

Where I want to be … need more alcohol

3

Page 4: Beeing a puppet master

Basic Overview• Stop administrating your env. and start

developing it

• Supports Linux, BSD, Solaris and Windows

• Re-usable code for managing software and configuration

• Provides a domain specific language to scripts (classes, conditions, selectors, variables, …)

4

Page 5: Beeing a puppet master

Basic Overview

• Support >20 different package providers

• Support >10 different init frameworks

• Control whenever a service needs to be started or stopped

• Service could be notified to restart

5

Page 6: Beeing a puppet master

Things you need to know

• Nodes - Machine to configure, identify by hostname

• Modules - Collection of classes and files

• Class - A collection of resources related to each other

• Resources - Things like packages, files, users, etc.

• Defines - A function-like construct for resources

6

Page 7: Beeing a puppet master

High-Level OverviewPuppet Master ConfigurationModules

Puppet Agent / Clients

Monitoring DNS Syslog Webserver

General Infrastructure

Software Development Environment

Development Testing Acceptance Production

7

Page 8: Beeing a puppet master

Network Overview

• Client or server initiated synchronizations

• CA on the puppet master to sign client certificates to verify authentication

• Transmission of all data between a master & client are encrypted

Puppet Client

Puppet Master

SSL8140/TCP

Client initiated puppet agent -t

8139/TCP Server initiated puppet kick

8

deprecated,!use mcollective

Page 9: Beeing a puppet master

Organize the master9

Page 10: Beeing a puppet master

Example (puppetmaster)• Location mostly on Linux `/etc/puppet`

• There are multiple ways to the holy grail!"" fileserver.conf!"" hieradata$   &"" common.yaml!"" manifests$   !"" node.pp$   &"" site.pp!"" modules$   &"" ssh$   !"" manifests$   $   &"" init.pp$   &"" templates$   &"" sshd_config.erb!"" puppet.conf&"" templates

10

Page 11: Beeing a puppet master

Module structure• Encapsulate a logical segment of an machines setup

• Thousands of modules exists

manifests/

files/

templates/

lib/

Tell the module how to work

Static files needed for development

Dynamic ruby-based templates

Relevant ruby-based libraries

11

Page 12: Beeing a puppet master

Resources types• files & directories

• users & groups

• services

• packages

• crontabs

• mount points

• nagios

• selinux

• ssh keys

• third party repositories (yum, apt, etc.)

Many many more :-) !

!

http://docs.puppetlabs.com/references/latest/type.html

12

Page 13: Beeing a puppet master

http://www.flickr.com/photos/tonymaro/2763463522

Syntax

13

Page 14: Beeing a puppet master

Syntax - Class

# single classclass ntp { … }!

# inherited classclass sftp inherits ssh { … }!

# scoped classclass ntp::base { … }

14

Page 15: Beeing a puppet master

Syntax - Resources

service { ‘httpd‘: ensure => running, enable => true, hasstatus => true, hasrestart => true,}

Type Title

Attributes15

Page 16: Beeing a puppet master

Syntax - if/else

if ($environment == “production“) { include powerdns} else { include bind}

16

Page 17: Beeing a puppet master

Syntax - switch/case

case $operatingsystem { Debian|Ubuntu: { include nagios::debian } CentOS: { include nagios::centos }}

17

Page 18: Beeing a puppet master

Example

http://www.flickr.com/photos/imsnotreal/2994415670/18

Page 19: Beeing a puppet master

Example## /etc/puppet/manifests/site.pp - first file!Exec { path => [ "/usr/local/bin","/usr/bin","/bin","/usr/local/sbin","/usr/sbin","/sbin","/opt/local/bin","/opt/local/sbin" ] }!## import some config filesimport "common"# auto-config files that are deployed by limeade or some other # services contains important variables and config settings for # some puppet-modulesimport "import/*.pp"# all nodes that are static configuredimport "nodes"

19

Page 20: Beeing a puppet master

## /etc/puppet/manifests/node.pp!## default node, deploy on all nodesnode default {»···include sudo»···include concat::setup»···include apt}!## qwecompany nodesnode qwecompany inherits default {»···include ssh»···include qwecompany_base»···include munin}!node 'net-dev.qwe123.de' inherits qwecompany {»···include qwecompany_net}

20

Page 21: Beeing a puppet master

## /etc/puppet/modules/ssh/manifests/init.ppclass ssh ($permitRootLogin='no',$port='22',$passwordAuth='no'){»···package {'openssh-server':»···»···ensure => present »···}»···file {'/etc/ssh/sshd_config':»···»···content => template('ssh/sshd_config.erb'),»···»···mode => '0400', »···»···notify => Service['sshd'],»···»···require => Package['openssh-server'],»···}»···service {'sshd':»···»···name => 'ssh',»···»···ensure => running,»···»···enable => true,»···»···hasstatus => true,»···»···hasrestart => true,»···»···require => File['/etc/ssh/sshd_config'],»···}}

21

Page 22: Beeing a puppet master

## /etc/puppet/modules/ssh/templates/sshd_config.erbPort <%= port %>#Port 22Protocol 2![…]!# Authentication:LoginGraceTime 2mPermitRootLogin <%= permitRootLogin %>StrictModes yes#MaxAuthTries 6![…]

22

Page 23: Beeing a puppet master

Facter

• Describes aspect of your machine - „facts“

• Facts written in Ruby

• Nice libraries of existing facts

• Custom facts are easy

23

Page 24: Beeing a puppet master

Factertmerkel@arena:~$ facterarchitecture => amd64augeasversion => 1.1.0domain => srv.avira.netfacterversion => 1.7.5filesystems => ext3,ext4,vfatfqdn => arena.srv.avira.nethardwareisa => x86_64hardwaremodel => x86_64hostname => arenainterfaces => eth0,eth1,loipaddress => 62.146.210.70ipaddress_eth0 => 62.146.210.70ipaddress_eth1 => 62.146.211.70ipaddress_lo => 127.0.0.1is_virtual => true

24

Page 25: Beeing a puppet master

Hiera

• Hierarchal data lookup system

• Structured data backend

• YAML, JSON, current puppet state

• Example: storage ssh keys in YAML hiera db

25

Page 26: Beeing a puppet master

Hiera - default lookup• Default lookup for class parameter

# /etc/puppet/hieradata/web01.example.com.yaml---ssh::permitRootLogin: "yes"ssh::port: 22!# /etc/puppet/hieradata/common.yaml---ssh::permitRootLogin: "no"

26

Page 27: Beeing a puppet master

Hiera - lookup function# /etc/puppet/hieradata/appservers.yaml---proxies: - hostname: lb01.example.com ipaddress: 192.168.22.21 - hostname: lb02.example.com ipaddress: 192.168.22.28

# Get the structured data:$proxies = hiera('proxies')!# Index into the structure:$use_ip = $proxies[1]['ipaddress'] # will be 192.168.22.28

27

Page 28: Beeing a puppet master

Marionette Collective

http://www.flickr.com/photos/leonardo_pilara/12121189764/28

Page 29: Beeing a puppet master

MCollective• Manage / Control / Execute

• Services

• Packages

• Process information

• Facter facts

• Pings29

Page 30: Beeing a puppet master

30

Demonstration

Page 31: Beeing a puppet master

Recommendation• Use `git`, bitch :-)

• git for every puppet module

• git submodules to combine them

• Minimum number of puppet master (it can handle >5000 servers without any problem)

• Manage everything with puppet, don’t make exceptions on an server

31

Page 32: Beeing a puppet master

Recommendation• Scale the master with unicorn or some other ruby thingy

• Start using it, if something fails create a new puppet master and move modules

• Check out public modules that are available

• https://github.com/drscream

• Please test the puppet agent on Windows

• Check mcollective if the usage would be helpful

32

Page 33: Beeing a puppet master

THE END

http://www.flickr.com/photos/andrewhurley/6254409229/33

What’s next?

Page 34: Beeing a puppet master

It’s working time :-)• Puppet master

[email protected]

• Puppet clients

[email protected]

[email protected]

• missing windows server34


Recommended