Bug 1677907 - Ansible API endpoints return 404
Summary: Ansible API endpoints return 404
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Red Hat Satellite
Classification: Red Hat
Component: API
Version: 6.4.2
Hardware: x86_64
OS: Linux
medium
medium
Target Milestone: 6.8.0
Assignee: Oleh Fedorenko
QA Contact: Lukáš Hellebrandt
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2019-02-16 18:25 UTC by Taft Sanders
Modified: 2021-12-01 10:49 UTC (History)
7 users (show)

Fixed In Version: tfm-rubygem-foreman_ansible-5.0.1
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2020-10-27 12:58:15 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Foreman Issue Tracker 29034 0 Normal Closed Update Ansible API docs for inventories 2021-02-11 14:33:04 UTC
Red Hat Product Errata RHSA-2020:4366 0 None None None 2020-10-27 12:58:34 UTC

Description Taft Sanders 2019-02-16 18:25:03 UTC
Description of problem:
Ansible endpoints from the API docs return 404 when trying to access via apache

Version-Release number of selected component (if applicable):
6.4.2

How reproducible:
Everytime

Steps to Reproduce:
1. curl any ansible API endpoint
2.
3.

Actual results:
404 error

Expected results:
A list of all ansible roles

Additional info:
# curl -H "Content-Type:application/json" -X GET -s -k -u admin:redhat http://satellite.redhat.com/ansible/api/ansible_roles/
<!DOCTYPE html>
<html>
<head>
  <title>The page you were looking for doesn't exist (404)</title>
...

From the hammer output we can see this is the correct endpoint being called when using debug mode:

# hammer -d ansible roles list
....
[ INFO 2019-02-15T23:38:00 API] Server: https://satellite.redhat.com
[ INFO 2019-02-15T23:38:00 API] GET /ansible/api/ansible_roles
...

Comment 1 Marek Hulan 2019-02-18 08:17:39 UTC
I can't reproduce on my 6.4.2 instance, please upload your version of foreman_ansible package, mine is

tfm-rubygem-foreman_ansible-2.2.9-8.el7sat.noarch

try also running hammer with --reload-cache. Also check you don't have any default or non-existing organization set in your hammer config. See "hammer defaults list". You'll get 404 if the organization/location does not exist. If that does not help, please provide a reproducer environment.

Comment 2 Nikhil Kathole 2019-04-03 05:57:09 UTC
Ansible API works only with v2. I guess its not bug.

# curl -s -X GET -k -u admin:changeme  'https://satelite/ansible/api/v2/ansible_roles/'
{
  "total": 2,
  "subtotal": 2,
  "page": 1,
  "per_page": 20,
  "search": null,
  "sort": {
    "by": null,
    "order": null
  },
  "results": [{"id":1,"name":"adriagalin.motd","created_at":"2019-03-29 17:41:34 UTC","updated_at":"2019-03-29 17:41:34 UTC"},{"id":2,"name":"RedHatInsights.insights-client","created_at":"2019-03-29 17:41:34 UTC","updated_at":"2019-03-29 17:41:34 UTC"}]
}


# curl -s -X GET -k -u admin:changeme  'https://satellite/ansible/api/ansible_roles/'
<!DOCTYPE html>
<html>
<head>
  <title>The page you were looking for doesn't exist (404)</title>

Comment 5 Marek Hulan 2019-04-03 07:15:15 UTC
Thanks for looking into this Nikhil, closing as notabug. Please reopen if we misunderstood something.

Comment 6 Taft Sanders 2020-02-10 13:31:50 UTC
Hello,

API documentation found at http://<SATELLITE>/apidoc/v2.html that appears to be provided by the foreman package shows a list of the following ansible endpoints:

Ansible inventories
Resource	Description
POST /api/ansible_inventories/hosts	Show Ansible inventory for hosts
GET /api/ansible_inventories/hosts	Show Ansible inventory for hosts
POST /api/ansible_inventories/hostgroups	Show Ansible inventory for hostgroups
GET /api/ansible_inventories/hostgroups	Show Ansible inventory for hostgroups

Ansible override values
Resource	Description
POST /ansible/api/ansible_override_values	Create an override value for a specific ansible variable
DELETE /ansible/api/ansible_override_values/:id	Destroy an override value

Ansible roles
Resource	Description
GET /ansible/api/ansible_roles/:id	Show role
GET /ansible/api/ansible_roles	List Ansible roles
DELETE /ansible/api/ansible_roles/:id	Deletes Ansible role
PUT /ansible/api/ansible_roles/import	Import Ansible roles
PUT /ansible/api/ansible_roles/obsolete	Obsolete Ansible roles
GET /ansible/api/ansible_roles/fetch	Fetch Ansible roles available to be imported

Ansible variables
Resource	Description
GET /ansible/api/ansible_variables/:id	Show variable
GET /ansible/api/ansible_variables	List Ansible variables
DELETE /ansible/api/ansible_variables/:id	Deletes Ansible variable
POST /ansible/api/ansible_variables	Create Ansible variable
PUT /ansible/api/ansible_variables/:id	Updates Ansible variable
PUT /ansible/api/ansible_variables/import	Import Ansible variables. This will only import variables for already existing roles, it will not import any new roles
PUT /ansible/api/ansible_variables/obsolete	Obsolete Ansible variables. This will only obsolete variables for already existing roles, it will not delete any old roles


It appears that the inventories section is missing the "ansible" prefix to its calls, along with all ansible calls missing the "v2" prefix to the endpoints. I can confirm it works with ansible and v2 added to the endpoints:

# curl -s -X GET -k -u apiuser:redhat https://batman.usersys.redhat.com/ansible/api/v2/ansible_inventories/hosts
{"all":{"hosts":[],"vars":{}},"_meta":{"hostvars":{}}}

Comment 7 Oleh Fedorenko 2020-02-17 15:43:08 UTC
Created redmine issue https://projects.theforeman.org/issues/29034 from this bug

Comment 8 Bryan Kearney 2020-02-17 17:05:52 UTC
Upstream bug assigned to ofedoren

Comment 9 Bryan Kearney 2020-02-17 17:05:54 UTC
Upstream bug assigned to ofedoren

Comment 10 Bryan Kearney 2020-02-20 09:07:23 UTC
Moving this bug to POST for triage into Satellite 6 since the upstream issue https://projects.theforeman.org/issues/29034 has been resolved.

Comment 11 Lukáš Hellebrandt 2020-06-29 14:21:53 UTC
Verified with Sat 6.8 snap 6.0.

Tried all request types with API endpoints from all ansible-related sections of apidoc (e.g. [0], [1]). They actually return data, not 404 error.

[0] curl -H "Content-Type:application/json" -X GET -k -u admin:changeme https://<FQDN>/ansible/api/ansible_inventories/hosts
[1] curl -H "Content-Type:application/json" -X POST -k -u admin:changeme https://<FQDN>/ansible/api/ansible_override_values -d '{"ansible_variable_id":"21", "override_value":{"match": "domain=domena", "value": "hodnota"}}'

Comment 14 errata-xmlrpc 2020-10-27 12:58:15 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory (Important: Satellite 6.8 release), and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHSA-2020:4366


Note You need to log in before you can comment on or make changes to this bug.