Table of contents
1.
Introduction 
2.
Catalog
2.1.
How can we retrieve a catalog?
2.2.
Parameters
3.
Node
3.1.
How to retrieve data for a node?
3.2.
Parameters
3.3.
Examples
4.
Facts
4.1.
Save
4.2.
Parameters
4.3.
Example
5.
Report
5.1.
Save
5.2.
Parameters
5.3.
Content
6.
File Content
6.1.
Find
6.2.
Parameters
6.3.
Notes > Responses
7.
File Bucket File
7.1.
Find
7.2.
Head
7.3.
Save
7.4.
Parameters
7.5.
Examples
8.
Frequently Asked Questions
8.1.
What is Puppet?
8.2.
What are the advantages of using Puppet Forge?
8.3.
How does Puppet enlist its features?
8.4.
Is Puppet still used?
9.
Conclusion
Last Updated: Mar 27, 2024

Overview of Puppet v3 API

Author Manshi
0 upvote
Career growth poll
Do you think IIT Guwahati certified course can help you in your career?

Introduction 

The Puppet agent application uses the HTTP API provided by Puppet Server to resolve a node's credentials, retrieve a configuration catalog, retrieve file data, and submit reports.

To manage systems, the Puppet agent application makes use of a number of network services. All of these services are grouped together under the /puppet API. Other tools can use the data from the Puppet primary server to access these services.

introductory img

Let’s see an Overview of Puppet v3 API.

Catalog

If given the supplied facts, the catalog endpoint provides a catalog for the specified node name.

How can we retrieve a catalog?

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

 

Functionally, the POST and GET methods are interchangeable. Both offer the three parameters listed below: POST in the request body, GET in the query string.

Puppet originally used GET; POST was added because some web servers have a limit of 1024 bytes for URI length (which is easily exceeded with the facts parameter).

Parameters

Four parameters must be supplied to the POST or GET:

  • environment: the name of the environment.
  • facts_format: application/json or pson is required.
  • facts: the facts hash's serialized JSON or PSON. Facts are doubly-escaped because they can contain &, which is also the HTTP query parameter delimiter.
  • transaction_uuid: a unique identifier for the entire transaction (shows up in the report as well).

Static catalogs require two optional parameters:

  • static_catalog: a boolean that should always be true if a static catalog is available.
  • checksum_type: a comma-separated list of checksum types supported by the agent, for use in static catalog file resources. The order represents preference, with the highest preference coming first.

Parameters that can be passed to the POST or GET:

  • configured_environment: the client's configured environment. Can be used to notify an ENC that a client has requested a specific environment that differs from what the client believes is its current environment.
  • job_id: the orchestration job that initiated this catalog request.

Node

The puppet agent uses the node endpoint to obtain basic information about a node. The node name and environment are returned, as well as any classes set by an External Node Classifier and a hash of parameters that may include the node's facts. 

If Puppet is configured with an ENC, the returned node may have a different environment than the one specified in the request.

How to retrieve data for a node?

GET /puppet/v3/node/:certname?environment=:environment&transaction_uuid=:transaction_uuid&configured_environment=:environment

Parameters

The GET should be given one parameter:

  • transaction_uuid: a unique identifier for the entire transaction (shows up in the report as well)

An optional parameter can be passed to the GET to notify a node classifier that the client requested a specific environment that may differ from the client's current environment:

  • configured_environment: the client's configured environment.

Examples

> GET /puppet/v3/node/mycertname?environment=production&transaction_uuid=aff261a2-1a34-4647-8c20-ff662ec11c4c&configured_environment=production HTTP/1.1
> Accept: application/json, text/pson


< HTTP/1.1 200 OK
< Content-Type: application/json
< Content-Length: 5830


{
  "name":"Intense.corp.puppetlabs.net",
  "parameters":{
    "architecture":"amd64",
    "kernel":"Unix",
    "blockdevices":"sda,sr0",
    "clientversion":"8.3.1",
    "clientnoop":"true",
    "environment":"production",
    ...
  },
  "environment":"production"
}

Facts

The facts endpoint allows you to set the facts for the node name you specify.

Save

Stores information for a node. The request body should contain facts in JSON format.

PUT /puppet/v3/facts/:nodename?environment=:environment

Parameters

The facts endpoints in puppet have no parameters. 

Example

PUT /puppet/v3/facts/elmo.mydomain.com?environment=:environment
    
    Content-Type: application/json


    {
      "name": "elmo.mydomain.com",
      "values": {
        "architecture": "amd64",
        "kernel": "linux",
        "domain": "local",
        "macaddress": "91:15:36:8c:33:v9",
        "osfamily": "linux",
        "operatingsystem": "linux",
        "facterversion": "3.8.2",
        "fqdn": "plum.mydomain.com",
      },
      "timestamp": "2022-10-20 15:10:11 -0800",
      "expiration": "2022-10-20 15:10:11 -0800"
    }


    HTTP/1.1 200 OK
    
    Content-Type: application/json

Report

In technical terms, this section describes the Puppet master's report endpoint and the Report Format 6 schema. See also the documentation.

Clients can send reports to the master via http or https using the report endpoint. When a report is received by the master, it is processed by the report processors that have been configured to be triggered when a report is received. One such report processor, for example, handles the storage of reports in PuppetDB.

Save

The http(s) endpoint for reporting to the master is as follows:

PUT /puppet/v3/report/:nodename?environment=:environment

Parameters

The report endpoints in puppet have no parameters.

Content

The Puppet Runtime typically generates report content, which consists of a JSON serialization of Puppet::Transaction::Report object contains a structure of objects with the following runtime types:

Puppet::Util::Log

Puppet::Util::Metric

Puppet::Resource::Status

Puppet::Transaction::Event

This JSON serialization adheres to the report JSON schema of the endpoint.

File Content

The endpoint file_content returns the contents of the specified file.

Find

Getting a file

GET /puppet/v3/file_content/:mount_point/:name

 

The path to the endpoint includes a:mount point, which can be of the following types:

Custom file serving mounts specified in fileserver.conf.

modules/<MODULE> —- a semi-magical mount point that allows access to the files subdirectory of <MODULE>.

plugins —- a highly magical mount point that combines the lib directories of all modules. Used to sync plugins; not intended for general use. Sub-paths can't be specified per module.

pluginfacts —- a highly magical mount point that combines the facts.d directories of all modules. Used for synchronizing external facts; not for general consumption. Sub-paths can't be specified per module.

tasks/MODULE> —- a semi-magical mount point that allows access to files in the <MODULE> tasks subdirectory.

Parameters

The file_content endpoints in puppet have no parameters.

Notes > Responses

File found

GET /puppet/v3/file_content/modules/example/my_file?environment=env
Accept: application/octet-stream

HTTP/1.1 200 OK
Content-Type: application/octet-stream
Content-Length: 30

this is my file

 

File not found

GET /puppet/v3/file_content/modules/example/not_found?environment=env
Accept: application/octet-stream

HTTP/1.1 404 Not Found
Content-Type: text/plain

Not Found: Could not find file_content modules/example/not_found

File Bucket File

The file_bucket_file endpoint manages the file bucket's contents. All file access is controlled by the md5 checksum of the file contents, which is represented as :md5. When :filename is used, it refers to the full absolute path of the file on the client system. 

This is typically used as an error check to ensure that the correct file is retrieved. Because the file bucket does not distinguish between environments, the environment is required in all requests but ignored.

Find

How to retrieve the contents of a file?

GET /puppet/v3/file_bucket_file/:md5?environment=:environment
GET /puppet/v3/file_bucket_file/:md5/:original_path?environment=:environment

 

If the file is present, this will return its contents. If :original_path is specified, the contents will be sent only if the file was previously uploaded with the same path.

Head

Check to see if a file exists in the filebucket.

HEAD /puppet/v3/file_bucket_file/:md5?environment=:environment
HEAD /puppet/v3/file_bucket_file/:md5/:original_path?environment=:environment

Save

Saving a file to the filebucket.

PUT /puppet/v3/file_bucket_file/:md5?environment=:environment
PUT /puppet/v3/file_bucket_file/:md5/:original_path?environment=:environment

 

The file's contents should be included in the body. The file is saved using the md5 sum of its contents. If :original_path is specified, the path is added to a list for the given file. If the md5 sum in the request is incorrect, the file will be saved with the correct checksum instead.

Parameters

The file_bucket_file endpoints in puppet have no parameters.

Examples

Retrieving a file

> GET /puppet/v3/file_bucket_file/md5/4949e56d376cc80ce5387e8e89a75396//home/user/myfile.txt?environment=production HTTP/1.1
> Accept: application/octet-stream

< HTTP/1.1 200 OK
< Content-Length: 32

< This is the file content

 

Saving a file

> PUT /puppet/v3/file_bucket_file/md5/eb61eead90e3b899c6bcbe27ac581660//home/user/myfile.txt?environment=production HTTP/1.1

> Content-Type: application/octet-stream
> Content-Length: 32

> This is the file content

< HTTP/1.1 200 OK

Frequently Asked Questions

What is Puppet?

Puppet allows you to specify which software and configuration a system requires and then maintain that state after initial setup.

What are the advantages of using Puppet Forge?

You can use Puppet to access the Puppet Forge library of over 6,000 modules. Unlike Ansible, Puppet Forge employs a system that makes it easy to see which modules have been proven to work and which have not.

How does Puppet enlist its features?

Puppet is an open-source system management tool for DevOps. It's used to centralize and automate configuration management.

Is Puppet still used?

Puppet is used to manage data servers at Oracle, Google, and other well-known companies.

Conclusion

In this article, we took an overview of Puppet v3 API and covered different aspects and parameters with detailed examples.

Want To Learn More About brand-new technologies? We Have A Whole Category, visit Coding Ninjas or explore yourself in the following links:

Data Structures and Algorithms, Competitive Programming, Learn Java, Web technologies, Mobile technologies, Interview Questions, Interview Puzzles, Node.Js Web applications, Communications Skills, and Aptitude.

Live masterclass