Ansible - Exception

Card Puncher Data Processing

About

Grammar - Error (Handling) and Code - Exception (Try, Catch, Finally statement) in Ansible

Possibilities

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, :-)'
  always:
    - name: Run always (clean, ...)
      file:
        path: /tmp/install.yaml
        state: absent

doc

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 }}'





Discover More
Card Puncher Data Processing
Ansible - Error Handling

See



Share this page:
Follow us:
Task Runner