title: How to nest variable in ansible with for
body: <p>I am working with Ansible and I need to display a list of the hosts' network interfaces. In a Jinja2 format template I need the following values: Name, IP, Mask and Network for each of the interfaces. To have this information I use the ansible_facts but I have a problem when making the for.</p>
  <p>I get the network interfaces from here:</p>
  <pre><code>&quot;ansible_interfaces&quot;: [
      &quot;eth1&quot;,
      &quot;eth0&quot;,
      &quot;lo&quot;
  ],
  </code></pre>
  <p>So far so good, I make a for and it shows me all three. My problem is that the information I need from each interface is separated in jason:</p>
  <pre><code>&quot;ansible_eth0&quot;: {
      &quot;active&quot;: true,
      &quot;device&quot;: &quot;eth0&quot;,
      &quot;hw_timestamp_filters&quot;: [],
      &quot;ipv4&quot;: {
          &quot;address&quot;: &quot;x.x.x.x&quot;,
          &quot;broadcast&quot;: &quot;x.x.x.x&quot;,
          &quot;netmask&quot;: &quot;255.255.192.0&quot;,
          &quot;network&quot;: &quot;x.x.x.x&quot;
      },
      &quot;ipv4_secondaries&quot;: [
          {
              &quot;address&quot;: &quot;x.x.x.x&quot;,
              &quot;broadcast&quot;: &quot;x.x.x.x&quot;,
              &quot;netmask&quot;: &quot;255.255.0.0&quot;,
              &quot;network&quot;: &quot;x.x.x.x&quot;
          }
      ],
      &quot;ipv6&quot;: [
          {
              &quot;address&quot;: &quot;&quot;,
              &quot;prefix&quot;: &quot;64&quot;,
              &quot;scope&quot;: &quot;link&quot;
          }
      ],
      &quot;macaddress&quot;: &quot;&quot;,
      &quot;module&quot;: &quot;virtio_net&quot;,
      &quot;mtu&quot;: 1500,
      &quot;pciid&quot;: &quot;virtio0&quot;,
      &quot;promisc&quot;: false,
      &quot;speed&quot;: -1,
      &quot;timestamping&quot;: [
          &quot;tx_software&quot;,
          &quot;rx_software&quot;,
          &quot;software&quot;
      ],
      &quot;type&quot;: &quot;ether&quot;
  },
  &quot;ansible_eth1&quot;: {
      &quot;active&quot;: true,
      &quot;device&quot;: &quot;eth1&quot;,
      &quot;hw_timestamp_filters&quot;: [],
      &quot;ipv4&quot;: {
          &quot;address&quot;: &quot;x.x.x.x&quot;,
          &quot;broadcast&quot;: &quot;x.x.x.x&quot;,
          &quot;netmask&quot;: &quot;255.255.240.0&quot;,
          &quot;network&quot;: &quot;x.x.x.x&quot;
      },
      &quot;ipv6&quot;: [
          {
              &quot;address&quot;: &quot;&quot;,
              &quot;prefix&quot;: &quot;64&quot;,
              &quot;scope&quot;: &quot;link&quot;
          }
      ],
      &quot;macaddress&quot;: &quot;&quot;,
      &quot;module&quot;: &quot;virtio_net&quot;,
      &quot;mtu&quot;: 1500,
      &quot;pciid&quot;: &quot;virtio1&quot;,
      &quot;promisc&quot;: false,
      &quot;speed&quot;: -1,
      &quot;timestamping&quot;: [
          &quot;tx_software&quot;,
          &quot;rx_software&quot;,
          &quot;software&quot;
      ],
      &quot;type&quot;: &quot;ether&quot;
  },
  </code></pre>
  <p>To get this information I try it in the following way:</p>
  <pre><code>{{% for interfaz in ansible_interfaces %}}
  {{% for item in ansible_['interfaz'] %}}
  
  Name: {{ item.device }}
  IP: {{ item.ipv4.address }}
  Netmask: {{ item.ipv4.metmask }}
  Red: {{ item.ipv4.network }}
  
  {{% endfor %}}
  {{% endfor %}}
  </code></pre>
  <p>I've tried it in different ways and can't figure out how to do it. In my opinion, what the for returns me is a string. And I tried with the iteritems option but I can't either. If someone can help me with the problem I would appreciate it.</p>