REST API catalog.version

35 views
Skip to first unread message

mvo...@gmail.com

unread,
Jul 29, 2025, 6:27:01 AMJul 29
to Puppet Users
Hello,

I have the following REST skript:

#!/bin/sh

HOST=$HOSTNAME
STRING='{"name":"HOST","values":{"architecture":"x86_64"}}'
STRING=${STRING/HOST/$HOST}
echo "STRING: $STRING"
URL_ENCODE=$(echo -n $STRING |  jq -sRr @uri)

curl --cert /etc/puppetlabs/puppet/ssl/certs/${HOST}.pem \
 --key /etc/puppetlabs/puppet/ssl/private_keys/${HOST}.pem \
 --cacert /etc/puppetlabs/puppet/ssl/certs/ca.pem \
 -X GET "https://puppet:8140/puppet/v3/catalog/$HOST?environment=production&facts_format=application/json&facts=${URL_ENCODE}&transaction_uuid=1234567890  "


I'm interested in getting the catalog version, as printed by:

puppet/lib/ruby/vendor_ruby/puppet/transaction.rb

Puppet.info _("Applying configuration version '%{version}'") % { version: catalog.version } if catalog.version


The reason is, I like to compare the catalog version from the server with
the catalog version off the last run:

$ cat /opt/puppetlabs/puppet/public/last_run_summary.yaml | grep config
config: heads/devel-0-g1940ad41

This would allow me to speed things up in a hot path.

How can this be done?


best regards,

Martin

mvo...@gmail.com

unread,
Jul 29, 2025, 9:21:54 AMJul 29
to Puppet Users
Case closed:

- The script works,  which I just found out, but not on my testing machine.

The catalog.version then can be queried with

cat result.txt | jq .version

Jason St-Cyr

unread,
Aug 2, 2025, 3:13:31 PMAug 2
to Puppet Users
Hi Martin, just as a caveat, I'm not a Puppet expert, but I decided to try out the new support search that Perforce put on the help docs (help.puppet.com/core) with this question and it's possible the answer it gave might help out! I've put in its answer below, in case it helps, but it also cited this doc as a source:  https://help.puppet.com/core/current/Content/PuppetCore/server/http_api/http_catalog.htm 

Those docs seem to have some Catalog API examples that might help? 

Here's the response the search tool gave, in case it helps:

----------------

You can retrieve the catalog version from the Puppet Server using the /puppet/v3/catalog API. The catalog version is included in the response under the version key when a catalog is successfully retrieved.

Here are the key details:

  1. Request Parameters: The API supports GET and POST methods. The relevant URL for your request would typically include the node name for which you want the catalog:

    GET /puppet/v3/catalog/:nodename?environment=:environment

    In your case, you are making a GET request with parameters such as facts_format and transaction_uuid. Ensure that the facts parameter contains serialized fact data as JSON, and it might need to be double-escaped due to containing characters like &.

  2. Response: If the catalog is found, the response includes the catalog details in JSON. The version field in the response represents the catalog version:

    { "name": "elmo.mydomain.com", "version": 1377473054, "code_id": null, "catalog_uuid": "827a74c8-cf98-44da-9ff7-18c5e4bee41e", "catalog_format": 1, ... }
  3. Comparison: After fetching the version from the API response, you can compare it to the config field in the last_run_summary.yaml. The config value generally refers to the branch or commit from which the catalog was compiled.

Make sure your curl request correctly constructs the API call and encodes the required data parameters to ensure a proper response

----------------
Reply all
Reply to author
Forward
0 new messages