Abstract
| Goal |
Automate Red Hat Satellite functionality at scale with Satellite API integration and Satellite Ansible Collection playbooks. |
| Objectives |
|
| Sections |
|
| Lab |
|
Query the Red Hat Satellite REST API to observe Satellite functionality, syntax, and authentication methods.
Red Hat Satellite includes a Representational State Transfer (REST) API. You can use the REST API to control a Satellite environment without using the Satellite web UI. The Satellite REST API helps to combine Satellite functionality with any third-party application in your environment that can communicate over HTTP.
The Satellite REST API supports the following use cases:
Integration of Satellite functionality with production IT systems or third-party applications.
Automation of maintenance tasks to ensure an operational Satellite environment.
Automation of recurring tasks by using scripts.
Use the following curl command syntax to make a Satellite REST API request:
[user@host]$curl --requestHTTP_VERB\![]()
--insecure \![]()
--usersat_username:sat_password\![]()
--data @file.json\![]()
--header "Content-Type:application/json" \![]()
API_ROUTE\![]()
| python -m json.tool
The HTTP_VERB argument is the intended API call to make with the
| |
Use the | |
Use the | |
Satellite API accepts data in JSON format only.
Use the | |
Use the | |
The API route of the request.
For example, the | |
For better readability, feed the output from the |
Use the GET HTTP verb with the API request to retrieve information about a resource from the Satellite API.
[user@host]$curl --request GET \--insecure \--usersat_username:sat_password\API_ROUTE\| python -m json.tool
For example, the following curl command retrieves the list of organizations in your Satellite Server, and details about them.
[user@host]$curl --request GET \--insecure \--user admin:redhat \https://satellite.lab.example.com/katello/api/organizations \| python -m json.tool% Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 710 0 710 0 0 232 0 --:--:-- 0:00:03 --:--:-- 232 { "total": 3, "subtotal": 3, "page": 1, "per_page": 20, "search": null, "sort": { "by": null, "order": null }, "results": [ { "label": "Default_Organization", "created_at": "2021-12-03 13:18:50 UTC", "updated_at": "2021-12-03 13:30:32 UTC", "id": 1, "name": "Default Organization", "title": "Default Organization", "description": null }, ...output omitted...
Use the POST HTTP verb with an API request to create a resource in the Satellite Server.
Ensure that you submit the data to the API in JSON format while running a POST HTTP request to the Satellite Server.
To submit the JSON data from a file, create the file with its content in JSON format.
The JSON file contains attribute values for the resource that you are creating.
{"parameter1":"value1", "parameter2":"value2", "parameter3":"value3"}After creating the JSON file, run the curl command, and pass the JSON data to the Satellite API to create the resource.
[user@host]$curl --request POST \--insecure \--usersat_username:sat_password\--header "Content-Type:application/json" \--data @file.json\API_ROUTE\| python -m json.tool
Use the PUT HTTP verb with the API request to modify a resource in the Satellite Server.
Ensure that you are submitting the data to the API in JSON format while running a PUT HTTP request to the Satellite Server.
To submit the JSON data from a file, create the file with its content in JSON format.
The JSON file contains attribute values for the resource that you are modifying.
Based on those values, the parameters of the intended resource are modified.
{"parameter1":"newvalue1", "parameter2":"newvalue2", "parameter3":"newvalue3"}After creating the JSON file, run the curl command, and pass the JSON data to the Satellite API to modify the existing resource.
[user@host]$curl --request PUT \--insecure \--usersat_username:sat_password\--header "Content-Type:application/json" \--data @file.json\API_ROUTE\| python -m json.tool
Use the DELETE HTTP verb with the API request to delete a resource from the Satellite Server.
To delete the resource, specify an API route that includes the numeric identifier of the intended resource.
Based on this numeric identifier, the API command instructs the Satellite Server to delete that resource.
[user@host]$curl --request DELETE \--insecure \--usersat_username:sat_password\--header "Content-Type:application/json" \API_ROUTE\| python -m json.tool
For example, the following curl command deletes the Test organization, which has an ID of 15.
[user@host]$curl --request DELETE \--insecure \--user admin:redhat \--header "Content-Type:application/json" \https://satellite.lab.example.com/katello/api/organizations/15 \| python -m json.tool
Red Hat Satellite 6 REST API documentation
For more information, see the API Requests in Different Languages chapter in the Red Hat Satellite 6.11 API Guide at https://access.redhat.com/documentation/en-us/red_hat_satellite/6.11/html-single/api_guide/index#chap-Red_Hat_Satellite-API_Guide-API_Requests_in_Different_Languages