I am currently optimizing our automation workflows for a massive cloud migration project. Every time I run a playbook, Ansible automatically executes the "setup" module to gather host variables, which is significantly slowing down our deployment cycles since we don't actually need those system details for these specific tasks. Is there a global setting or a playbook-level parameter I can toggle to turn off gathering facts by default and save on execution time?
3 answers
To disable fact gathering at the playbook level, you simply need to add gather_facts: False (or no) at the same level as your hosts: declaration. This prevents the implicit execution of the setup module, which can shave off several seconds per host, especially in environments with high latency or a large number of managed nodes. If you find that you need to disable this globally across your entire infrastructure, you can modify your ansible.cfg file by setting gathering = explicit. This change ensures that facts are only collected if you specifically ask for them in a play, which is a best practice for performance-driven CI/CD pipelines.
That is a solid optimization move! Are you planning to use any conditional logic later in your play that might rely on discovered variables like ansible_distribution or ansible_eth0, or is this strictly a task-based execution where system architecture doesn't matter?
You just need to set gather_facts: no in your YAML file. It is the quickest way to stop the "GATHERING FACTS" header from appearing during your run.
I agree with Susan. It’s a very straightforward fix. As Heather mentioned in the original post, when you're managing hundreds of instances in Cloud Technology environments, disabling this is often the first step in performance tuning.
Thomas, we are strictly executing pre-defined shell scripts and moving binaries, so the underlying OS distribution data isn't required for our logic. However, if I turn it off now, can I still manually trigger fact gathering halfway through a play if a specific task suddenly requires a variable like the IP address? I want to make sure I'm not locking myself out of that data entirely if the requirements change mid-deployment.