Creating API endpoints with AWX

I’m posting this here because searching for this topic on google always returns the Ansible Tower API reference guide, and that’s not what i’m looking for.

We are using AWX for quite a few projects, one of them being automated infrastructure deployments. I have a few playbooks that we presenting to a different application (Service Now) as an API endpoint in AWX.

Service Now is able to launch this job via the API, and everything is working great, but the issue is how we pass data back to SerivceNow.

The only way we can find to return data back is using the debug module, which seems a bit janky. It does in fact work, but searching pages and pages of job_events seems a bit wasteful.

Any suggestions on how we should actually be controlling how data is sent back?

I realize this is a bit of a ramble so I can clarify if needed.

dufusk (dufusk@gmail.com) said:

I'm posting this here because searching for this topic on google always
returns the Ansible Tower API reference guide, and that's not what i'm
looking for.

We are using AWX for quite a few projects, one of them being automated
infrastructure deployments. I have a few playbooks that we presenting to a
different application (Service Now) as an API endpoint in AWX.

Service Now is able to launch this job via the API, and everything is
working great, but the issue is how we pass data back to SerivceNow.

The only way we can find to return data back is using the debug module,
which seems a bit janky. It does in fact work, but searching pages and
pages of job_events seems a bit wasteful.

Just post to whatever API you need to post whatever data.

Example modules:
- http://docs.ansible.com/ansible/latest/modules/jira_module.html
- https://docs.ansible.com/ansible/latest/modules/snow_record_module.html

Or use the URI module.

Bill

Maybe have your playbooks call an API endpoint in ServiceNow and post the data?

Due to some internal shortcomings we aren’t allowed access to the ServiceNow API’s, but yes ideally this would be the right way to do it.

If you are calling a playbook (not a workflow) and want to pass data back you can use the set_stats Ansible module.

For example:

  • set_stats:
    data:
    my_var: my_value

Then in the JSON response of GET /api/v2/jobs// there will be an artifacts entry like:

    "artifacts": {
        "my_var": "my_value"
    },

It works with per_host=no, but if I change it to per_host=yes, the artifact list is empty {} on AWX (it is properly shown as custom stats, though).

Is there any way to have per host stats except to combine them in the playbook?

Also what about workflow results? Can they be made accessible in the similar way?