52
Dan Bode| Puppet Labs [email protected] bodepd <on> [twitter,freenode] Puppet as Data Transformations

Puppet as data_chicago

  • Upload
    bodepd

  • View
    709

  • Download
    2

Embed Size (px)

Citation preview

Page 1: Puppet as data_chicago

Dan Bode| Puppet Labs

[email protected] bodepd <on> [twitter,freenode]

Puppet as DataTransformations

Page 2: Puppet as data_chicago

# puppetcamp # puppetize @ puppetlabs

What is it about?

• Deconstructing Puppet to data

• Why you should care

Page 3: Puppet as data_chicago

Dissecting a Puppet Run

Part One

Page 4: Puppet as data_chicago

# puppetconf # puppetize @ puppetlabs

Facter, who am I?

Agent

Hi! your facts are:

kernel=linuxipaddress=10.0.0.3macaddress=…

Page 5: Puppet as data_chicago

# puppetconf # puppetize @ puppetlabs

Hi Mr. Master, I need a catalog. Here are my facts

http://www.dgcomputers.org/testimonials.php

Agent

facts

Page 6: Puppet as data_chicago

# puppetconf # puppetize @ puppetlabs

facts

AgentThanks for you

facts.I’ll just store them

in PuppetDBPuppetDB

Page 7: Puppet as data_chicago

# puppetconf # puppetize @ puppetlabs

PuppetDBPuppetDB

facts

ENCENC

Agent

Mr. ENC, is this host defined as

an external node?Yep, he should be an apache server.

Here is the definition

nodes

Page 8: Puppet as data_chicago

# puppetconf # puppetize @ puppetlabs

PuppetDBPuppetDB

facts

AgentJust compiled

your catalog. One sec while I store it

in PuppetDB.

catalog

Page 9: Puppet as data_chicago

# puppetconf # puppetize @ puppetlabs

PuppetDBPuppetDB

facts

Agent

catalog

Here is your catalog. Send me a report and let me know how it

went!

catalog

Page 10: Puppet as data_chicago

# puppetconf # puppetize @ puppetlabs

PuppetDBPuppetDB

facts

Agent

catalog

I hate to be a bother, but

can you compute the md5sums of

this file?

catalog

Page 11: Puppet as data_chicago

# puppetconf # puppetize @ puppetlabs

PuppetDBPuppetDB

facts

Agent

catalog

Oh, I need that one!

Can I get the file.

catalog

Page 12: Puppet as data_chicago

# puppetconf # puppetize @ puppetlabs

PuppetDBPuppetDB

facts

Agent

catalog

Thanks, now let’s just do that 1000

more times.

catalog

Page 13: Puppet as data_chicago

# puppetconf # puppetize @ puppetlabs

PuppetDBPuppetDB

facts

Agent

catalog

You know ‘content’ will embed the contents in the catalog?

catalog

Page 14: Puppet as data_chicago

# puppetconf # puppetize @ puppetlabs

PuppetDBPuppetDB

facts

AgentJust finished

applying. Here are the results.

report

catalog

Page 15: Puppet as data_chicago

Puppet’s internal data language (indirectory/termini)

Part Two

Page 16: Puppet as data_chicago

# puppetconf # puppetize @ puppetlabs

facts find from terminus facter

Agent

Page 17: Puppet as data_chicago

# puppetconf # puppetize @ puppetlabs

catalog find from terminus rest

http://www.dgcomputers.org/testimonials.php

Agent

facts

Page 18: Puppet as data_chicago

# puppetconf # puppetize @ puppetlabs

facts

Agentfacts save to

terminus puppetdb

PuppetDB

Page 19: Puppet as data_chicago

# puppetconf # puppetize @ puppetlabs

PuppetDBPuppetDB

facts

ENCENC

Agent

node find from terminus exec (or

ldap)

nodes

Page 20: Puppet as data_chicago

# puppetconf # puppetize @ puppetlabs

PuppetDBPuppetDB

facts

Agentcatalog find from terminus compiler

catalog

Page 21: Puppet as data_chicago

# puppetconf # puppetize @ puppetlabs

PuppetDBPuppetDB

facts

Agentcatalog save to

terminus puppetdb

catalog

Page 22: Puppet as data_chicago

# puppetconf # puppetize @ puppetlabs

FacterFacter ENCENC

Disecting a Puppet Run

Com

pil

er

Com

pil

er

Config Catalogs

Nodes/Manife

st

Reports

Facts

Page 23: Puppet as data_chicago

# puppetconf # puppetize @ puppetlabs

CLI commands

Page 24: Puppet as data_chicago

# puppetcamp # puppetize @ puppetlabs

CLI Puppet Facts

# mkdir –p /tmp/yaml/facts

# puppet facts find node_name --render-as yaml \

> /tmp/yaml/facts/node_name.yaml

Page 25: Puppet as data_chicago

# puppetcamp # puppetize @ puppetlabs

Creating a node (optional):

# mkdir –p /tmp/yaml/nodes

# puppet node find node_name \

--node_terminus=exec \

--external_nodes=/etc/puppet/nodes.sh \

--facts_terminus=yaml \

--clientyamldir=/tmp/yaml/ --render-as=yaml \

> /tmp/yaml/nodes/node_name.yaml

Page 26: Puppet as data_chicago

# puppetcamp # puppetize @ puppetlabs

Applying a catalog:

# puppet catalog find node_name \

/tmp/catalog.yaml

Page 27: Puppet as data_chicago

# puppetcamp # puppetize @ puppetlabs

Creating a catalog:

# puppet apply –catalog /tmp/catalog.yaml

(its easy assuming you are not using file sources)

Page 28: Puppet as data_chicago

# puppetconf # puppetize @ puppetlabs

Fun with IRB

Page 29: Puppet as data_chicago

# puppetcamp # puppetize @ puppetlabs

IRB Facts

irb:> require ‘puppet/face’

> Puppet.parse_config # required Puppet > 3.0

> facts=Puppet::Face[:facts, :current].find('node_name')

Page 30: Puppet as data_chicago

# puppetcamp # puppetize @ puppetlabs

Access a Fact value (irb):

> facts.values['ipaddress']

=> "10.0.2.15"

Page 31: Puppet as data_chicago

# puppetcamp # puppetize @ puppetlabs

Creating a node (from irb):

> node=Puppet::Node.new('node_name',

{:classes => {:foo => {:bar => :baz}}})

>node.merge(facts.values)

Page 32: Puppet as data_chicago

# puppetcamp # puppetize @ puppetlabs

Creating a catalog:

irb> catalog=Puppet::Face[:catalog, :current].\

find('node_name', :extra => { :node => node})

Page 33: Puppet as data_chicago

Interacting with Puppet’s Data

Use Cases

Page 34: Puppet as data_chicago

# puppetcamp # puppetize @ puppetlabs

Inspecting the catalog:

• What types are in the catalog?

irb> catalog.resources.collect {|r| r.type }.uniq

• Gimme a resource:

irb>catalog.resource(‘Package[httpd]’)

Page 35: Puppet as data_chicago

# puppetcamp # puppetize @ puppetlabs

Rspec Puppet:

let :facts do

{:operatingsystem => ‘Redhat’}

end

let :params do

{:bind_address => ‘0.0.0.0’

end

it { should contain_file(‘/tmp/foo.conf’) }

Page 36: Puppet as data_chicago

# puppetcamp # puppetize @ puppetlabs

Thundering Herd

Pre-compile catalogs for faster auto-scaling

Page 37: Puppet as data_chicago

# puppetcamp # puppetize @ puppetlabs

Applying pre-compiled catalogs:

• Gather facts from an ec2 instance

• Generate a single catalog

• Apply that catalog to all hosts

puppet apply --catalog /tmp/catalog.json –

server puppet-fileserver

Page 38: Puppet as data_chicago

# puppetcamp # puppetize @ puppetlabs

DMZ

tcp over USB

Page 39: Puppet as data_chicago

Interacting with Puppet’s Data

Use Cases

Page 40: Puppet as data_chicago

# puppetcamp # puppetize @ puppetlabs

Hacking reports

Everything in Puppet is a state transition

User[‘dan’] : absent -> present

User[‘dan’][‘shell’] -> ‘/sbin/nologin’ -> /bin/bash

Page 41: Puppet as data_chicago

# puppetcamp # puppetize @ puppetlabs

Setting up the agent:

[agent]

report=true

Page 42: Puppet as data_chicago

# puppetcamp # puppetize @ puppetlabs

Archive reports in your yamldir

[master]

reports = store

Page 43: Puppet as data_chicago

# puppetcamp # puppetize @ puppetlabs

Puppet reports

$ cd `puppet config print reportdir`

$ ls

node1 node2 node3

$ ls node1

Page 44: Puppet as data_chicago

# puppetcamp # puppetize @ puppetlabs

Every report from every run ever

$ ls node1

201206060256.yaml 201206060303.yaml 201206060519.yaml 201206122349.yaml 201206122354.yaml 201206130002.yaml

Page 45: Puppet as data_chicago

# puppetcamp # puppetize @ puppetlabs

Lets crack one open!

Irb > require ‘yaml’

>reports=YAML.load_file('201206130002.yaml')

Page 46: Puppet as data_chicago

# puppetcamp # puppetize @ puppetlabs

Have a look

>(reports.methods - Object.methods).sort

Notice the following methods:

Page 47: Puppet as data_chicago

# puppetcamp # puppetize @ puppetlabs

High level data

> reports.exit_status

0

> reports.status

=> "unchanged"

> reports.host

”node1”

Page 48: Puppet as data_chicago

# puppetcamp # puppetize @ puppetlabs

metrics

> reports.metrics.keys

["resources", "events", "changes", "time"]

> reports.metrics['resources']

[‘failed’, 0],[ ‘changed’, ‘7’]

Page 49: Puppet as data_chicago

# puppetcamp # puppetize @ puppetlabs

And the awesome sauce

> reports.resource_statuses.keys

=> ["Package[xinetd]", "File[/srv/node/1]", "Package[swift]", "Exec[compile fragments]", "Package[swift-container]", "File[/var/opt/lib/pe-puppet/concat/_etc_swift_object-server.conf]", "File[/etc/rsync.d/frag-account]”]

Page 50: Puppet as data_chicago

# puppetcamp # puppetize @ puppetlabs

And the awesome sauce

> status = reports.resource_statuses

> status.keys

=> ["Package[xinetd]", "File[/srv/node/1]", "Package[swift]", "Exec[compile fragments]", "Package[swift-container]", "File[/var/opt/lib/pe-puppet/concat/_etc_swift_object-server.conf]", "File[/etc/rsync.d/frag-account]”]

Page 51: Puppet as data_chicago

# puppetcamp # puppetize @ puppetlabs

And the awesome sauce>events = status["File[/etc/swift/swift.conf]"].events

> events.first.status

"success”

> events.first.desired_value

:present

> events.first.previous_value

=> :absent

Page 52: Puppet as data_chicago

amp

Thank YouDan Bode| Puppet Labs [email protected]