How to use multiple filter in setup module

I want to extract only specific information of the systems using Ansible setup module , like ansible_memtotal_mb , ansible_machine and ansible_distribution_version . How to do that in single ansible command ?

Regards
Vikrant

It's possible to 'loop' the 'filter' in the module 'setup'
https://docs.ansible.com/ansible/latest/modules/setup_module.html

For example:

  - hosts: test_01
    gather_facts: false
    tasks:
      - setup:
          filter: "{{ item }}"
        loop:
          - 'ansible_memtotal_mb'
          - 'ansible_machine'
          - 'ansible_distribution_version'
      - debug:
          var: hostvars.test_01.ansible_facts

gives

  ok: [test_01] =>
    hostvars.test_01.ansible_facts:
      distribution_version: '12.0'
      machine: i386
      memtotal_mb: 3400

It's not possible to create single 'filter' because of the limited
functionality of 'fnmatch', I think
https://docs.python.org/3.8/library/fnmatch.html

HTH,

  -vlado

FWIW. Smarter approach to avoid the burden of collecting the facts on each
play is 'Caching facts'
https://docs.ansible.com/ansible/latest/user_guide/playbooks_variables.html#caching-facts

HTH,

  -vlado

FYI, filter does not prevent gathering of other facts, it just filters
the result, running in loop gathers facts multiple times, it is much
more efficient to gather 1 time and then extract the subset you
desire.