Ansible - Exception

> Infrastructure as code > Ansible

1 - About

2 - Possibilities

2.1 - Block

tasks:
- name: Handle the error
  block:
    - debug:
        msg: 'I execute normally'
    - name: i force a failure
      command: /bin/false
    - debug:
        msg: 'I never execute, due to the above task failing, :-('
  rescue:
    - debug:
        msg: 'I caught an error, can do stuff here to fix it, :-)'

doc

Advertising

2.2 - Ignore error

The error will not be counted as a failure.

  - name: 'Check network connectivity to ldap ({{ ldap_host }})'
    wait_for:
      host: '{{ ldap_host }}'
      port: "{{ item }}"
      state: started         # Port should be open
      delay: 0               # No wait before first check (sec)
      timeout: 3             # Stop checking after timeout (sec)
    ignore_errors: yes
    with_items:
    - '{{ ldap_port }}'
infra/ansible/exception.txt · Last modified: 2019/09/10 14:16 by gerardnico