Puppet runs can be deconstructed into data at each step:
1) Facter gathers facts about the agent node.
2) The ENC defines the node's configuration.
3) The catalog compiler generates a catalog based on facts and ENC definitions.
4) The agent applies the catalog and generates a report.
All of this data, including facts, catalogs, reports, can be accessed and manipulated programmatically for use cases like pre-compiling catalogs, inspecting state changes, or analyzing failures. Interacting with Puppet's internal data structures provides power and flexibility beyond traditional Puppet runs.
4. Facter, who am I?
Hi! your facts are:
kernel=linux
ipaddress=10.0.0.3
Agent macaddress=…
# puppetconf # puppetize @ puppetlabs
5. facts
Hi Mr. Master,
I need a catalog. Here
Agent are my facts
http://www.dgcomputers.org/testimonials.php
# puppetconf # puppetize @ puppetlabs
6. facts
Thanks for you facts.
Agent store them in
I’ll just
PuppetDB
PuppetDB
# puppetconf # puppetize @ puppetlabs
7. Mr. ENC, is this host
defined as an external Yep, he should be an
node? apache server. Here is
the definition
nodes
ENC
ENC
Agent PuppetDB
PuppetDB
facts
# puppetconf # puppetize @ puppetlabs
8. catalog
Just compiled your
Agent One sec while
catalog. PuppetDB
PuppetDB
I store it in PuppetDB.
facts
# puppetconf # puppetize @ puppetlabs
9. Here is your
catalog. Send me
a report and let
me know how it
went!
catalog
Agent PuppetDB
PuppetDB
catalog
facts
# puppetconf # puppetize @ puppetlabs
10. I hate to be a
bother, but can
you compute
the md5sums of
this file?
catalog
Agent PuppetDB
PuppetDB
catalog
facts
# puppetconf # puppetize @ puppetlabs
11. Oh, I need that
one! Can I get
the file.
catalog
Agent PuppetDB
PuppetDB
catalog
facts
# puppetconf # puppetize @ puppetlabs
12. Thanks, now
let’s just do that
1000 more
times.
catalog
Agent PuppetDB
PuppetDB
catalog
facts
# puppetconf # puppetize @ puppetlabs
13. You know
‘content’ will
embed the
contents in the
catalog?
catalog
Agent PuppetDB
PuppetDB
catalog
facts
# puppetconf # puppetize @ puppetlabs
14. report
Just finished applying.
Agent are the results.
Here PuppetDB
PuppetDB
catalog
facts
# puppetconf # puppetize @ puppetlabs
27. Creating a catalog:
# puppet apply –catalog /tmp/catalog.yaml
(its easy assuming you are not using file sources)
# puppetcamp # puppetize @ puppetlabs
34. 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]’)
# puppetcamp # puppetize @ puppetlabs
35. 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’) }
# puppetcamp # puppetize @ puppetlabs
37. 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
# puppetcamp # puppetize @ puppetlabs
40. Hacking reports
Everything in Puppet is a state transition
User[‘dan’] : absent -> present
User[‘dan’][‘shell’] -> ‘/sbin/nologin’ -> /bin/bash
# puppetcamp # puppetize @ puppetlabs
41. Setting up the agent:
[agent]
report=true
# puppetcamp # puppetize @ puppetlabs
42. Archive reports in your
yamldir
[master]
reports = store
# puppetcamp # puppetize @ puppetlabs
43. Puppet reports
$ cd `puppet config print reportdir`
$ ls
node1 node2 node3
$ ls node1
# puppetcamp # puppetize @ puppetlabs
44. Every report from every run
ever
$ ls node1
201206060256.yaml 201206060303.yaml
201206060519.yaml 201206122349.yaml
201206122354.yaml 201206130002.yaml
# puppetcamp # puppetize @ puppetlabs