DevOps / Ansible Interview questions
How does Ansible ensure idempotency in playbook runs?
Idempotency in Ansible comes from module design, not from the playbook or engine automatically detecting "nothing to do." Each module is written to first check the current state of the target (a file's contents, whether a package is installed, a service's running state) and only performs an action if that state doesn't already match what was requested.
- name: Ensure nginx is installed ansible.builtin.package: name: nginx state: present # module checks first: is it already installed?
If the desired state is already true, the module reports ok (no change); if it had to act, it reports changed. This is why re-running the exact same playbook against a system already in the desired state produces no changes the second time. Idempotency depends on the module author having implemented this check correctly - a poorly written custom module or a raw shell command run via shell/command won't automatically be idempotent unless the playbook author adds explicit conditions (like creates: or a when guard) to replicate that check-before-act behavior.
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...
