DevOps / Ansible Interview questions
How do you troubleshoot slow fact gathering in Ansible?
- Time the gather_facts step specifically using
-vvvor the profile_tasks callback to confirm it's actually the bottleneck versus other tasks. - Disable gathering for plays that don't need facts (
gather_facts: false), which is often the single biggest win if facts aren't actually used. - Narrow gathered subsets with
gather_subsetto skip expensive categories (like all network interfaces) when only a few specific facts are needed. - Enable fact caching so repeated runs within the cache's expiration window skip live gathering entirely and reuse the last known values.
- Check for slow or high-latency hosts specifically - a handful of consistently slow hosts (not the whole inventory) often points to a host-level issue, like DNS resolution delays during setup, rather than an Ansible-wide problem.
- hosts: all gather_facts: true vars: ansible_facts_modules: setup tasks: - name: Only gather what's needed ansible.builtin.setup: gather_subset: - network
Fact gathering is one of the more overlooked sources of playbook slowness precisely because it's implicit - it's worth explicitly timing it before assuming a slow run is due to the playbook's own task logic.
More Related questions...