title: Ansible dynamic inventory GCP filter flattened
body: <p>As mentioned in <a href="https://docs.ansible.com/ansible/latest/collections/google/cloud/gcp_compute_instance_info_module.html" rel="nofollow noreferrer">parameter/filters</a>, that also points out <a href="https://cloud.google.com/sdk/gcloud/reference/topic/filters" rel="nofollow noreferrer">this link</a></p>
  <blockquote>
  <p>By default the filter expression operates on root level resources. In order to filter on a nested list(not at the root level of the json) , one can use the <code>--flatten</code> flag to provide a the <code>resource-key</code> to list. For example, To list members under <code>my-project</code> that have an editor role, one can run:</p>
  <pre class="lang-sh prettyprint-override"><code>gcloud projects get-iam-policy cloudsdktest --flatten=bindings --filter=bindings.role:roles/editor --format='value(bindings.members)'
  </code></pre>
  </blockquote>
  <p>I'm trying to filter out only hosts that have size 50 (<code>diskSizeGb: &quot;50&quot;</code>) using dynamic inventory filter only.</p>
  <p>Could someone point out how to use flatten tag with Ansible dynamic inventory since I cannot access nested values when running the following (I'm not even sure if that's possible):</p>
  <pre class="lang-sh prettyprint-override"><code>ansible-inventory -i name.gcp.yml --list
  </code></pre>
  <p>This is an example output of what I want my filter to be based on:</p>
  <pre class="lang-none prettyprint-override"><code>&quot;disks&quot;: [
      {
          &quot;boot&quot;: true,
          &quot;deviceName&quot;: &quot;somename&quot;,
          &quot;diskSizeGb&quot;: &quot;50&quot;,
      }
  ],
  </code></pre>
  <p>These are the filters I have tried but I'm getting Invalid list filter expression as a warning and I'm not getting the expected result:</p>
  <pre class="lang-yaml prettyprint-override"><code>filters: (name eq hostname) (disks[0].diskSizeGb eq '50')
  
  filters: [name=hostname AND disks[0].diskSizeGb=50]
  </code></pre>