title: Extract nested dict value with conditions from JSON using JINJA2 in Ansible
body: <p>I'm trying to extract the CDN domain name for a specific Alias from Ansible's <code>cloudfront_facts</code>, with the following (summarized) output:</p>
  
  <pre><code>{
    "cdn_facts": {
     "ansible_facts": {
      "cloudfront": {
        "summary": {
         "distributions": [
          {
            "Aliases": [
             "media.example.com"
            ],
            "DomainName": "a1b2c3d4e5f6g.cloudfront.net"
          },
          {
            "Aliases": [
             "example.com"
            ],
            "DomainName": "g7f6e5d4c3b2a.cloudfront.net"
          }
        ]
       }
      }
    }
  }
  </code></pre>
  
  <p>In other words, for the Alias <code>example.com</code> I'd like to set a fact with the value of <code>g7f6e5d4c3b2a.cloudfront.net</code>.</p>
  
  <p>I've tried the following to try and print out the value, but it's simply producing an empty list.</p>
  
  <pre><code>- debug:
      msg: "{{ cdn_facts.ansible_facts.cloudfront.summary.distributions | selectattr('Aliases[0]', 'equalto', 'example.com') | map(attribute='DomainName') | list }}"
  </code></pre>
  
  <p>I'm at a loss on how to even debug this, as <code>cdn_facts.ansible_facts.cloudfront.summary.distributions</code> produces an array of dicts, but <code>selectattr</code> and <code>map</code> are not producing anything.</p>