Skip to content

Instantly share code, notes, and snippets.

@tnolet
Last active June 27, 2024 22:28

Revisions

  1. tnolet revised this gist Oct 24, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion puppetdb_postgres_hacks.md
    Original file line number Diff line number Diff line change
    @@ -116,7 +116,7 @@ Or, for example, get all the eth1 addresses for all nodes starting with dummy*:

    Update some facts:

    update certname_facts set value = '634.64 MB' where name = 'memorysize' and certname like 'dummy%';
    UPDATE certname_facts SET value = '634.64 MB' WHERE name = 'memorysize' AND certname LIKE 'dummy%';



  2. tnolet revised this gist Oct 24, 2013. 1 changed file with 4 additions and 0 deletions.
    4 changes: 4 additions & 0 deletions puppetdb_postgres_hacks.md
    Original file line number Diff line number Diff line change
    @@ -114,5 +114,9 @@ Or, for example, get all the eth1 addresses for all nodes starting with dummy*:
    10.20.1.0
    10.20.1.0

    Update some facts:

    update certname_facts set value = '634.64 MB' where name = 'memorysize' and certname like 'dummy%';



  3. tnolet revised this gist Oct 24, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion puppetdb_postgres_hacks.md
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    **NB**: The following examples where done on Puppet Enterprise 3.0. Should be similar for OS versions, except for some file locations.
    **NB**: The following examples where done on Puppet Enterprise 3.0 running on Centos 6. Should be similar for open source versions, except for some file locations.

    ### 1. Logging into the PuppetDB PostgresQL database on Linux

  4. tnolet renamed this gist Oct 24, 2013. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  5. tnolet renamed this gist Oct 24, 2013. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  6. tnolet renamed this gist Oct 24, 2013. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  7. tnolet revised this gist Oct 24, 2013. 1 changed file with 21 additions and 0 deletions.
    21 changes: 21 additions & 0 deletions gistfile1.md
    Original file line number Diff line number Diff line change
    @@ -93,5 +93,26 @@ Then use that hash to get the resources:
    or in a one-liner:

    SELECT title FROM catalog_resources INNER JOIN certname_catalogs ON catalog_resources.catalog = certname_catalogs.catalog WHERE certname_catalogs.certname = 'agent';

    ## 3. Same thing, but now with facts

    Get some nice fact data, or manipulate it for testing or modelling:

    SELECT * FROM certname_facts WHERE certname = 'agent';

    Or, for example, get all the eth1 addresses for all nodes starting with dummy*:

    pe-puppetdb=# SELECT value FROM certname_facts WHERE name = 'network_eth1' AND certname LIKE 'dummy%';
    value
    -----------
    10.20.1.0
    10.20.1.0
    10.20.1.0
    10.20.1.0
    10.20.1.0
    10.20.1.0
    10.20.1.0
    10.20.1.0



  8. tnolet revised this gist Oct 24, 2013. 1 changed file with 48 additions and 2 deletions.
    50 changes: 48 additions & 2 deletions gistfile1.md
    Original file line number Diff line number Diff line change
    @@ -38,7 +38,7 @@ a. List all tables:

    b. Get all nodes:

    pe-puppetdb=# select * from certnames;
    pe-puppetdb=# SELECT * FROM certnames;
    name | deactivated
    ------------+-------------
    agent |
    @@ -48,4 +48,50 @@ b. Get all nodes:
    dummy25 |
    ...

    b.
    c. Get some resources for a specific node. First get the catalog hash for a node:

    pe-puppetdb=# SELECT catalog FROM certname_catalogs WHERE certname = 'agent';
    catalog
    ------------------------------------------
    42115d6afda63764e16536153441f55efd83c8f4

    Then use that hash to get the resources:

    pe-puppetdb=# SELECT title FROM catalog_resources WHERE catalog = '42115d6afda63764e16536153441f55efd83c8f4';
    title
    --------------------------------------------------------------------
    peadmin-public.pem
    /etc/puppetlabs/mcollective/ssl/clients
    pe-mcollective-metadata
    Settings
    /opt/puppet/libexec/mcollective/mcollective/agent/puppetd.rb
    default
    /etc/puppetlabs/mcollective/ssl
    /etc/puppetlabs/mcollective/ssl/clients/mcollective-public.pem
    Pe_mcollective::Server::Plugins
    Pe_mcollective::Shared_key_files
    /opt/puppet/libexec/mcollective/mcollective/agent/puppetd.ddl
    Pe_mcollective
    main
    /etc/puppetlabs/mcollective/server.cfg
    Pe_mcollective::Server
    Pe_mcollective::Params
    mcollective-private.pem
    pe-mcollective
    main
    /opt/puppet/libexec/mcollective/mcollective
    /opt/puppet/libexec/mcollective/mcollective/application/puppetd.rb
    mcollective-cacert.pem
    /opt/puppet/sbin/refresh-mcollective-metadata
    main
    mcollective-cert.pem
    Pe_mcollective::Role::Agent
    puppet-dashboard-public.pem
    mcollective-public.pem
    (28 rows)

    or in a one-liner:

    SELECT title FROM catalog_resources INNER JOIN certname_catalogs ON catalog_resources.catalog = certname_catalogs.catalog WHERE certname_catalogs.certname = 'agent';


  9. tnolet revised this gist Oct 24, 2013. No changes.
  10. tnolet revised this gist Oct 24, 2013. 1 changed file with 25 additions and 2 deletions.
    27 changes: 25 additions & 2 deletions gistfile1.md
    Original file line number Diff line number Diff line change
    @@ -15,14 +15,37 @@ The easiest way to snoop around in de actual PuppetDB postgres database is using

    ### 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.
    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
    name | deactivated
    ------------+-------------
    agent |
    dummy174 |
    dummy76 |
    agent2 |
    dummy25 |
    ...

    b.
  11. tnolet revised this gist Oct 24, 2013. 1 changed file with 15 additions and 1 deletion.
    16 changes: 15 additions & 1 deletion gistfile1.md
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    **NB**: The following examples where done on Puppet Enterprise 3.0. Should be similar for OS versions, except for some file locations.

    ### Logging into the PuppetDB PostgresQL database on Linux
    ### 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.

    @@ -12,3 +12,17 @@ The easiest way to snoop around in de actual PuppetDB postgres database is using
    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.

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

  12. tnolet revised this gist Oct 24, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion gistfile1.md
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    **NB**: The following examples where done on Puppet Enterprise 3.0. Should be similar for OS versions, except for some file locations.

    ## Logging into the PuppetDB PostgresQL database on Linux
    ### 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.

  13. tnolet revised this gist Oct 24, 2013. 1 changed file with 9 additions and 9 deletions.
    18 changes: 9 additions & 9 deletions gistfile1.md
    Original file line number Diff line number Diff line change
    @@ -1,14 +1,14 @@
    **NB**: The following examples where done on Puppet Enterprise 3.0. Should be similar for OS versions, except for some file locations.

    # Logging into the PuppetDB PostgresQL database on Linux
    ## 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=#
    [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=#
  14. tnolet created this gist Oct 24, 2013.
    14 changes: 14 additions & 0 deletions gistfile1.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,14 @@
    **NB**: The following examples where done on Puppet Enterprise 3.0. Should be similar for OS versions, except for some file locations.

    # 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=#