Return variables & their values, which can be picked leveraging Morpheus APIs after running a job

In the response below I am wondering if there is a way to return variables out-side of Ansible OUTPUT as part of JSON response?
The Ansible output in the Bold does have what I need but its coming out as unformatted string which is a pain to manipulate.

{
“jobExecution”: {
“id”: 2106,
“name”: “SG LDAP Search”,
“process”: {
“id”: 3744,
“accountId”: 9,
“uniqueId”: “0b426a8e-cc13-4693-b1d8-665f38398b6b”,
“processType”: {
“code”: “localWorkflow”,
“name”: “local workflow”
},
“displayName”: null,
“description”: “SG LDAP Search”,
“subType”: null,
“subId”: null,
“zoneId”: null,
“integrationId”: null,
“appId”: null,
“instanceId”: null,
“containerId”: null,
“serverId”: null,
“containerName”: null,
“status”: “complete”,
“reason”: null,
“percent”: 100.0,
“statusEta”: 0,
“message”: null,
“output”: null,
“error”: null,
“startDate”: “2022-04-27T12:56:34Z”,
“endDate”: “2022-04-27T12:56:45Z”,
“duration”: 11490,
“dateCreated”: “2022-04-27T12:56:34Z”,
“lastUpdated”: “2022-04-27T12:56:45Z”,
“createdBy”: {
“username”: “”,
“displayName”: “svc-SANITISED”
},
“updatedBy”: {
“username”: “”,
“displayName”: “svc-SANITISED”
},
“events”: [
{
“id”: 6040,
“processId”: 3744,
“accountId”: 9,
“uniqueId”: “8c1e202f-6f0e-43bf-88b6-ee6470a3c08f”,
“processType”: {
“code”: “executeTask”,
“name”: “execute task”
},
“description”: “SG - LDAP Search”,
“refType”: “jobTemplate”,
“refId”: 2102,
“subType”: null,
“subId”: null,
“zoneId”: null,
“integrationId”: null,
“instanceId”: null,
“containerId”: null,
“serverId”: null,
“containerName”: null,
“displayName”: null,
“status”: “complete”,
“reason”: null,
“percent”: 100.0,
“statusEta”: 14574,
“message”:"[1;35m[WARNING]: provided hosts list is empty, only localhost is available. Note that[0m\n[1;35mthe implicit localhost does not match ‘all’[0m\n",
**“output”:"\nPLAY [localhost] *************************************************************\n\n
**TASK [Lookup an AD User] *****************************************************\n[0;32mok: [localhost][0m\n\n
**TASK [Spit ldap_attributes] **************************************************\n[0;32mok: [localhost] => {[0m\n[0;32m “msg”: [[0m\n[0;32m {[0m\n[0;32m “dn”: “CN=SANITISED,OU=Partners,OU=Accounts,DC=REGION,DC=SANITISED,DC=net”, [0m\n[0;32m “givenName”: “F_Name”, [0m\n[0;32m “mail”: \F_name.L_name@SANITISED.com, [0m\n[0;32m “sAMAccountName”: “SANITISED”, [0m\n[0;32m “sn”: “L_Name”[0m\n[0;32m }[0m\n[0;32m ][0m\n[0;32m}[0m\n\n
**TASK [Spit ldap_attributes.results] ******************************************\n[0;32mok: [localhost] => (item={u’dn’: u’CN=SANITISED,OU=Partners,OU=Accounts,DC=REGION,DC=SANITISED,DC=net’, u’mail’: u’F_name.L_name@SANITISED.com’, u’givenName’: u’F_name’, u’sn’: u’L_name’, u’sAMAccountName’: u’SANITISED’}) => {[0m\n[0;32m “msg”: “Firstname: F_name Lastname: L_name sAMAccountName: SANITISED mail: F_name.L_name@SANITISED.com”[0m\n[0;32m}[0m\n\n
**TASK [Lookup an AD Group] ******************************************************\n[0;32mok: [localhost][0m\n\nTASK [Exit if an AD Group is not found] **************************************\n[0;36mskipping: [localhost][0m\n\n
**PLAY RECAP *******************************************************************\n[0;32mlocalhost[0m : [0;32mok=4 [0m changed=0 unreachable=0 failed=0 [0;36mskipped=1 [0m rescued=0 ignored=0 \n\n",
“error”:"[1;35m[WARNING]: provided hosts list is empty, only localhost is available. Note that[0m\n[1;35mthe implicit localhost does not match ‘all’[0m\n",
“startDate”: “2022-04-27T12:56:34Z”,
“endDate”: “2022-04-27T12:56:45Z”,
“duration”: 11484,
“dateCreated”: “2022-04-27T12:56:34Z”,
“lastUpdated”: “2022-04-27T12:56:45Z”,
“createdBy”: {
“username”: “”,
“displayName”: “svc-SANITISED”
},
“updatedBy”: {
“username”: “”,
“displayName”: “svc-SANITISED”
}
}
]
},
“job”: {
“id”: 2102,
“name”: “SG LDAP Search”,
“description”: null,
“type”: {
“id”: 2,
“code”: “morpheus.workflow”,
“name”: “Workflow Job”
}
},
“description”: null,
“dateCreated”: “2022-04-27T12:56:34Z”,
“startDate”: “2022-04-27T12:56:34Z”,
“endDate”: “2022-04-27T12:56:45Z”,
“duration”: 11498,
“resultData”: “{“success”:true,“msg”:null,“processId”:3744}”,
“status”: “success”,
“statusMessage”: null,
“createdBy”: {
“id”: 137,
“username”: “svc-SANITISED”,
“displayName”: “svc-SANITISED”
}
}
}

Something like this is on the table for future Ansible task updates. It would fall under a Feature Request/Idea.

That being said, Ansible pretty much just barfs out to stdout. There’s no good way to parse that data. The solution I had in my head was an Ansible module that would push task runtime data back to Morpheus for use in the rest of the workflow. Something like:

- name: get file info
  stat:
    path: /etc/os-release
  register: osinfo

- name: push var to morpheus
  morpheus.pushdata:
    key: myvarname
    value: "{{ osinfo.checksum }}"

# in the next task, which is python
print(morpheus['taskvars']['myvarname']
# would print 
50ba294cdf28c0d5bcde25708df53346825a429f

Please note, there is no timeframe currently for anything like this being added.