title: How to compare or lookup specific values from two lists in ansible and print
body: <p>How to compare two lists in ansible and print desired output below, i have looked other posts in stackoverflow regarding comparing/lookup list , but the way i want desired output is a bit different, unable to figure out the logic to get this working. Please point me to any post that can help me.Thanks</p>
  <p>List1:</p>
  <pre><code>[
      {
          &quot;DES&quot;: &quot;server1&quot;,
          &quot;PORT&quot;: &quot;E46&quot;,
      },
      {
          &quot;DESCRIP&quot;: &quot;server2&quot;,
          &quot;PORT&quot;: &quot;E47&quot;,
      },
      {
          &quot;DESCRIP&quot;: &quot;server3&quot;,
          &quot;PORT&quot;: &quot;E4&quot;,
      },
      {
          &quot;DESCRIP&quot;: &quot;server4&quot;,
          &quot;PORT&quot;: &quot;E7&quot;,
      }
  ]
  </code></pre>
  <p>List2:</p>
  <pre><code>[
          {
              &quot;INTERFACES&quot;: [
                  &quot;E6&quot;,
                  &quot;E8&quot;,
                  &quot;E9&quot;,
                  &quot;E10&quot;,
                  &quot;E11&quot;,
                  &quot;E12&quot;,
                  &quot;E13&quot;,
                  &quot;E14&quot;,
                  &quot;E27&quot;,
                  &quot;E28&quot;,
                  &quot;E37&quot;,
                  &quot;E43&quot;,
                  &quot;E44&quot;,
                  &quot;E45&quot;,
                  &quot;E46&quot;,
                  &quot;E47&quot;
              ],
              &quot;VLAN_ID&quot;: &quot;17&quot;
          },
          {
              &quot;INTERFACES&quot;: [
                  &quot;E7&quot;,
                  &quot;E10&quot;,
                  &quot;E11&quot;,
                  &quot;E12&quot;,
                  &quot;E13&quot;,
                  &quot;E14&quot;,
                  &quot;E27&quot;,
                  &quot;E28&quot;,
                  &quot;E45&quot;,
                  &quot;E46&quot;
              ],
              &quot;VLAN_ID&quot;: &quot;16&quot;
          }
      ]
  </code></pre>
  <p>desired output:</p>
  <p>If list1 <code>PORT</code> value matches/present in list2 <code>INTERFACES</code> then print something like this: <code>server1 E46 has: VLAN_ID: 17 ; VLAN_ID: 16</code> or <code>server2 E47 has: VLAN_ID: 17 ; NO VLAN_ID: 16</code></p>
  <p>If list1 <code>PORT</code> value dosen't matches/present in list2 <code>INTERFACES</code> then print something like <code>server3 E4 has NO VLAN_ID: 17 NO VLAN_ID: 16</code></p>
  <p>below is full desired print:</p>
  <pre><code>server1 E46 has: VLAN_ID: 17 ; VLAN_ID: 16
  server2 E47 has: VLAN_ID: 17 ; NO VLAN_ID: 16
  server3 E4 has: NO VLAN_ID: 17 ; NO VLAN_ID: 16
  server4 E7 has: VLAN_ID: 16 ; NO VLAN_ID: 17
  </code></pre>