How to set ansible’s gather_subset per host

ansible

We can use gather_subset at play level.
Is it possible to use it on a per host level? Like putting it in a host_vars file?
My quick testing on 2.2.1.0 did not work out.

My problem at hand: I have a host, for which get_cpu_facts fails. And really, I never need hardware facts for this host, so I would like to put "!hardware" in its gather_subset.

Best Answer

AFAIK you can't set gather_subset per host if you use automatic fact gathering at play start.

But you can disable automatic fact gathering and call setup manually with required parameters (which can be supplied from host vars):

---
- hosts: all
  gather_facts: no
  pre_tasks:
    - setup:
        gather_subset: "{{ gather_subset | default(omit) }}"