Posts

Showing posts with the label Ansible Error Handling

Ansible Error Handling and Fail Handling

Image
Hello everyone!! In this post I would like to experiment with the failure handling with block-rescue-always block in a Ansible tasks in playbook.  Prerequisites * Ansible installed and their must be Target nodes * Basic understanding of any programming language that uses try- catch blocks Ansible stops playbook execution on a task failure and we can choose to ignore that using 'ignore_errors' to continue with remaining tasks. (in Python we have 'pass' similar to that). If you have couple of tasks in a playbook, when first task fails Ansible stops there. But if you want to execute the next tasks even though your first task failed. --- # File name: ignore_err.yml - name: check ignore errors hosts: localhost gather_facts: false tasks: - block: - command: "ls ~/" - command: "ls ~/bin" - command: "ls /etc/hosts" become_user: root become: yes ignore_errors: yes No...