Do you think IIT Guwahati certified course can help you in your career?
No
Introduction
Puppet orchestrator is an efficient tool for making quick modifications to your infrastructure. With orchestrator you can start Puppet, run tasks, or plan anytime you need. It removes the need for manual labor throughout your work.
This blog explains the details of the Basics of Orchestration API V1 in Puppet and the details of Orchestrator API authentication, Root endpoints, Command endpoints, and Inventory endpoints.
Without further ado, let's get started.
Orchestrator API v1
The orchestrator API allows you to run tasks and plans on demand, schedule them, find out information about events and jobs, track node utilisation, and more.
The following are some uses of Orchestrator API v1 :
Forming orchestrator API requests The orchestrator API requires authentication and accepts properly formatted HTTPS requests.
Root endpoints To obtain metadata from the orchestrator API, use the orchestrator endpoint.
Command endpoints Use the command endpoints to run Puppet, jobs, and plans on demand or to halt running jobs. You can also make task targets, which grant users with restricted privileges the ability to conduct specific tasks on specific nodes or node groups.
Inventory endpoints Use the inventory endpoints to determine whether the orchestrator can connect to a node.
Jobs endpoints Examine jobs and their details using the jobs endpoints.
Scheduled jobs endpoints Examine plan jobs and associated details using the plan jobs endpoints.
Task endpoints To learn more about tasks you've installed and tasks Puppet Enterprise includes, use the tasks endpoints (PE).
Usage endpoints Use the usage endpoint to access information about the active nodes in your deployment.
Scopes endpoints To obtain details about task targets, use the scopes endpoints.
Orchestrator API error responses Error answers from the Orchestrator API are presented as JSON objects.
Let's look into the details of Forming orchestrator API requests.
Forming orchestrator API requests
The orchestrator API requires authentication and accepts properly formatted HTTPS requests.
The URI path for Orchestrator API queries must fit the following pattern:
https://<DNS>:8143/orchestrator/v1/<ENDPOINT>
The components of the variable route come from:
DNS: The DNS name of your PE console host. You can use a puppet command, localhost, or manually type the DNS name (as explained in Using example commands).
ENDPOINT: A section or sections that specify the endpoint, such as a command or a jobs section. Certain endpoints demand extra portions, such as POST /command/deploy.
Orchestrator API authentication
Requests to the orchestrator API must be authenticated using user authentication tokens. Visit Token-based authentication for information on how to create, configure, revoke, and delete authentication tokens in PE.
You can use the puppet-access show to include a token in an orchestrator API call, for example:
The GET /orchestrator endpoint supports no parameters, but you still need to give authentication as with other orchestrator API endpoints.
Response format
The response is a JSON object with the following keys:
info: It contains the title, description, licence details, and version compatibility warnings for the API.
status: A URI route that you can use to check the status of the orchestrator API. Use the Status API to look up the status of the orchestrator services.
collections: A number of endpoints, including the environments and jobs endpoints, can be accessed via collections of URI paths. You can learn which environments are available or whether a named environment is present from the environment endpoint response.
commands: The Command endpoints' commands URI paths.
Let's look into the details of command endpoints.
Command endpoints
You can use the command endpoints to start and stop running jobs, plans, and Puppet on demand. Additionally, you can make task-targets, granting permission escalation to users who would otherwise be unable to execute specific activities or tasks on specific nodes or node groups.
POST /command/deploy
You can execute Puppet on demand – and make the orchestrator available to all of the environment's nodes.
Request format
The content type of requests made to this endpoint using the Forming orchestrator API is application/json. The following table contains the keys that must be used in the body of the JSON object. There is always a need for the environment key. The values of other keys may determine whether additional keys are needed.
The server returns 202 and a JSON object with the following keys if all node runs are successful and the environment is successfully deployed:
id: A permanent web address that points to the recently created job.
name: The newly created job is identified by a string field number. You can use this with other endpoints like POST /command/stop and GET /jobs/job-id> to receive information about a job's status.
It is used to stop the orchestrator job that is running right now.
Request format
The content type of requests made to this endpoint using the Forming orchestrator API is application/json. The body must contain a JSON object with a job key specifying the job ID of the task to be stopped, such as:
{
"job": "1909"
}
You can also try this code with Online Ruby Compiler
On a group of nodes, run a task. Nodes in the defined scope that you do not have authority to run tasks on are excluded from the task's execution.
Request format
The content type of requests made to this endpoint using the Forming orchestrator API is application/json. The following table contains the keys that must be used in the body of the JSON object. The majority of keys must be used; however, certain keys may be empty or optional.
The server responds with 202 and a JSON object with the following keys if the task launches successfully:
id: A permanent URL pointing to the recently established job. To get details about the job's status, use it in conjunction with the GET /jobs/job-id> endpoint.
name: The newly established job's stringified identification number.
It is used to create a task-target, which is a collection of tasks, nodes, and node groups you may use to grant users with a specified level of privilege escalation when they otherwise wouldn't be able to perform a given task or perform a task on a given node or node group. The user can execute the task(s) in the task-target on the set of nodes specified in the task-target when you give them permission to utilise it.
Request format
The content type of requests made to this endpoint using the Forming orchestrator API is application/json. A JSON object utilising these keys must make up the body.
Upon successfully creating the task-target, the server issues a 200 response and returns a JSON object with the following keys:
id: A permanent web address that points to the task-target. You can use it to acquire details about the task-target using the GET /scopes/task targets/task-target-id> endpoint.
name: The special identification for the task-target.
The content type of requests made to this endpoint using the Forming orchestrator API is application/json. A JSON object utilising these keys must make up the body.
Example:
{
"plan_name" : "ninjas",
"description" : "Start the coding on node1 and node2",
"params" : {
"nodes" : ["node1.example.com", "node2.example.com"],
"command" : "whoami",
"canary" : 1
}
}
You can also try this code with Online Ruby Compiler
The inventory endpoints are used to determine whether the orchestrator can connect to a node. These endpoints are based on nodes that are linked to the PCP broker, a component of the Puppet orchestrator architecture.
GET /inventory
It is used to get a list of every node linked to the Puppet Communications Protocol (PCP) broker.
Request format
This endpoint receives simple calls from the Forming orchestrator API, like:
GET https://orchestrator.example.com:1909/orchestrator/v1/inventory
You can also try this code with Online Ruby Compiler
There are no parameters supported by the GET /inventory endpoint. However, you still need to give authentication like with other orchestrator API endpoints.
Response format
A JSON object with an array of nodes is the sign of an appropriate response. The following keys are used in response to give details about each node's PCP broker connection.
It returns details regarding connections made by various nodes to the Puppet Communications Protocol (PCP) broker.
Request format
The content type of requests made to this endpoint using the Forming orchestrator API is application/json. The body must contain a JSON object with an array of node names.
Example:
{
"nodes" : [
"node1.example.com",
]
}
You can also try this code with Online Ruby Compiler
You can use the orchestrator endpoint to obtain metadata from the orchestrator API.
What is the use of inventory endpoints?
The inventory endpoints are used to determine whether the orchestrator can connect to a node.
What is the use of a command endpoint?
The command endpoints are used to start and stop running jobs, plans, and Puppet on demand.
Conclusion
In this article, we have extensively discussed the details of the Basics of Orchestration API V1 in Puppet, along with the details of Orchestrator API authentication, Root endpoints, Command endpoints, and Inventory endpoints.