Managing exceptions
There are many cases, where for one reason or another, you want your playbook and roles to carry on in the case one or more tasks fail. A typical example of this could be that you want to check if software is installed or not. Let's see the following example to install Java. In the roles/java/tasks/main.ymal
file, we are going to put the following code:
- name: Verify if the current version of Java is installed command: rpm -q jdk1.8.0_91-1.8.0_91-fcs register: java ignore_errors: True changed_when: java|failed - name: Ensure that JavaSE is download uri: url: 'http://download.oracle.com/otn-pub/java/jdk/8u91-b14/jdk-8u91-linux-x64.rpm' method: GET HEADER_Cookie: 'gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; ...
Get Learning Ansible 2 - Second Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.