cbrdy
cbrdy

Reputation: 822

Skip ansible progress task if dependent step is skipped

I would like to skip ansible progress task below if the dependent task is skipped ? How would I achieve it ?

- name: long running shell
  shell:
    cmd: '/opt/apps/long_running_script.sh'
  async: 1000
  poll: 0
  when:
    verify.rc != 0
  register: check_status

- name: Check on long running step
  async_status:
    jid: "{{ check_status.ansible_job_id }}"
  register: job_result
  until: job_result.finished
  retries: 90
  delay: 10

I tried using when: check_status is finished but seeing the error when the first task is skipped.

Upvotes: 3

Views: 3256

Answers (1)

Moon
Moon

Reputation: 3047

When a task is skipped, the resultant variable will have a property name skipped with value true so you should be able to write logic like below.

when: check_status.skipped | default(false)

The default will be needed because for the regular flow (not skipped) skipped property will not be available in check_status.

or,

when: check_status.skipped is defined and check_status.skipped

even simpler as @β.εηοιτ.βε commented,

when: check_status is skipped

Upvotes: 5

Related Questions