Interview Prep/Ansible/Playbooks, Plays, Tasks and Handlers

What does `gather_facts: false` do and when do you use it?

IntermediateConceptPlaybooks, Plays, Tasks and Handlers
Answer

It skips the implicit setup task at the beginning of the play, saving several seconds per host. Use it when the play does not need facts: localhost API plays, simple restarts, or bootstrap plays before Python exists.

- hosts: all
  gather_facts: false
  tasks:
    - ansible.builtin.setup:
        gather_subset: [min, network]

A play can gather a subset later. If you rely on ansible_facts while facts are off, the variable is undefined and the template fails.

All Ansible questions Roadmap: Ansible

More on Playbooks, Plays, Tasks and Handlers