Node 
Collaboration with 
PuppetDB 
Michael Richardson @m_richo
Agenda 
1. Who am i 
2. The challenges we face 
3. What is PuppetDB 
4. How can PuppetDB help 
5. Examples
$ whoami 
• Michael Richardson @m_richo 
• engineer at Odecee 
• Solaris/Linux Sys Admin 
• currently battling Windows 
• coffee consumer 
• devops enthusiast 
• puppet certified
The Challenge
The Challenge 
Faster 
provisioning
The Challenge 
Faster 
provisioning
The Challenge 
Faster 
provisioning 
more environments
The Challenge 
Faster 
provisioning 
more environments
The Challenge 
Faster 
provisioning 
more environments
micro-services 
The Challenge 
Faster 
provisioning 
more environments
micro-services 
The Challenge 
Faster 
provisioning 
more environments
Tools like Puppet have 
become essential
The need for 
automated, repeatable, versioned 
provisioning and configuration 
management of infrastructure and 
services
Let’s raise the bar 
We need 
automated, repeatable, versioned 
learning, reactive and adaptive 
provisioning and configuration 
management of infrastructure and 
services
This is where 
PuppetDB 
and tools can help
So what is PuppetDB?
So what is PuppetDB? 
1. PuppetLabs product. 
2. Storage service for Puppet produced 
data. 
3. Written in Clojure. 
4. Persists data to a Postgres DB 
5. Supports Puppet Enterprise and Puppet 
Open Source environments.
PuppetDB 
PuppetDB 
Puppet 
Master 
agent agent agent agent 
Postgres
PuppetDB 
PuppetDB 
Puppet 
Master 
agent agent agent agent 
Postgres
PuppetDB 
PuppetDB 
Puppet 
Master 
agent agent agent agent 
Postgres 
PuppetDB 
Puppet 
Master 
Load 
balancer
What data goes in PuppetDB
Node Facts
ipaddress network 
macaddress 
sshrsakey kernel osfamily 
Node Facts 
operatingsystemrelease 
FQDN
Node Catalog’s
Node Catalog’s
Facts about every node 
Catalog for every node 
CMDB?? 
So much useful data
How do we access it?
PuppetDB has an API
PuppetDB API 
PuppetDB REST API has the following endpoints: 
• Nodes 
• Catalogs 
• Facts 
• Fact-names 
• Resources 
• Environments 
• Metrics 
• Reports 
• Events 
• And more
Query PuppetDB 
Query all the nodes
Query PuppetDB 
Query nodes and filter results
Query PuppetDB 
Query all facts for a given node
Query PuppetDB 
Query an individual fact for a given node
Sick of running curl?
Check out Puppet Explorer 
thank you Erik Dalén and
Check out Puppetboard 
thank you Daniele Sluijters
Dashboards are lovely. 
But how can we use 
this data to allow 
node collaboration
Introducing 
PuppetDBquery module 
https://forge.puppetlabs.com/dalen/puppetdbquery 
Again, thank you Erik Dalén
PuppetDB query 
Provides 
1. CLI commands 
2. PuppetDB Hiera backend 
3. PuppetDB functions
PuppetDB query 
Provides 
1. CLI commands 
2. PuppetDB Hiera backend 
3. PuppetDB functions
PuppetDB query 
Provides 
1. CLI commands 
2. PuppetDB Hiera backend 
3. PuppetDB functions 
o query_nodes 
o query_facts
Puppet run 
Puppet 
Master 
agent 
facts 
Hiera data 
Puppet code 
catalog 
report
Puppet run with 
puppetdbquery 
Hiera data 
PuppetDB 
Puppet 
Master 
agent 
facts 
Puppet code 
catalog 
report
query_nodes 
Accepts 2 arguments 1. Query to filter nodes 
2. Fact to return (optional)
query_nodes 
Accepts 2 arguments 1. Query to filter nodes 
2. Fact to return (optional) 
Returns an array of results 
webservers = [‘node2.local’, ‘node3.local’] 
foo_db_ip = [‘10.10.40.12’]
query_facts 
Accepts 2 arguments 
1. Query to filter nodes 
2. List of facts to return
query_facts 
Accepts 2 arguments 
1. Query to filter nodes 
2. List of facts to return 
Returns nested hash of results 
webserver_network = {"node2.local"=>{"macaddress” 
=>"08:00:27:99:4B:CB", "ipaddress"=>"10.0.2.15"}, 
"node3.local"=>{"macaddress"=>"08:00:27:99:4B:CB", 
"ipaddress"=>"10.0.2.15"}}
What’s this give us?
What’s this give us? 
The ability to dynamically 
configure a system based on 
the state of other systems in 
the infrastructure.
Examples
populate files with query results
populate files with query results
populate files with query results
Examples – load balancer
Examples – whitelist addresses
Examples – search for service
Summary 
• PuppetDB has a wealth of information 
about your systems. Start using it! 
• Populate dynamic configuration based on 
PuppetDB data. 
• Allow hosts and services to simply be 
discovered by their peers.
Thank you. 
#protip 
Go buy this book now 
By Alessandro Franceschi 
It is EXCELLENT!
Thank you. 
For folks from Sydney 
Sydney Puppet User Group 
http://www.meetup.com/Sydney-Puppet-User-Group/ 
Come along 
Thank you 
Any Questions? 
Michael Richardson @m_richo

Puppet Camp Melbourne 2014: Node Collaboration with PuppetDB

Editor's Notes

  • #12 Let’s not forget about people
  • #13 You need automated, repeatable, versionable provisioning and management of infrastructure and services.
  • #14 You need automated, repeatable, versionable provisioning and management of infrastructure and services.
  • #15 Discuss adding and removing services, Multiple environments React to auto-scaling
  • #23 Puppet agent includes facter Base install produces > 100 facts Custom facts
  • #24 Base install produces > 100 facts Custom facts