# How to loop JSON of API CALL - Ansible

**URL:** <https://forum.ansible.com/t/how-to-loop-json-of-api-call-ansible/23266>\
**Category:** Ansible Project\
**Created:** [December 15, 2016, 2:10pm UTC](https://forum.ansible.com/t/how-to-loop-json-of-api-call-ansible/23266 "2016-12-15T14:10:36Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hector\_Marina1](https://avatars.discourse-cdn.com/v4/letter/h/a8b319/32.png) [@Hector\_Marina1](https://forum.ansible.com/u/Hector_Marina1)\
**Post date:** [December 15, 2016, 2:10pm UTC](https://forum.ansible.com/t/how-to-loop-json-of-api-call-ansible/23266/1 "2016-12-15T14:10:36Z")

</div>

Hello all, I have an API call, called by Ansible module. I want that this JSON loop ‘n’ times with differents values. This is the JSON:

> ```auto
> {
> "name": "{{hostname}}",
> "links": [
> {
> "href": "https://xxxxxxxxxx.ixxi-servicios.com/api/admin/enterprises/2",
> "rel": "enterprise"
> },
> {
> "href": "https://cxxxxxxter.xxxx-serxxxvicios.com/api/admin/enterprises/2/datacenterrepositories/1/virtualmachinetemplates/{{id_template.stdout}}",
> "rel": "virtualmachinetemplate"
> },
> {
> "title":"{{ip}}",
> "rel":"nic1",
> "type":"xxxx/vnd.xxxxx.externalip+json",
> "href": "https://xxxxxx.xxxx-xxxxxx.com:443/api/admin/enterprises/2/limits/2/externalnetworks/{{id_vlan.stdout}}/ips/{{id_ip.stdout}}"
> }
> ],
> "variables": {
> "net-ip0": "{{ip}}",
> "net-mask0": "{{netmask}}",
> "net-gw0": "{{gateway}}",
> "hostname": "{{hostname}}"
> },
> "ram": "{{ram}}",
> "cpu": "{{cpu}}",
> "description": "{{hostname}}"
> }
> 
> ```

The values that must vary the value are:

- {{id\_template.stdout}}
- {{id\_vlan.stdout}}
- {{id\_ip.stdout}}
- {{ip}}
- {{netmask}}
- {{gateway}}

I will use this to add some ethernet interfaces into VM. This vars are defined in other file like this:

```auto
hostname: 'prueba'
cpu: '1'
ram: '1024'
template: 'CENTOS_6.5_AUTO'

nic:
- nic: nic1
  ip: '192.168.1.1'
  netmask: '255.255.255.192'
  gateway: '192.168.1.1'
  vlan: 'vlan1'
- nic: nic2
  ip: '192.168.1.2'
  netmask: '255.255.255.192'
  gateway: '192.168.1.4'
  vlan: 'vlan2'

```

The loop should be use this information to insert in the JSON this vars as many times as the number of nic we have.

any ideas?
