Skip to content

Instantly share code, notes, and snippets.

@tnolet
Last active June 27, 2024 22:28
Show Gist options
  • Save tnolet/7133083 to your computer and use it in GitHub Desktop.
Save tnolet/7133083 to your computer and use it in GitHub Desktop.
PuppetDB is awesome. Here's some tips on accessing the data in the Postgresql database...most of 'm just reminders for myself.

NB: The following examples where done on Puppet Enterprise 3.0. Should be similar for OS versions, except for some file locations.

1. Logging into the PuppetDB PostgresQL database on Linux

The easiest way to snoop around in de actual PuppetDB postgres database is using the command prompt. You have to be the peadmin user though. Couldn't get it working just under root.

[root@master bin]# sudo su - pe-postgres -s /bin/bash
-bash-4.1$ /opt/puppet/bin/psql
psql (9.2.4)
Type "help" for help.

pe-postgres=# \c pe-puppetdb
You are now connected to database "pe-puppetdb" as user "pe-postgres".
pe-puppetdb=#

2. Snooping around the data

Using the REST interface is the way to go, but for some testing purposes I needed to check and/or manipulate some data. Just use the psql console for this:

a. List all tables:

pe-puppetdb=# \d
                   List of relations
 Schema |          Name           | Type  |    Owner
--------+-------------------------+-------+-------------
 public | catalog_resources       | table | pe-puppetdb
 public | catalogs                | table | pe-puppetdb
 public | certname_catalogs       | table | pe-puppetdb
 public | certname_facts          | table | pe-puppetdb
 public | certname_facts_metadata | table | pe-puppetdb
 public | certnames               | table | pe-puppetdb
 public | edges                   | table | pe-puppetdb
 public | reports                 | table | pe-puppetdb
 public | resource_events         | table | pe-puppetdb
 public | resource_params         | table | pe-puppetdb
 public | schema_migrations       | table | pe-puppetdb

b. Get all nodes:

pe-puppetdb=# select * from certnames;
    name    | deactivated
------------+-------------
 agent      |
 dummy174   |
 dummy76    |
 agent2     |
 dummy25    |
...

b.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment