0

I have the following set_fact task:

- set_fact:
   task_uuid: "{{ task_status.json  |lower |to_json | from_json |json_query('taskuuid') }}"

This is what I have for the task_status.json:

 debug:
   var: task_status.json
{
"task_status.json": {
    "taskUuid": "e66cea71-ef33-4610-9194-0403e4bb2153"
}
}

Output: task_uuid var is empty.

I tried any and all combination (removed the to_json,from_json,etc).

Please advice. I am basically looking to pull the value of taskUUID.

I am re-using the set_fact task for a few api endpoints - some of which give 'taskUuid' and some give 'taskuuid' and some even 'task_uuid' - i m finding a way to get the UUID from these endpoints using a common filter

Vijay Nidhi
  • 161
  • 1
  • 1
  • 9
  • identifiers are case sensitive => taskuuid is wrong, You want taskUuid. Moreover, you can apply `json_query` directly to your variable. And in this case, you don't even need json_query at all => `task_status.json.taskUuid` – Zeitounator Apr 06 '20 at 14:13
  • Hi @Zeitounator - thanks for the reply - is there a way to lowercaps the taskUuid. The reason is - i m re-using the same set_fact based on a rest api response(via uri module) for a variety of api endpoints. Some return 'taskuuid', some return 'taskUuid' and some in fact return task_uuid. Hence in above - itried to lower it all with lower – Vijay Nidhi Apr 06 '20 at 14:17
  • Now I understand. You should edit your question to make what your are trying to do more obvious. – Zeitounator Apr 06 '20 at 14:19
  • @Zeitounator- thanks updated the question to add more context Also I did not get your statement: "Moreover, you can apply json_query directly to your variable" - i thought that is what I m doing above? – Vijay Nidhi Apr 06 '20 at 14:23
  • I just didn't get why you were trying to lower the content, so not really getting why you were applying all those filters to your var before using json_query. – Zeitounator Apr 06 '20 at 14:26

1 Answers1

1

This is how I would do to make sure I catch either case, whether the identifier is camel case or not:

    - set_fact:
        task_uuid : "{{ task_status.json.taskUuid | default(task_status.json.taskuuid | default(''))  }}"

The nested default is just there to make sure the task does not fail in case neither identifiers are present. Adapt to your own need.

Zeitounator
  • 38,476
  • 7
  • 53
  • 66