
The idea of RESTful APIs is pretty appealing: using the basic components of the WWW as APIs to bring together services. Operations like HTTP GET and POST, base URIs and media types like JSON are supported almost everywhere simply because the web is supported almost everywhere, it is pretty easy to provide REST enabled servers, services and clients with a few clicks and calls. For this reason the API of Red Hat Satellite – and most of the other Red Hat products – is built as REST API.
I’ve already written an article about how to access the Satellite REST API via Ansible. Today I came across a rather handy example: sometimes you need to know the URLs of the Satellite provided repos. This can of course be queried via the API. But in contrast to my old article, we do not query the Foreman part of the api ($SATELLITE_URL/api/
) but the Katello part: /katello/api/
.
All repositories can be shown via the URL /katello/api/repositories?organization_id=1
. To query URLs on the command line I recommend Ansible:
$ ansible localhost -m uri -a "method=GET user=admin password=$PASSWORD force_basic_auth=yes validate_certs=no url=https://satellite-server.example.com/katello/api/repositories?organization_id=1&full_results=true"
localhost | SUCCESS => {
"apipie_checksum": "7cd3aad709af2f1ae18a3daa0915d712",
"cache_control": "must-revalidate, private, max-age=0",
"changed": false,
...
"id": 45,
"label": "EPEL_7_-_x86_64",
...
"product": {
"cp_id": "1452001252604",
"id": 127,
"name": "EPEL",
"sync_plan": [
"name",
"description",
"sync_date",
"interval",
"next_sync"
]
},
"relative_path": "Platin/Library/custom/EPEL/EPEL_7_-_x86_64",
"url": "http://dl.fedoraproject.org/pub/epel/7/x86_64/"
...
The option full_results
just ensures that the entire result is shown even if it is pretty long. Note that the product I can be used to query the entire product information:
$ ansible localhost -m uri -a "method=GET user=admin password=$PASSWORD force_basic_auth=yes validate_certs=no url=https://satellite-server.example.com/katello/api/products/127"
localhost | SUCCESS => {
...
"id": 127,
"label": "EPEL",
"last_sync": "2016-01-05 13:43:38 UTC",
"last_sync_words": "about 1 month",
"name": "EPEL",
"organization": {
...
The id of the repository can be used to query the full repository information, including a full repo path:
$ ansible localhost -m uri -a "method=GET user=admin password=$PASSWORD force_basic_auth=yes validate_certs=no url=https://satellite-server.example.com/katello/api/repositories/45"
localhost | SUCCESS => {
...
"content_type": "yum",
"full_path": "http://satellite-server.example.com/pulp/repos/Platin/Library/custom/EPEL/EPEL_7_-_x86_64",
...
If you want to skip the part figuring out the IDs manually but have a name you could search for, it is possible to filter the results. The search URL for this case would be: /katello/api/repositories?organization_id=1&full_results=true&search=*EPEL*"
as shown in the following example:
$ ansible localhost -m uri -a "method=GET user=admin password=$PASSWORD force_basic_auth=yes validate_certs=no url=https://satellite-server.example.com/katello/api/repositories?organization_id=1&full_results=true&search=*EPEL*"
localhost | SUCCESS => {
...
"relative_path": "Platin/Library/custom/EPEL/EPEL_7_-_x86_64",
...