LOGBOOK

HELP

Quiz Entry - updated: 2026.11.05

How do you gather only some facts, or all except some, and why must !hardware be quoted?

Pass gather_subset to ansible.builtin.setup: - hardware collects only hardware facts, - "!hardware" collects everything except them. The quotes are needed because in YAML an unquoted value can't start with ! (it marks a YAML tag).

- name: Collect only hardware facts
  ansible.builtin.setup:
    gather_subset:
      - hardware

- name: Collect all facts except for hardware facts
  ansible.builtin.setup:
    gather_subset:
      - "!hardware"

Hardware facts (devices, partitions, memory) are among the slowest to collect, so excluding them is a common speed-up when a play only needs, say, the OS and network facts. Other subsets include network, virtual and min (a minimal core set). The same setting can also be given at play level as gather_subset: next to gather_facts.

The quoting rule is the same YAML lesson as for {{: certain characters at the start of an unquoted value mean something to the YAML parser ({ a dictionary, [ a list, ! a tag, * an alias). When a value starts with one of them, quote it.

Go deeper:

From Quiz: ITIA / Ansible Variables, Secrets and Facts | Updated: Nov 05, 2026