First of all i am not sure if i am in the correct place but since i was a little lost in api specs: (Sorry your system didnt allow me to post links)
- Readhat api-catalog ansible-automation-controller
- AWX REST API
- Automation Controller API
- Ansible TOWER API (redirected from deployed Ansible Automation Platform in browseable API)
i’ll try my luck here. I try to use the AWX REST API in a java based application to call a job template of the Ansible Automation Platform. So first i tried “to find” the schema definition to generate my stubs.
In some Thread here someone pointed out it could be obtained via s3.amazonaws.com/awx-public-ci-files/devel/schema.json (maybe a possibility to download it directly in the docs would be handy).
As first test i call the /api/v2/job_templates/{id}/launch/ (POST) Endpoint and was a little confused about the specification.
- First i need to provide a version but its not defined in any way. Is the purpose to use it as /api/{version}/job_templates/{id}/launch/ ?
- Further i got exceptions after receiving the response because passwords_needed_to_start is defined as String in the JobLaunch but in reality (in my case) the Ansible Automation Platform returns an (empty) array. Also in the description it is mentioned that it would be an array so i guess the current definition is faulty? (Maybe this also effects JobDetail, JobList and JobRelaunch)
- In the end i tried to get the id from my call for further operations but i found out i couldn’t. That’s since the response is defined as #/definitions/JobLaunch which doesn’t contain the information. But in reality i get following response structure:
{
"job": 1,
"ignored_fields": {
},
"id": 1,
"type": "job",
"url": "/api/v2/jobs/1/",
"related": {
"created_by": "/api/v2/users/2/",
"modified_by": "/api/v2/users/2/",
"labels": "/api/v2/jobs/1/labels/",
"inventory": "/api/v2/inventories/57/",
"project": "/api/v2/projects/3/",
"organization": "/api/v2/organizations/11/",
"credentials": "/api/v2/jobs/1/credentials/",
"unified_job_template": "/api/v2/job_templates/8452/",
"stdout": "/api/v2/jobs/1/stdout/",
"execution_environment": "/api/v2/execution_environments/3/",
"job_events": "/api/v2/jobs/1/job_events/",
"job_host_summaries": "/api/v2/jobs/1/job_host_summaries/",
"activity_stream": "/api/v2/jobs/1/activity_stream/",
"notifications": "/api/v2/jobs/1/notifications/",
"create_schedule": "/api/v2/jobs/1/create_schedule/",
"job_template": "/api/v2/job_templates/8452/",
"cancel": "/api/v2/jobs/1/cancel/",
"relaunch": "/api/v2/jobs/1/relaunch/"
},
"summary_fields": {
"organization": {
"id": 11,
"name": "name",
"description": "description"
},
"inventory": {
"id": 57,
"name": "name",
"description": "description",
"has_active_failures": true,
"total_hosts": 5,
"hosts_with_active_failures": 1,
"total_groups": 0,
"has_inventory_sources": false,
"total_inventory_sources": 0,
"inventory_sources_with_failures": 0,
"organization_id": 11,
"kind": ""
},
"execution_environment": {
"id": 3,
"name": "1 DEFAULT | RedHat ee-supported-rhel8",
"description": "Ansible Engine v2.15. configuration_as_code managed.",
"image": "ansible-automation-platform-24/ee-supported-rhel8:latest"
},
"project": {
"id": 3,
"name": "1",
"description": "2",
"status": "successful",
"scm_type": "git",
"allow_override": true
},
"job_template": {
"id": 8452,
"name": "name",
"description": "description"
},
"unified_job_template": {
"id": 8452,
"name": "name",
"description": "description",
"unified_job_type": "job"
},
"created_by": {
"id": 2,
"username": "user",
"first_name": "first",
"last_name": "last"
},
"modified_by": {
"id": 2,
"username": "user",
"first_name": "first",
"last_name": "last"
},
"user_capabilities": {
"delete": false,
"start": true
},
"labels": {
"count": 0,
"results": []
},
"credentials": [
{
"id": 1583,
"name": "name",
"description": "description",
"kind": "ssh",
"cloud": false
},
{
"id": 1948,
"name": "name",
"description": "",
"kind": "vault",
"cloud": false
},
{
"id": 1686,
"name": "name",
"description": "description",
"kind": "vault",
"cloud": false
},
{
"id": 1928,
"name": "name",
"description": "descp",
"kind": "vault",
"cloud": false
}
]
},
"created": "2024-08-08T09:49:53.994483Z",
"modified": "2024-08-08T09:49:54.036005Z",
"name": "name",
"description": "description",
"job_type": "run",
"inventory": 57,
"project": 3,
"playbook": "playbook.yml",
"scm_branch": "1.2.3.4",
"forks": 0,
"limit": "host",
"verbosity": 0,
"extra_vars": "{\"version\": \"1\"}",
"job_tags": "tags",
"force_handlers": false,
"skip_tags": "",
"start_at_task": "",
"timeout": 0,
"use_fact_cache": false,
"organization": 11,
"unified_job_template": 8452,
"launch_type": "manual",
"status": "pending",
"execution_environment": 3,
"failed": false,
"started": null,
"finished": null,
"canceled_on": null,
"elapsed": 0.0,
"job_args": "",
"job_cwd": "",
"job_env": {
},
"job_explanation": "",
"execution_node": "",
"controller_node": "",
"result_traceback": "",
"event_processing_finished": false,
"launched_by": {
"id": 2,
"name": "someuser",
"type": "user",
"url": "/api/v2/users/2/"
},
"work_unit_id": null,
"job_template": 8452,
"passwords_needed_to_start": [],
"allow_simultaneous": false,
"artifacts": {
},
"scm_revision": "",
"instance_group": null,
"diff_mode": false,
"job_slice_number": 0,
"job_slice_count": 1,
"webhook_service": "",
"webhook_credential": null,
"webhook_guid": ""
}
All informations i need would be present but not accessible.
- Is my assumption correct that the AWX REST API is the point of truth? Or is the API changed extended in Ansible Automation Controller/Ansible Tower?
- Is it even correct to assume that only one “v2” API exists and any little change would result in “v3”?
- If not how can i find out which exactly version of the AWX REST API the Ansible Automation Platform is using (Can’t find any hint in any docs)
- Am i using the API correctly? Since i am not familiar with all aspects of the products/api i am not sure if i use it as intended?
Current Endpoint Definition:
"/api/v2/job_templates/{id}/launch/": {
"get": {
"description": "...",
"operationId": "api_job_templates_launch_read",
"parameters": [],
"responses": {
"200": {
"description": "",
"schema": {
"$ref": "#/definitions/JobLaunch"
}
}
},
"summary": "Make a GET request to this resource to determine if the job_template can be",
"tags": [
"api"
]
},
"parameters": [
{
"in": "path",
"name": "version",
"required": true,
"type": "string"
},
{
"in": "path",
"name": "id",
"required": true,
"type": "string"
}
],
"post": {
"description": "...",
"operationId": "api_job_templates_launch_create",
"parameters": [
{
"in": "body",
"name": "data",
"required": true,
"schema": {
"$ref": "#/definitions/JobLaunch"
}
}
],
"responses": {
"201": {
"description": "",
"schema": {
"$ref": "#/definitions/JobLaunch"
}
}
},
"summary": "Make a GET request to this resource to determine if the job_template can be",
"tags": [
"api"
]
}
}
Schema Definition of JobLaunch:
"JobLaunch": {
"properties": {
"ask_credential_on_launch": {
"readOnly": true,
"title": "Ask credential on launch",
"type": "boolean",
"x-nullable": true
},
"ask_diff_mode_on_launch": {
"readOnly": true,
"title": "Ask diff mode on launch",
"type": "boolean",
"x-nullable": true
},
"ask_execution_environment_on_launch": {
"readOnly": true,
"title": "Ask execution environment on launch",
"type": "boolean",
"x-nullable": true
},
"ask_forks_on_launch": {
"readOnly": true,
"title": "Ask forks on launch",
"type": "boolean",
"x-nullable": true
},
"ask_instance_groups_on_launch": {
"readOnly": true,
"title": "Ask instance groups on launch",
"type": "boolean",
"x-nullable": true
},
"ask_inventory_on_launch": {
"readOnly": true,
"title": "Ask inventory on launch",
"type": "boolean",
"x-nullable": true
},
"ask_job_slice_count_on_launch": {
"readOnly": true,
"title": "Ask job slice count on launch",
"type": "boolean",
"x-nullable": true
},
"ask_job_type_on_launch": {
"readOnly": true,
"title": "Ask job type on launch",
"type": "boolean",
"x-nullable": true
},
"ask_labels_on_launch": {
"readOnly": true,
"title": "Ask labels on launch",
"type": "boolean",
"x-nullable": true
},
"ask_limit_on_launch": {
"readOnly": true,
"title": "Ask limit on launch",
"type": "boolean",
"x-nullable": true
},
"ask_scm_branch_on_launch": {
"readOnly": true,
"title": "Ask scm branch on launch",
"type": "boolean",
"x-nullable": true
},
"ask_skip_tags_on_launch": {
"readOnly": true,
"title": "Ask skip tags on launch",
"type": "boolean",
"x-nullable": true
},
"ask_tags_on_launch": {
"readOnly": true,
"title": "Ask tags on launch",
"type": "boolean",
"x-nullable": true
},
"ask_timeout_on_launch": {
"readOnly": true,
"title": "Ask timeout on launch",
"type": "boolean",
"x-nullable": true
},
"ask_variables_on_launch": {
"readOnly": true,
"title": "Ask variables on launch",
"type": "boolean",
"x-nullable": true
},
"ask_verbosity_on_launch": {
"readOnly": true,
"title": "Ask verbosity on launch",
"type": "boolean",
"x-nullable": true
},
"can_start_without_user_input": {
"readOnly": true,
"title": "Can start without user input",
"type": "boolean"
},
"credential_needed_to_start": {
"readOnly": true,
"title": "Credential needed to start",
"type": "string"
},
"credential_passwords": {
"title": "Credential passwords",
"type": "string"
},
"credentials": {
"items": {
"type": "integer"
},
"type": "array",
"uniqueItems": true
},
"defaults": {
"readOnly": true,
"title": "Defaults",
"type": "string"
},
"diff_mode": {
"title": "Diff mode",
"type": "boolean"
},
"execution_environment": {
"title": "Execution environment",
"type": "integer"
},
"extra_vars": {
"title": "Extra vars",
"type": "object"
},
"forks": {
"minimum": 0,
"title": "Forks",
"type": "integer"
},
"instance_groups": {
"items": {
"type": "integer"
},
"type": "array",
"uniqueItems": true
},
"inventory": {
"title": "Inventory",
"type": "integer"
},
"inventory_needed_to_start": {
"readOnly": true,
"title": "Inventory needed to start",
"type": "string"
},
"job_slice_count": {
"minimum": 0,
"title": "Job slice count",
"type": "integer"
},
"job_tags": {
"title": "Job tags",
"type": "string"
},
"job_template_data": {
"readOnly": true,
"title": "Job template data",
"type": "string"
},
"job_type": {
"enum": [
"run",
"check"
],
"title": "Job type",
"type": "string"
},
"labels": {
"items": {
"type": "integer"
},
"type": "array",
"uniqueItems": true
},
"limit": {
"title": "Limit",
"type": "string"
},
"passwords_needed_to_start": {
"readOnly": true,
"title": "Passwords needed to start",
"type": "string"
},
"scm_branch": {
"title": "Scm branch",
"type": "string"
},
"skip_tags": {
"title": "Skip tags",
"type": "string"
},
"survey_enabled": {
"readOnly": true,
"title": "Survey enabled",
"type": "string"
},
"timeout": {
"title": "Timeout",
"type": "integer"
},
"variables_needed_to_start": {
"readOnly": true,
"title": "Variables needed to start",
"type": "string"
},
"verbosity": {
"enum": [
0,
1,
2,
3,
4,
5
],
"title": "Verbosity",
"type": "integer"
}
},
"type": "object"
}
I would happy if anybody could help me with this or point me to the correct direction.