Ansible - Task Status

Card Puncher Data Processing

About

Article about the task status

Example

register variable structure

A variable that is registered to give the result of the task would have the following structure.

"registered_variable_name": {
	"changed": false,
	"skip_reason": "Conditional result was False",
	"skipped": true
}

Modify the status condition

With changed_when and failed_when

- name: Testing the JDBC connectivity
  command: "{{ sqlline_home }}/sqlline -u 'jdbc:sqlserver://{{ infa_db_endpoint }}:{{ infa_db_port }};databaseName={{ infa_domain_db_name }}' -n '{{ infa_db_user }}' -p '{{ infa_db_password }}' -e 'select 1'"
  register: jdbc_test_result
  changed_when: "jdbc_test_result.rc != 0"
  failed_when: "jdbc_test_result.rc != 0"

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

Conditional Task

Doc

tasks:

  - shell: /usr/bin/foo
    register: result
    ignore_errors: True

  - debug:
      msg: "it failed"
    when: result is failed

  # in most cases you'll want a handler, but if you want to do something right now, this is nice
  - debug:
      msg: "it changed"
    when: result is changed

  - debug:
      msg: "it succeeded in Ansible >= 2.1"
    when: result is succeeded

  - debug:
      msg: "it succeeded"
    when: result is success

  - debug:
      msg: "it was skipped"
    when: result is skipped

where: What are Handlers in Ansible? And how to use them with examples.

Documentation / Reference





Discover More
Card Puncher Data Processing
Ansible - Exception

and in Ansible rescue of a block doc The error will not be counted as a failure.
Card Puncher Data Processing
Ansible PlayBook - Task

A task is a call to an ansible module with arguments located in a play list. Variables can be used in arguments to modules. Tasks are executed top to bottom one at a time, against matched by the...



Share this page:
Follow us:
Task Runner