Interview Prep/Ansible/Variables, Facts and Precedence

How do you gather only some facts to save time?

IntermediateConceptVariables, Facts and Precedence
Answer

Use gather_subset to include or exclude categories, or filter to select keys.

- hosts: all
  gather_facts: true
  gather_subset:
    - "!hardware"
    - "!all"
    - network

min is always collected. Hardware facts (disks, DMI) are the slowest on big hosts. You can also run ansible.builtin.setup with gather_subset: min as a task and only gather more if needed.

All Ansible questions Roadmap: Ansible

More on Variables, Facts and Precedence