### Enable and Start PuppetDB Service (Installed) Source: https://github.com/puppetlabs/puppetdb/blob/main/documentation/install_from_source.markdown Ensures the PuppetDB service is running and configured to start automatically on system boot. This uses the Puppet resource type to manage the service. ```bash $ sudo puppet resource service puppetdb ensure=running enable=true ``` -------------------------------- ### Start PuppetDB Service (Installed) Source: https://github.com/puppetlabs/puppetdb/blob/main/documentation/install_from_source.markdown Starts the PuppetDB service after it has been installed from source. This command assumes the service has been properly installed and configured. ```bash $ sudo service puppetdb start ``` -------------------------------- ### Install OpenJDK 11 with Homebrew Source: https://github.com/puppetlabs/puppetdb/blob/main/dev-docs/run-pdb-on-macos.md Use Homebrew to install OpenJDK 11. Ensure to follow up with the symbolic link command for proper setup. ```bash brew install openjdk@11 ``` ```bash sudo ln -sfn /usr/local/opt/openjdk@11/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk-11.jdk ``` -------------------------------- ### Install Leiningen with Homebrew Source: https://github.com/puppetlabs/puppetdb/blob/main/dev-docs/run-pdb-on-macos.md Install the Leiningen build automation tool using Homebrew. ```bash brew install leiningen ``` -------------------------------- ### Install pgbox using require-pgbox Source: https://github.com/puppetlabs/puppetdb/blob/main/documentation/CONTRIBUTING.md Use the helper script to download and install pgbox into a specified directory, then move the pgbox executable to your PATH. ```bash $ ext/bin/require-pgbox 0.0.0 /tmp/pgbox-install $ mv /tmp/pgbox-install/bin/pgbox ~/.local/bin ``` -------------------------------- ### Install JDK Source: https://github.com/puppetlabs/puppetdb/blob/main/ci/README.md Installs the Java Development Kit (JDK) onto the machine. ```bash #!/bin/bash # Installs JDK onto machine ``` -------------------------------- ### Example PuppetDB Configuration File Source: https://github.com/puppetlabs/puppetdb/blob/main/documentation/configure.markdown An example of an INI-style configuration file for PuppetDB, demonstrating settings for global, database, PuppetDB, and jetty sections. ```ini [global] vardir = /var/lib/puppetdb logging-config = /var/lib/puppetdb/logback.xml [database] subname = //localhost:5432/puppetdb [puppetdb] certificate-allowlist = /path/to/file/containing/certnames disable-update-checking = false [jetty] port = 8080 ``` -------------------------------- ### Install pgbox Source: https://github.com/puppetlabs/puppetdb/blob/main/ci/README.md Installs pgbox, a tool for managing PostgreSQL instances, onto the machine. ```bash #!/bin/bash # Installs pgbox onto machine ``` -------------------------------- ### Install virtualenv Source: https://github.com/puppetlabs/puppetdb/blob/main/util/pdb/README.md Installs the virtualenv package using apt-get. Ensure you have root privileges. ```bash apt-get install virtualenv ``` -------------------------------- ### Install Project Dependencies Source: https://github.com/puppetlabs/puppetdb/blob/main/dev-docs/run-pdb-on-macos.md Install project dependencies using Leiningen after downloading the pgbox script and adding it to your PATH. ```bash lein install ``` -------------------------------- ### Install Leiningen Source: https://github.com/puppetlabs/puppetdb/blob/main/ci/README.md Installs Leiningen, a build automation tool for Clojure projects, onto the machine. ```bash #!/bin/bash # Installs Leiningen onto machine ``` -------------------------------- ### Start PostgreSQL Sandbox using pgbox Source: https://github.com/puppetlabs/puppetdb/blob/main/documentation/CONTRIBUTING.md Directly interact with the pgbox utility to start the PostgreSQL sandbox, specifying the PGBOX environment variable. ```bash $ PGBOX=~/tmp/pdb-sandbox/pg pgbox pg_ctl start -w ``` -------------------------------- ### Stop, Upgrade, and Start PuppetDB Service Source: https://github.com/puppetlabs/puppetdb/blob/main/documentation/upgrade.markdown Use these commands to stop the PuppetDB service, ensure the latest package is installed, and then restart the service. This is a standard procedure for upgrading the PuppetDB package. ```bash $ sudo puppet resource service puppetdb ensure=stopped $ sudo puppet resource package puppetdb ensure=latest $ sudo puppet resource service puppetdb ensure=running ``` -------------------------------- ### Unpack PuppetDB Tarball for Installation Source: https://github.com/puppetlabs/puppetdb/blob/main/documentation/install_from_source.markdown Unpacks the generated PuppetDB distribution tarball to prepare for installation. Navigate into the unpacked directory to run the installation script. ```bash $ cd pkg $ tar -xzf puppetdb-*.tar.gz $ cd puppetdb-* ``` -------------------------------- ### Install PuppetDB CLI using gem Source: https://github.com/puppetlabs/puppetdb/blob/main/documentation/pdb_client_tools.markdown Install the PuppetDB CLI from Rubygems. Use the --bindir option to specify the installation directory if it's not in Ruby's standard bindir. ```bash gem install --bindir /opt/puppetlabs/bin puppetdb_cli ``` ```bash gem install puppetdb_cli ``` -------------------------------- ### Install PuppetDB from Source (Full) Source: https://github.com/puppetlabs/puppetdb/blob/main/documentation/install_from_source.markdown Performs a full installation of the PuppetDB service and its associated terminus code. This is typically used when running PuppetDB on the same host as the Puppet Server. ```bash $ sudo bash install.sh all ``` -------------------------------- ### Start PuppetDB Service (Running from Source) Source: https://github.com/puppetlabs/puppetdb/blob/main/documentation/install_from_source.markdown Starts the PuppetDB service when running directly from source code. Requires specifying the configuration file path. ```bash $ lein run services -c /path/to/config.ini ``` -------------------------------- ### Install lein-ezbake Locally Source: https://github.com/puppetlabs/puppetdb/blob/main/acceptance/README.md Install the downloaded lein-ezbake JAR and POM files into the local Maven repository. This command should be run before each beaker:acceptance invocation. ```bash mvn org.apache.maven.plugins:maven-install-plugin:2.5.2:install-file \ -DpomFile=lein-ezbake-0.2.2.pom \ -Dfile=lein-ezbake-0.2.2.jar \ -DlocalRepositoryPath=tmp/m2-local ``` -------------------------------- ### PuppetDB CLI configuration file example (Windows) Source: https://github.com/puppetlabs/puppetdb/blob/main/documentation/pdb_client_tools.markdown Example JSON configuration file for the PuppetDB CLI on Windows. Note the escaped backslashes in the CA certificate path, which is necessary for Windows paths. ```json { "puppetdb": { "server_urls": "https://:8081", "cacert": "C:\\ProgramData\\PuppetLabs\\puppet\\etc\\ssl\\certs\\ca.pem" } } ``` -------------------------------- ### Install PuppetDB from Source (Service Only) Source: https://github.com/puppetlabs/puppetdb/blob/main/documentation/install_from_source.markdown Installs only the PuppetDB service component from the source distribution. Use this if you only need the service and not the terminus code. ```bash $ sudo bash install.sh service ``` -------------------------------- ### Install PuppetDB Package Source: https://github.com/puppetlabs/puppetdb/blob/main/documentation/install_from_packages.markdown Use Puppet to ensure the latest version of the puppetdb package is installed. ```bash $ sudo puppet resource package puppetdb ensure=latest ``` -------------------------------- ### Install PuppetDB from Source (Terminus Only) Source: https://github.com/puppetlabs/puppetdb/blob/main/documentation/install_from_source.markdown Installs only the PuppetDB terminus code from the source distribution. Use this if you only need the terminus code and not the service itself. ```bash $ sudo bash install.sh termini ``` -------------------------------- ### Query All Installed Packages Source: https://github.com/puppetlabs/puppetdb/blob/main/documentation/api/query/v4/packages.markdown Use this endpoint to retrieve all installed packages across all nodes. It returns unique (package_name, version, provider) combinations. Supports filtering by package name using a regular expression. ```shell puppet query "packages { package_name ~ 'ssl'}" ``` ```shell curl -G http://localhost:8080/pdb/query/v4/packages --data-urlencode 'query=["~", "package_name", "ssl"]' ``` -------------------------------- ### PuppetDB CLI configuration file example (Unix) Source: https://github.com/puppetlabs/puppetdb/blob/main/documentation/pdb_client_tools.markdown Example JSON configuration file for the PuppetDB CLI on Unix-like systems. This configuration specifies the PuppetDB server URL and the path to the CA certificate, enabling token authentication for PE. ```json { "puppetdb": { "server_urls": "https://:8081", "cacert": "/etc/puppetlabs/puppet/ssl/certs/ca.pem" } } ``` -------------------------------- ### Install Leiningen Source: https://github.com/puppetlabs/puppetdb/blob/main/documentation/install_from_source.markdown Installs Leiningen, a build tool for Clojure, which is a prerequisite for building PuppetDB from source. Ensure Leiningen is symlinked to a directory in your system's PATH. ```bash $ mkdir ~/bin && cd ~/bin $ curl -L 'https://raw.githubusercontent.com/technomancy/leiningen/stable/bin/lein' -o lein --tlsv1 $ chmod ugo+x lein $ ./lein # symlink lein to somewhere in your $PATH $ sudo ln -s /full/path/to/bin/lein /usr/local/bin ``` -------------------------------- ### Example: Triggering delete command with curl Source: https://github.com/puppetlabs/puppetdb/blob/main/documentation/api/admin/v1/cmd.markdown This example shows how to use curl to send a POST request to the /pdb/admin/v1/cmd endpoint to trigger the 'delete' command for a specific certname. ```sh $ curl -X POST http://localhost:8080/pdb/admin/v1/cmd \ -H 'Accept: application/json' \ -H 'Content-Type: application/json' \ -d '{"command": "delete", "version": 1, "payload": {"certname" : "node-1"}}' {"deleted": "node-1"} ``` -------------------------------- ### Example Fact Path: Mount Options Source: https://github.com/puppetlabs/puppetdb/blob/main/documentation/api/query/v4/fact-contents.markdown Illustrates a fact path to access the first mount option for a specific device. ```json ["mountpoints", "/", "options", 0] ``` -------------------------------- ### GET /pdb/query/v4/package-inventory Source: https://github.com/puppetlabs/puppetdb/blob/main/documentation/api/query/v4/packages.markdown Retrieves a list of all installed packages along with the certname of the nodes they are installed on. This provides a comprehensive inventory of packages across your infrastructure. ```APIDOC ## GET /pdb/query/v4/package-inventory ### Description Returns all installed packages along with the certname of the nodes they are installed on. ### Method GET ### Endpoint /pdb/query/v4/package-inventory ### Query Parameters - **query** (string) - Optional - A PuppetDB query string to filter results. ### Response #### Success Response (200) - **certname** (string) - The certname of the node the package data was collected from. - **package_name** (string) - The name of the package. - **version** (string) - The version of the package. - **provider** (string) - The name of the provider (e.g., `apt`). ### Request Example ```bash curl -G http://localhost:8080/pdb/query/v4/package-inventory --data-urlencode 'query=["=", "certname", "agent1"]' ``` ### Response Example ```json [ { "certname": "agent1", "package_name": "openssl", "version": "1.0.1f-1ubuntu2", "provider": "apt" } ] ``` ``` -------------------------------- ### Install pg_trgm Extension Source: https://github.com/puppetlabs/puppetdb/blob/main/documentation/release_notes_older.markdown Install the PostgreSQL pg_trgm extension for improved indexing performance with regular expression queries. This command should be run as a PostgreSQL super-user before starting PuppetDB. ```sql create extension pg_trgm ``` -------------------------------- ### GET /pdb/query/v4/packages Source: https://github.com/puppetlabs/puppetdb/blob/main/documentation/api/query/v4/packages.markdown Retrieves a list of all installed packages across all nodes. Each record represents a unique (package_name, version, provider) combination. ```APIDOC ## GET /pdb/query/v4/packages ### Description Returns all installed packages, across all nodes. One record is returned for each `(package_name, version, provider)` combination that exists in your infrastructure. ### Method GET ### Endpoint /pdb/query/v4/packages ### Query Parameters - **query** (string) - Optional - A PuppetDB query string to filter results. ### Response #### Success Response (200) - **package_name** (string) - The name of the package. - **version** (string) - The version of the package. - **provider** (string) - The name of the provider (e.g., `apt`). ### Request Example ```bash curl -G http://localhost:8080/pdb/query/v4/packages --data-urlencode 'query=["~", "package_name", "ssl"]' ``` ### Response Example ```json [ { "package_name": "emacs24", "version": "24.5+1-6ubuntu1", "provider": "apt" } ] ``` ``` -------------------------------- ### Set up virtualenv Source: https://github.com/puppetlabs/puppetdb/blob/main/util/pdb/README.md Creates and activates a Python 3 virtual environment named 'venv'. Install project dependencies using pip. ```bash virtualenv -p python3 venv source venv/bin/activate pip install -r requirements.txt ``` -------------------------------- ### Get all fact paths of a specific type Source: https://github.com/puppetlabs/puppetdb/blob/main/documentation/api/query/v4/fact-paths.markdown Filter fact paths by their data type. This example retrieves all fact paths that are of the 'integer' type. ```bash curl -X GET http://localhost:8080/pdb/query/v4/fact-paths \ --data-urlencode 'query=["=", "type", "integer"]' ``` ```json [ { "path" : [ "blockdevice_sda_size" ], "type" : "integer" }, { "path" : [ "uptime_days" ], "type" : "integer" }, { "path" : [ "blockdevice_sdb_size" ], "type" : "integer" }, { "path" : [ "uptime_seconds" ], "type" : "integer" }, { "path" : [ "uptime_hours" ], "type" : "integer" } ] ``` -------------------------------- ### Initial Beaker Acceptance Test Run Source: https://github.com/puppetlabs/puppetdb/blob/main/documentation/acceptance_tests.markdown Perform the first run of Beaker acceptance tests to provision a fully configured VM. This command initiates the setup process for a specific test file. ```ruby rake "beaker:first_run[acceptance/tests/some/test.rb]" ``` -------------------------------- ### GET /pdb/query/v4/package-inventory/ Source: https://github.com/puppetlabs/puppetdb/blob/main/documentation/api/query/v4/packages.markdown Retrieves all packages installed on a specific node identified by its certname. This endpoint functions similarly to querying the package-inventory endpoint with a filter for the given certname. ```APIDOC ## GET /pdb/query/v4/package-inventory/ ### Description Returns all packages installed on the provided certname. It behaves exactly like a call to `/pdb/query/v4/packages` with a query string of `["=", "certname", ] ### Method GET ### Endpoint /pdb/query/v4/package-inventory/ ### Parameters #### Path Parameters - **CERTNAME** (string) - Required - The certname of the node to query packages for. ### Response #### Success Response (200) - **package_name** (string) - The name of the package. - **version** (string) - The version of the package. - **provider** (string) - The name of the provider (e.g., `apt`). ### Response Example ```json [ { "package_name": "openssl", "version": "1.0.1f-1ubuntu2", "provider": "apt" } ] ``` ``` -------------------------------- ### Prepare and Run CI Tests Source: https://github.com/puppetlabs/puppetdb/blob/main/ci/README.md Prepares the CI machine for tests and then runs tests using the `ci/bin/run` script. This is a wrapper script for setting up the testing environment. ```bash ci/bin/prep-and-run-in ``` -------------------------------- ### Create Test Database Users Source: https://github.com/puppetlabs/puppetdb/blob/main/documentation/CONTRIBUTING.md When setting up a custom PostgreSQL server for testing, create the necessary database users and grant them appropriate privileges. These commands are typically handled by `pdbbox-init`. ```bash $ createuser -DRSP pdb_test $ createuser -dRsP pdb_test_admin ``` -------------------------------- ### Get Failure Events for a Specific Node Pattern Source: https://context7.com/puppetlabs/puppetdb/llms.txt Filter resource events to find only failures on nodes matching a specific pattern (e.g., starting with 'web'). Useful for identifying problematic nodes. ```bash curl -G http://localhost:8080/pdb/query/v4/events \ --data-urlencode 'query=["and", ["=", "status", "failure"], ["~", "certname", "^web.*"], ["=", "resource_type", "Service"]] ' ``` -------------------------------- ### Count Nodes with Certname Prefix Source: https://github.com/puppetlabs/puppetdb/blob/main/documentation/api/query/v4/pql.markdown Utilize the 'count()' aggregate function in the projection along with a filter to count objects matching a specific pattern. This example counts nodes whose certname starts with 'web'. ```puppet nodes[count()] { certname ~ "web.*" } ``` -------------------------------- ### Get Factsets for Nodes with Uptime Greater Than 24 Hours Source: https://github.com/puppetlabs/puppetdb/blob/main/documentation/api/query/v4/factsets.markdown This example demonstrates a more complex query to find factsets for nodes where the 'uptime_hours' fact is greater than 24. It uses subqueries to extract relevant certnames. ```bash curl -X GET http://localhost:8080/pdb/query/v4/factsets \ -d 'query=["in", "certname", ["extract", "certname", ["select_facts", ["and", ["=", "name", "uptime_hours"], [">", "value", 24]]]]]' ``` -------------------------------- ### Install Locust Dependencies Source: https://github.com/puppetlabs/puppetdb/blob/main/documentation/testing_storage_changes.markdown Install Locust and PyYAML for current user. Ensure the installation path is in your PYTHONPATH and PATH. ```bash pip install --user locust pyyaml ``` -------------------------------- ### Example Fact Path: Device Size Source: https://github.com/puppetlabs/puppetdb/blob/main/documentation/api/query/v4/fact-contents.markdown Demonstrates a fact path to retrieve the size of a device mounted at a specific path. ```json ["mountpoints", "/boot", "size"] ``` -------------------------------- ### Initialize PuppetDB Environment Source: https://github.com/puppetlabs/puppetdb/blob/main/dev-docs/run-pdb-on-macos.md Initialize a pdbbox environment with specified sandbox, PostgreSQL binary path, port, and bind address. ```bash $ ext/bin/pdbbox-init \ --sandbox ./test-sandbox \ --pgbin /usr/local/bin \ --pgport 5432 \ --bind-addr 127.0.0.1 \ ``` -------------------------------- ### Install pg_trgm Extension Source: https://github.com/puppetlabs/puppetdb/blob/main/documentation/configure_postgres.markdown Install the 'pg_trgm' extension in PostgreSQL to improve the performance of queries that use regular expression filters. This may require installing the 'postgresql-contrib' package. ```bash sudo -u postgres sh psql puppetdb -c 'create extension pg_trgm' exit ``` -------------------------------- ### Install puppetdb-termini Package Source: https://github.com/puppetlabs/puppetdb/blob/main/documentation/connect_puppet_apply.markdown Ensures the puppetdb-termini package is installed on Puppet nodes. This is a prerequisite for using PuppetDB as a terminus. ```ruby package {"puppetdb-termini": ensure => installed, } ``` -------------------------------- ### Prepare MacOS for PuppetDB Tests Source: https://github.com/puppetlabs/puppetdb/blob/main/ci/README.md Prepares MacOS systems for running PuppetDB tests by installing necessary dependencies and configurations. ```bash #!/bin/bash # Prepares MacOS machines for running PuppetDB tests ``` -------------------------------- ### Start and Stop PostgreSQL in Sandbox Source: https://github.com/puppetlabs/puppetdb/blob/main/documentation/CONTRIBUTING.md Use these commands to manage the PostgreSQL database server within the PDBBOX sandbox environment. Ensure the PDBBOX environment variable is set. ```bash $ export PDBBOX=~/tmp/pdb-sandbox $ ext/bin/pdbbox-env pg_ctl start -w ``` ```bash $ ext/bin/pdbbox-env pg_ctl stop ``` -------------------------------- ### PQL Query Structure Example Source: https://github.com/puppetlabs/puppetdb/blob/main/documentation/api/query/v4/pql.markdown Example demonstrating PQL query structure including entity, projection, and filter with a regex. ```pql nodes[certname] { certname ~ "^web" } ``` -------------------------------- ### Install puppetdb-termini Package Source: https://github.com/puppetlabs/puppetdb/blob/main/documentation/connect_puppet_server.markdown Install the puppetdb-termini package on platforms that use Puppet packages to enable Puppet Server integration with PuppetDB. ```bash $ sudo puppet resource package puppetdb-termini ensure=latest ``` -------------------------------- ### Example Test Specification Strings Source: https://github.com/puppetlabs/puppetdb/blob/main/ci/README.md Illustrates different formats for test specification strings, which define test flavors and dependency information. ```text core/openjdk8/pg-9.6 ``` ```text int/openjdk11/pup-6.x/srv-6.x/pg-11 ``` ```text core+ext/openjdk11/pg-11/rich ``` ```text rspec/pup-6.x ``` -------------------------------- ### Run Core Tests with Ephemeral Sandboxes Source: https://github.com/puppetlabs/puppetdb/blob/main/ci/README.md Executes core tests using ephemeral Leiningen and pgbox executables, along with ephemeral PuppetDB and PostgreSQL sandboxes. Requires PostgreSQL and JDK to be installed separately. Passes the command to `ext/bin/with-pdbbox`. ```bash #!/bin/bash # Runs a command using ephemeral Leiningen and pgbox executables, as well as ephemeral PuppetDB and PostgreSQL sandboxes. User still needs PostgreSQL and JDK installed. Passes command to `ext/bin/with-pdbbox` which creates the ephemeral sandboxes. ``` -------------------------------- ### Example Factset Response Structure Source: https://github.com/puppetlabs/puppetdb/blob/main/documentation/api/query/v4/factsets.markdown This is an example of the JSON response structure for a factset, detailing node information, timestamps, and expanded facts. ```json [ { "facts" : { "href": "/pdb/query/v4/factsets/desktop.localdomain/facts", "data": [ { "name": "blockdevice_sde_vendor", "value": "Generic" }, { "name": "mtu_wlp5s0", "value": 1500 }, { "name": "processor6", "value": "Intel(R) Core(TM) i7-4790 CPU @ 3.60GHz" }, { "name": "trusted", "value" : { "authenticated" : "remote", "certname" : "desktop.localdomain", "extensions" : { } } }, { "name": "system_uptime", "value": { "days" : 5, "hours" : 120, "seconds" : 433391, "uptime" : "5 days" } }, ... ] }, "producer" : "server.localdomain", "producer_timestamp" : "2015-03-06T00:20:14.833Z", "timestamp" : "2015-03-06T00:20:14.918Z", "environment" : "production", "certname" : "desktop.localdomain", "hash" : "d118d161990f202e911b6fda09f79d24f3a5d4f4" } ] ``` -------------------------------- ### Print JDK Information Source: https://github.com/puppetlabs/puppetdb/blob/main/ci/README.md Prints information about the installed JDK. Can output the full version, major version, or package/spec name. ```bash #!/bin/bash # Prints information about installed JDK # Can output full version (1.8.0_172), major version (8), or package/spec (openjdk8) ``` -------------------------------- ### Run All Normal Tests Source: https://github.com/puppetlabs/puppetdb/blob/main/documentation/CONTRIBUTING.md Execute the core, integration, and external tests using the sandbox harness. Assumes no server is running on port 34335. ```bash $ ext/bin/run-normal-tests ``` -------------------------------- ### Run Basic Acceptance Tests Source: https://github.com/puppetlabs/puppetdb/blob/main/acceptance/README.md Execute the default acceptance tests using the rake beaker:acceptance task after installing dependencies. ```bash bundle install rake beaker:acceptance ``` -------------------------------- ### Query Package Inventory by Node Source: https://github.com/puppetlabs/puppetdb/blob/main/documentation/api/query/v4/packages.markdown Retrieve all installed packages along with the certname of the nodes they are installed on. Supports filtering by certname, package name, and version. ```shell puppet query "package_inventory{ certname = 'agent1' }" ``` ```shell curl -G http://localhost:8080/pdb/query/v4/package-inventory --data-urlencode 'query=["=", "certname", "agent1"]' ``` ```shell puppet query "package_inventory[certname]{ package_name ~ 'openssl' and version ~ '1\.0\.1[\-a-f]' }" ```