title: Fetch the value based on a particular string in Ansible
body: <p>I would like to fetch the value based on the keyword mentioned in the rules yaml file. If the keyword in rules.yaml is mentioned as <strong>OBJ</strong>, it should fetch the value of po_id matching with the same subnet in input &amp; rules yaml file and if the keyword is <strong>GRP</strong>, then it should fetch the value of pog_id matchign with the same subnet in input &amp; rules yaml file. Expected result as shown below.</p>
  <p><strong>Input.yml</strong></p>
  <pre><code>[
      {
          
          &quot;po_id&quot;: &quot;11155588779966&quot;,
          &quot;pog_id&quot;: &quot;1115558871321649&quot;,
          &quot;subnetname&quot;: &quot;DNS&quot;,
          &quot;netname&quot;: &quot;Test1&quot;
      },
      {  
          &quot;po_id&quot;: &quot;99996688778855&quot;,
          &quot;pog_id&quot;: &quot;1115558812345&quot;,
          &quot;subnetname&quot;: &quot;NTP&quot;,
          &quot;netname&quot;: &quot;Test2&quot;
      },
      {
          &quot;po_id&quot;: &quot;123456789101112&quot;,
          &quot;pog_id&quot;: &quot;111555880321624&quot;,
          &quot;subnetname&quot;: &quot;NET&quot;,
          &quot;netname&quot;: &quot;Test3&quot;  
      }
  ]
  </code></pre>
  <p><strong>rules.yml</strong></p>
  <pre><code>rules:
           -    rule number: &quot;1&quot; 
                destCidr: &quot;OBJ({{DNS}}) , 10.22.22.0/24&quot;
                    
  
           -    rule number: &quot;2&quot;
                destCidr: &quot;OBJ({{ NTP }}) , 10.33.33.0/24&quot;
                
  
           -    rule number: &quot;3&quot;
                destCidr: &quot;OBJ({{ NET }}), GRP({{ NTP }}) , 10.33.33.0/24&quot;
  </code></pre>
  <p><strong>Expected Output</strong></p>
  <pre><code>[
      {
          &quot;rule number&quot;: &quot;1&quot;,
          &quot;destCidr&quot;: &quot;OBJ(11155588779966), 10.22.22.0/24 &quot;
      },
      {
          &quot;rule number&quot;: &quot;2&quot;,
          &quot;destCidr&quot;: &quot;OBJ(99996688778855), 10.33.33.0/24&quot;
      },
      {    
          &quot;rule number&quot;: &quot;3&quot;,
          &quot;destCidr&quot;: &quot;OBJ(123456789101112), GRP(1115558812345), 10.33.33.0/24 &quot;
      }
  ]
  </code></pre>