Handling REST API output with json_query

31 views
Skip to first unread message

Mike Cifelli

unread,
Jun 22, 2021, 2:41:49 PM6/22/21
to Ansible Development
Seeking assistance with properly parsing returned json data, storing desired string as variable, to then append it in another play that updates a resource.  Essentially I am interacting with Cisco ISE APIs to manage/update endpoint attributes.  Overview of playbook:

-The first play is a GET query to provide me with a specific endpoint details

-The next play prints the returned output essentially showing the admin that everything is good thus far

-Then I extract the endpoint ID string using json_query and store it as a variable

-For peace of mind the following play prints the variable to show we have the ID string of the endpoint

-Then the last play I attempt to update the endpoint group assignment via appending the id string 

I am stuck on the last play that appends the endpoint id string.  Play using json_query:

  - name: Get ISE ID String

    set_fact:

     id: "{{ endpoint_id | json_query(jmesquery) }}"

    vars:

      jmesquery: '*.SearchResult.resources[*].id'

Tower output showing how the id string is being appended:

"status": 400, "url": "https://xx.xx.xx.xx:9060/ers/config/endpoint/[[u'69d3bf30-ce12-11eb-ba90-c63c5470e9ab']]"

How can I properly store/append the endpoint id string properly so that the url in my last play looks like this:

"status": 400, "url": "https://xx.xx.xx.xx:9060/ers/config/endpoint/69d3bf30-ce12-11eb-ba90-c63c5470e9ab"

  Please advise.  TIA!

Mike Cifelli

unread,
Jun 23, 2021, 2:16:06 PM6/23/21
to Ansible Development
Here is the solution:

- name: Extract ID from Nested List 
  set_fact: id: "{{ id[0][0] }}"

Reply all
Reply to author
Forward
0 new messages