Calling rest API from Ansible

Hi all,

I have the below task which requires to call a rest API in order to call another API.
Basically i have a dict of portgroups which i will need to call an API to get the ID from. {{ portgroupID }}

Then run the below code.
I guess i could do it in a separate task, but then how do i link the ID with item.portgroup_name? Is there any easy way? provided that these are coming from different sources?

  • name: Creating Mac Discovery Pol Binding
    uri:
    url: "https://{{ hostname }}/policy/api/v1/infra/segments/nsx-{{ item.portgroup_name | replace(’ ', ‘-’) }}/segment-discovery-profile-binding-maps/{{ portgroupID }}
    force_basic_auth: yes
    validate_certs: False
    headers:
    Accept: “application/json”
    Content-Type: “application/json”
    user: “{{ username }}”
    password: “{{ password }}”
    method: PATCH
    body: “{{ lookup(‘file’,‘files/macbind.json’) }}”
    status_code: “200”
    body_format: json
    with_items: “{{ jsondata.dvs_portgroup_info[lookup(‘vars’, ‘dvsName’)] }}”
    when:
  • item.portgroup_name.find(‘DVUplinks’) == -1
  • item.portgroup_name.find(‘nsx-’) == -1