puppet camp amsterdam 2015: how to leverage the power of the puppet forge

41
Using the Forge PuppetCamp Amsterdam Ger Apeldoorn - http://puppetspeciali

Upload: puppet-labs

Post on 14-Jul-2015

346 views

Category:

Software


2 download

TRANSCRIPT

Using the ForgePuppetCamp Amsterdam

Ger Apeldoorn - http://puppetspecialist.nl

Freelance PuppetConsultant/Trainer

Who's this?

What is a module?

What is a module?

What is a module?

What is a module?

What is a module?

What is a module?

What is a module?

What is a module?

Write our own modules?

Write our own modules?

Not if we can help it!

http://forge.puppetlabs.com

Finding the great ones

Supported & Approved modules

Documentation easy to use?

Is it recent?

Look at the source

Special modules

Special modules

Roles & Profiles

Company-specific module

Implementation layer(Profiles)

Includes regular classes

Might add resources directly

create_resources call

Business layer (Roles)Only includes profiles

No logic at all

One server - One role

Roles & Profiles

These are just regular modules, we just use them differently!

How to do it?

Create roles moduleroot@puppet# mkdir -p role/manifests

Create profiles moduleroot@puppet# mkdir -p profile/manifests

Create a base-profile to cover generic settings# modules/profile/manifests/base.pp:class profile::base { include users include ssh include motd ...

How to do it?

Put all required resources in the profile class# modules/profile/manifests/lamp.pp:class profile::lamp { include apache include mysql create_resources('apache::vhost', ..... create_resources('mysql_database', ..... ...

Combine the required profiles in the role class# modules/role/manifests/frontend.pp:class role::frontend { include profile::base include profile::lamp}

Remember, roles can ONLY include profiles!!!

The company module

The company moduleWhat do we put in there?

Custom Defined typesWrapper defined types and classesSmall classes not interesting for third parties

Hiera introduction

Configured Hierarchy:

#/etc/puppet/hiera.yaml::hierarchy: - "%{::clientcert}" - "%{::environment}" - common

Node app01.autiplan.com:

environment: testing

Hieradata

# hiera/app01.autiplan.com.yaml---examplekey: value for \ app01.autiplan.com

# hiera/testing.yaml---examplekey: value for nodes in \ testing environment

# hiera/common.yaml---examplekey: value for all nodes

It's all about Hierarchy

What will be in $test?

$test = hiera('examplekey')

Types of Hieradata

Regular values# hiera/app01.autiplan.com.yaml---examplekey: value

Types of Hieradata

Arrays# hiera/app01.autiplan.com.yaml---array: [ item1, item2, item3 ]

otherarray: - item1 - item2 - item3

Note: Never use tabs in Hiera files!

Types of Hieradata

Hashes

# hiera/app01.autiplan.com.yaml---hash: key1: value key2: value

Types of Hieradata

Combinations# hiera/app01.autiplan.com.yaml---hash: key1: value key2: value key3: - arrayvalue1 - arrayvalue2 key4: subhashkey1: value subhashkey2: value

Hiera-related functions

...and what to use them for

What does it do?

Retrieves the first-found value in thehierarchy. (top-down)

What to use it for?

Basic variable-lookup.Very easy to create exceptions!

How to use it?

$smarthost = hiera('smarthost')

Example Hieradata

# hiera/mail.autiplan.com.yaml---smarthost: smtp.myprovider.nl

# hiera/testing.yaml---smarthost: testsmtp.autiplan.com

# hiera/common.yaml---smarthost: mail.autiplan.com

hiera('key' [, default_value])

What does it do?

Retrieves the first-found value in thehierarchy. (top-down)

What to use it for?

Basic variable-lookup.Very easy to create exceptions!

How to use it?

$smarthost = hiera('smarthost')

Example Hieradata

# hiera/mail.autiplan.com.yaml---smarthost: smtp.myprovider.nl

# hiera/testing.yaml---smarthost: testsmtp.autiplan.com

# hiera/common.yaml---smarthost: mail.autiplan.com

hiera('key' [, default_value])

What does it do?

Retrieves the first-found value in thehierarchy. (top-down)

What to use it for?

Basic variable-lookup.Very easy to create exceptions!

How to use it?

$smarthost = hiera('smarthost')

Example Hieradata

# hiera/mail.autiplan.com.yaml---smarthost: smtp.myprovider.nl

# hiera/testing.yaml---smarthost: testsmtp.autiplan.com

# hiera/common.yaml---smarthost: mail.autiplan.com

hiera('key' [, default_value])

What does it do?

Retrieves an array or hash valuein the hierarchy, concatinatesall found results

What to use it for?

Combining data from allhierarchy levels.

How to use it?

$users = hiera_array('users')

Example Hieradata

# hiera/app01.autiplan.com.yaml---users: [ 'user1', 'user2' ]

# hiera/testing.yaml---users: [ 'testuser' ]

# hiera/common.yaml---users: [ 'user3', 'user4' ]

hiera_array('key' [, default_value]) (and hiera_hash)

What does it do?

Generates resources from a

HASH.

What to use it for?

Generate any resource based on

data from Hiera.

Can also be used with

hiera_hash to create resources

from all levels!

Example Hieradata

# hiera/web01.autiplan.com.yaml---vhosts: autiplan.com: alias: www.autiplan.com autiplan.dk: alias: www.autiplan.dk docroot: /var/www/html/autiplan.dk autiplan.nl: alias: www.autiplan.nl cdn.autiplan.com: port: 81 docroot: /var/www/html/cdn

create_resources('type', HASH [, default_values])

How to use it?

create_resources ('apache::vhost', hiera('vhosts', {}))

What does it do?

Automatically loads class

parameters from Hiera.

What to use it for?

Specify all class parameters in

Hiera.

Use all hierarchical benefits for

class parameters.

Simplify the use of

parameterized classes.

How to use it?

include mysql::server

Example Hieradata

# hiera/web01.autiplan.com.yaml---mysql::server::root_password: m0ars3cr3t

# hiera/common.yaml---mysql::server::root_password: t0ps3cr3tmysql::server::package_name: mysql-servermysql::server::restart: true

Data bindings

                                   Demo!

Manage your modulesR10K

Simple configurationCreates environment for each branchDownloads all modules listed in Puppetfile (shopping list)

From Puppetforge or Git repositories

Manage your modules

Manage your modulesR10KPuppetfile

*snip*mod 'simondean/iis', '0.1.3'mod 'saz/resolv_conf', '1.0.3'mod 'saz/dnsmasq', '1.0.1'

mod "role", :git => "http://[gerritserver]/puppet-role", :ref => '0.1.0' #tag (or branch) to use*snip*

For more information; take a look at the Manageable Puppet Infrastructure at:http://puppetspecialist.nl/mpi

Any Questions?