DevOps / Ansible Interview questions
How can you optimize role design to avoid duplicate work at scale?
- Use run_once for cluster-wide actions - a task that only needs to happen once across the whole play (like registering a load balancer entry) shouldn't repeat per host.
- Cache expensive lookups - if a role queries an external API or database for shared data, fetch it once (e.g. via
delegate_toon a single host, orrun_once) and share the result via a fact or registered variable, rather than every host repeating the same external call. - Structure role dependencies carefully in meta/main.yml - without care, the same dependency role can run multiple times if several roles in a play each declare it as a dependency; set
allow_duplicates: falsewhere repetition isn't needed. - Use group_vars/host_vars instead of per-role redundant variable definitions so shared configuration isn't copy-pasted into every role that needs it.
- Leverage fact caching so roles across many plays in the same run (or repeated runs) aren't each triggering their own full fact gathering pass.
The common thread is identifying work that's logically "once per play/run" rather than "once per host" and making that explicit with the right directive, instead of letting Ansible's default per-host execution model repeat genuinely shared work unnecessarily across every target.
Invest now in Acorns!!! 🚀
Join Acorns and get your $5 bonus!
Acorns is a micro-investing app that automatically invests your "spare change" from daily purchases into diversified, expert-built portfolios of ETFs. It is designed for beginners, allowing you to start investing with as little as $5. The service automates saving and investing. Disclosure: I may receive a referral bonus.
Invest now!!! Get Free equity stock (US, UK only)!
Use Robinhood app to invest in stocks. It is safe and secure. Use the Referral link to claim your free stock when you sign up!.
The Robinhood app makes it easy to trade stocks, crypto and more.
Webull! Receive free stock by signing up using the link: Webull signup.
More Related questions...
