DevOps / Ansible Interview questions
What happens when a task fails in an Ansible playbook?
By default, when a task fails on a given host, Ansible immediately stops running further tasks against that specific host for the remainder of the play, while continuing normally on any other hosts that haven't failed. The host is marked as failed and, unless later corrected, is excluded from any remaining tasks in that play.
- name: A task that might fail but shouldn't stop the play ansible.builtin.command: /opt/scripts/check.sh ignore_errors: true - name: Custom failure condition ansible.builtin.command: /opt/scripts/deploy.sh register: result failed_when: "'ERROR' in result.stdout"
ignore_errors: true lets the play continue on that host even after a failure, while failed_when lets you redefine what "failure" even means for a task, useful when a script's exit code doesn't perfectly line up with success/failure. Failed hosts are recorded in a .retry file by default, which can be fed back into --limit @site.retry to re-run the playbook only against the hosts that failed last time, rather than the whole inventory.
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...
