title: Ansible: How to filter dict2items and run playbook only for the matched values
body: <p>I have a dict playbook which looks like this:</p>
  <pre><code>  x_php_versions_installed:
        ea-php71:
          - ea-php71-php-bcmath
          - ea-php71-php-xmlrpc
          - ea-php71-php-zip
          - pecl-memcached
          - pecl-imagick
        ea-php72:
          - ea-php72-php-cli
          - ea-php72-php-common
          - ea-php72-php-curl
          - pecl-imagick
  </code></pre>
  <p>I would like to filter them, to write me each item.value which contains 'ea' string but not everything else. My task looks like this:</p>
  <pre><code>- name: Write out only the ea packages
    debug:
      msg: '{{ item.value }}'
    when: item.value | selectattr(item.value, 'contains', 'ea')
    loop: '{{ x_php_versions_installed | dict2items }}
  </code></pre>
  <p>But it does not work, because it will list all of the packages, not only the ea ones. The expected answer should look like this:</p>
  <pre><code>...
  &quot;msg&quot;: [
      &quot;ea-php71-php-bcmath&quot;,
      &quot;ea-php71-php-xmlrpc&quot;,
      &quot;ea-php71-php-zip&quot;
  ]
  ...
  &quot;msg&quot;: [
      &quot;ea-php72-php-cli&quot;,
      &quot;ea-php72-php-common&quot;,
      &quot;ea-php72-php-curl&quot;
  ]
  ...
  </code></pre>
  <p>Another possibility is to filter out the 'pecl' string, it will gave me the same result and it also works fine.</p>