# Can we use both filter and gather\_subset in the setup module at a time?

**URL:** <https://forum.ansible.com/t/can-we-use-both-filter-and-gather-subset-in-the-setup-module-at-a-time/6638>\
**Category:** Get Help\
**Tags:** ansible\
**Created:** [June 18, 2024, 3:26pm UTC](https://forum.ansible.com/t/can-we-use-both-filter-and-gather-subset-in-the-setup-module-at-a-time/6638 "2024-06-18T15:26:44Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mukesh1328](https://avatars.discourse-cdn.com/v4/letter/m/258eb7/32.png) [@Mukesh1328](https://forum.ansible.com/u/Mukesh1328)\
**Post date:** [June 18, 2024, 3:26pm UTC](https://forum.ansible.com/t/can-we-use-both-filter-and-gather-subset-in-the-setup-module-at-a-time/6638/1 "2024-06-18T15:26:45Z")

</div>

\*\*Can we use both filter and gather\_subset in the setup module at a time? \*\*.

```auto
- name: Check CPU and Memory
   hosts: all
   gather_facts: false
   tasks:
    - setup:
       filter: ansible_*_mb
       gather_subset:
            - processor_count

    - debug:
        msg:
         - "{{ ansible_processor_vcpus }}"
         - "{{ ansible_memtotal_mb }}"

```

---

<div class="post-metadata">

**Author:** ![sivel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sivel/32/1198_2.png) [@sivel](https://forum.ansible.com/u/sivel)\
**Post date:** [June 18, 2024, 3:29pm UTC](https://forum.ansible.com/t/can-we-use-both-filter-and-gather-subset-in-the-setup-module-at-a-time/6638/2 "2024-06-18T15:29:44Z")

</div>

Yes, but your example would produce nothing I assume. You are only gathering data about processor count, and then filtering on that to only include information about memory.

EDIT: To clarify, subsets restrict what data is gathered from the system, filtering filters the gathered information down to specific keys. Filters do not impact what data is gathered, only what is ultimately returned after gathering.

---

<div class="post-metadata">

**Author:** ![Mukesh1328](https://avatars.discourse-cdn.com/v4/letter/m/258eb7/32.png) [@Mukesh1328](https://forum.ansible.com/u/Mukesh1328)\
**Post date:** [June 19, 2024, 2:53am UTC](https://forum.ansible.com/t/can-we-use-both-filter-and-gather-subset-in-the-setup-module-at-a-time/6638/3 "2024-06-19T02:53:36Z")

</div>

I want to get the managed node CPU info and Memory info, from the above example debug is only printing either of the “{{ ansible\_processor\_vcpus }}” or “{{ ansible\_memtotal\_mb }}” but not both.

---

<div class="post-metadata">

**Author:** ![chris](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/chris/32/293_2.png) [@chris](https://forum.ansible.com/u/chris)\
**Post date:** [June 19, 2024, 7:59am UTC](https://forum.ansible.com/t/can-we-use-both-filter-and-gather-subset-in-the-setup-module-at-a-time/6638/4 "2024-06-19T07:59:27Z")

</div>

Try this?

```yaml
- name: Check CPU and Memory
  hosts: all
  gather_facts: false
  tasks:

    - name: Gather hardware facts
      setup:
        gather_subset:
          - hardware

    - name: Debug processors and memory
      ansible.builtin.debug:
        msg:
         - "CPUs: {{ ansible_processor_vcpus }}"
         - "Memory: {{ ansible_memtotal_mb }}"

```
