Interview Prep/Ansible/Variables, Facts and Precedence Problems

`'ansible_mounts' is undefined` after a "speed up facts" change

IntermediateTroubleshootingVariables, Facts and Precedence Problems
Answer

Likely causes → gather_subset was reduced (for example to ['!all', 'min'] or ['!hardware']), and mounts, memory and devices are part of the hardware subset.

Diagnose → ansible web01 -m setup -a 'gather_subset=!all,min' | grep -c mounts returns 0.

Fix → Add back what the play needs:

gather_facts: true
gather_subset: [min, hardware]

Or call ansible.builtin.setup with that subset right before the task that needs it.

Prevent → Document which facts each role relies on, and test roles with the same gather_subset that production uses.

All Ansible questions Roadmap: Ansible

More on Variables, Facts and Precedence Problems