O'Reilly logo

Learning Ansible 2 - Second Edition by Fabio Alessandro Locati

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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; ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required