⚡ ~/naveed Interview Prep
⚡ Portfolio Home ✍️ Engineering Blog Deep Dives 🎯 Interview Hub 1,000+ Scenarios ☸️ Kubernetes Mastery Hub 24 Modules 🎮 DevOps Arcade & Quizzes Subnet Blitz ⚡ 🗺️ DevOps Roadmaps PDFs & Guides 🤖 Morpheus Analysis AI Quant ↗ 🛠️ Developer Tools Utilities 🧪 Labs & Experiments 📄 Interactive CV & Certs 🔗 All Links & Socials ⚡ Join The Dispatch (Weekly SRE Newsletter) →
← Back to All Ansible Automation Interview Questions Scenario 11 of 15 in Ansible Automation
Senior DevOps / SRE [L2] Ansible Performance Optimization Performance Tuning [L2]
🎯 Target Role / Context: Senior DevOps / SRE Scenario #11 · Performance Engineering

Q: Ansible playbook runs take over 15 minutes across a fleet of 800 servers, with 70% of execution time spent during fact-gathering. How do you optimize fact gathering and caching?

Fact gathering against large fleets creates severe network and CPU bottlenecks. Optimize by disabling facts when not needed, filtering specific facts, or implementing persistent fact caching with Redis or JSON backends.

#Ansible #Fact Gathering #Performance #Redis #Fact Caching
🎙️ Candidate Opening & Architectural Context
""Gathering facts executes the setup module across every host, returning hundreds of kilobytes of JSON per node. At scale across 500+ nodes, this consumes massive network bandwidth and controller CPU time. I optimize this by disabling unnecessary fact steps, pruning gathering subsets, or enabling Redis fact caching.""
Advertisement
⚡ Recommended Practice Lab

Want to master this scenario in a live sandbox? KodeKloud's CKA & CKAD Hands-On Certification Track covers this exact problem with hands-on terminal drills.

🛠️ Production Runbook & Step-by-Step Resolution

1️⃣

Disable Facts When Not Required

Most deployment playbooks only deploy pre-built packages and configurations, requiring zero host facts. Turn off fact gathering globally in the play:

  • gather_facts: false at the top of your play.
  • Saves 100% of the fact collection phase, reducing start times from minutes to seconds.
2️⃣

Gather Only Specific Fact Subsets

If your play only needs networking or OS family information, prune the gathering scope using gather_subset:

  • gather_subset: ['!all', '!min', 'network']
  • Avoids expensive disk partition, hardware, and virtual memory scans across large fleets.
Advertisement
3️⃣

Implement Centralized Fact Caching (Redis/JSON)

Cache gathered facts persistently on the controller or in Redis so subsequent runs bypass the setup module entirely:

  • In ansible.cfg, configure Redis caching:
    gathering = smart
    fact_caching = redis
    fact_caching_timeout = 86400
    fact_caching_connection = localhost:6379:0
  • With gathering = smart, Ansible only collects facts if the cache has expired or host is new.
💡 The Senior SRE Gold Nugget (Key Architectural Takeaway)
"Fact collection across 500+ hosts is a major performance bottleneck. Disable facts when not needed (gather_facts: false), restrict scopes with gather_subset, or enable smart fact caching with Redis to cut execution times by over 80%."
⚡ 60-Second Elevator Pitch Talking Points
  • The default setup module collects hundreds of facts per host, creating severe network bottlenecks on 500+ node fleets.
  • Set 'gather_facts: false' for standard application deployments that do not evaluate host conditions.
  • Use 'gather_subset: ["!all", "network"]' to collect only the specific facts your templates require.
  • Enable 'gathering = smart' in ansible.cfg to automatically skip fact gathering if facts are already cached.
  • Implement high-performance fact caching using Redis ('fact_caching = redis') with a 24-hour TTL.
  • For simple controllers, use file-based JSON caching ('fact_caching = jsonfile') stored in /tmp/ansible_facts.
⛔ Critical Candidate Mistakes to Avoid in This Scenario

Senior hiring managers and bar raisers evaluate how you prioritize during outages. Avoid these common anti-patterns:

  1. Leaving gather_facts: true enabled on every single play in a multi-tier playbook Repeats the expensive 500-node fact collection phase multiple times during a single playbook run.
  2. Setting fact_caching_timeout to 0 or infinite without TTL expiration Stale cached facts cause playbooks to evaluate outdated IP addresses and memory stats long after hardware changes.
  3. Failing to secure the Redis fact caching backend Redis stores complete system metadata and environment variables; expose it only on localhost or over TLS.
Advertisement
Want more Ansible Automation scenarios?
Explore our complete collection of scenario-based Ansible Automation interview runbooks.
Browse All Ansible Automation Questions →