how to return additional variables as a part of job status get request

117 views
Skip to first unread message

Punit Jain

unread,
Feb 24, 2020, 11:00:19 AM2/24/20
to AWX Project
Hi,

I am using ansible AWX for issuing REST calls for calling playbook. Playbook connects to downstream servers and provisions storage using underlying storage API's and registers o/p of rest call. My requirement is to get back a o/p of rest call as a part of job status call, however i am not able to do that as of now. Here is test playbook.

---
- name: Get REST o/p
  connection: local
  gather_facts: false
  hosts: localhost
  tasks:
    - name: print a sample message
      debug:
        msg: "Test playbook"

    - name: get value and print
      debug:
        var=key
      register: outputvalue

Calling it using REST at endpoint <AWX server>/api/v2/job_templates/11/launch/ results in getting back job id

{
    "job": 55,
    "ignored_fields": {
        "extra_vars": {
            "key": "test key"
        }
    },
    "id": 55,
    "type": "job",
    "url": "/api/v2/jobs/55/",
    "related": {
        "created_by": "/api/v2/users/2/",
        "modified_by": "/api/v2/users/2/",
        "labels": "/api/v2/jobs/55/labels/",
        "inventory": "/api/v2/inventories/1/",
        "project": "/api/v2/projects/10/",
        "extra_credentials": "/api/v2/jobs/55/extra_credentials/",
        "credentials": "/api/v2/jobs/55/credentials/",
        "unified_job_template": "/api/v2/job_templates/11/",
        "stdout": "/api/v2/jobs/55/stdout/",
        "job_events": "/api/v2/jobs/55/job_events/",
        "job_host_summaries": "/api/v2/jobs/55/job_host_summaries/",
        "activity_stream": "/api/v2/jobs/55/activity_stream/",
        "notifications": "/api/v2/jobs/55/notifications/",
        "create_schedule": "/api/v2/jobs/55/create_schedule/",
        "job_template": "/api/v2/job_templates/11/",
        "cancel": "/api/v2/jobs/55/cancel/",
        "relaunch": "/api/v2/jobs/55/relaunch/"
    },
    "summary_fields": {
        "inventory": {
            "id": 1,
            "name": "Demo Inventory",
            "description": "",
            "has_active_failures": false,
            "total_hosts": 1,
            "hosts_with_active_failures": 0,
            "total_groups": 0,
            "has_inventory_sources": false,
            "total_inventory_sources": 0,
            "inventory_sources_with_failures": 0,
            "organization_id": 1,
            "kind": ""
        },
        

on querying the job status, api/v2/jobs/55/ the result is :

{
    "id": 55,
    "type": "job",
    "url": "/api/v2/jobs/55/",
    "related": {
        "created_by": "/api/v2/users/2/",
        "labels": "/api/v2/jobs/55/labels/",
        "inventory": "/api/v2/inventories/1/",
        "project": "/api/v2/projects/10/",
        "extra_credentials": "/api/v2/jobs/55/extra_credentials/",
        "credentials": "/api/v2/jobs/55/credentials/",
        "unified_job_template": "/api/v2/job_templates/11/",
        "stdout": "/api/v2/jobs/55/stdout/",
        "job_events": "/api/v2/jobs/55/job_events/",
        "job_host_summaries": "/api/v2/jobs/55/job_host_summaries/",
        "activity_stream": "/api/v2/jobs/55/activity_stream/",
        "notifications": "/api/v2/jobs/55/notifications/",
        "create_schedule": "/api/v2/jobs/55/create_schedule/",
        "job_template": "/api/v2/job_templates/11/",
        "cancel": "/api/v2/jobs/55/cancel/",
        "relaunch": "/api/v2/jobs/55/relaunch/"
    },
    "summary_fields": {
        "inventory": {
            "id": 1,
            "name": "Demo Inventory",
            "description": "",
            "has_active_failures": false,
            "total_hosts": 1,
            "hosts_with_active_failures": 0,
            "total_groups": 0,
            "has_inventory_sources": false,
            "total_inventory_sources": 0,
            "inventory_sources_with_failures": 0,
            "organization_id": 1,
            "kind": ""
        },
        "project": {
            "id": 10,
            "name": "demoproj",
            "description": "",
            "status": "successful",
            "scm_type": "git"
        },
    "created": "2020-02-24T15:33:28.807983Z",
    "modified": "2020-02-24T15:33:29.077686Z",
    "name": "demotemplate",
    "description": "",
    "job_type": "run",
    "inventory": 1,
    "project": 10,
    "playbook": "test.yml",
    "scm_branch": "",
    "forks": 0,
    "limit": "",
    "verbosity": 0,
    "extra_vars": "{}",
    "job_tags": "",
    "force_handlers": false,
    "skip_tags": "",
    "start_at_task": "",
    "timeout": 0,
    "use_fact_cache": false,
    "unified_job_template": 11,
    "launch_type": "manual",
    "status": "successful",
    "failed": false,
    "started": "2020-02-24T15:33:29.153003Z",
    "finished": "2020-02-24T15:33:31.625738Z",


What I see in response is only status: successful. 

How do i attach a variable to JSOn response from job status ?

Thanks and Regards,
Punit

Punit Jain

unread,
Feb 25, 2020, 1:15:29 AM2/25/20
to AWX Project
Hi Team,

Any advice on this ?

Regards,
Punit

--
You received this message because you are subscribed to the Google Groups "AWX Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to awx-project...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/awx-project/5f822f0a-074a-4638-a5e9-6069873624a9%40googlegroups.com.

Mani Mohan

unread,
Feb 25, 2020, 4:10:28 AM2/25/20
to Punit Jain, AWX Project
Hi Punit,

You can try this below API query.
api/v2/jobs/55/job_events/?task=Your_task_name.

In your code you have to display the results of that particular variable in the task " Your_task_name " 
and the API query will print the results in json format, then you have to dig in a bit to see your custom result.

Let me know if you have any questions.

Thanks and Regards
Mani Mohan

Punit Jain

unread,
Feb 25, 2020, 10:07:29 AM2/25/20
to Mani Mohan, AWX Project
Thanks Mani. That works.

Regards,
Punit
Reply all
Reply to author
Forward
0 new messages