---
- hosts: all
  
  vars:
    timeout_retries: 2  # number or poll tries
    timeout_delay: 10   # delay between polls
    email_list: "[email protected]"

  tasks:

  - name: laucnhing long task
    shell: "/bin/sleep 30; echo trololo"
    async: 60000
    poll: 0
    register: long_task

  - name: check timeout
    async_status: jid={{ long_task.ansible_job_id }}
    register: job_result
    until: job_result.finished
    retries: "{{ timeout_retries }}"
    delay: "{{ timeout_delay }}"
    ignore_errors: yes

  # warning mail
  - local_action: mail
        host="localhost" port=25
        from="adba@{{ ansible_hostname }}"
        to="{{ email_list }}"
        subject='WARNING "{{ inventory_hostname }}" long running task'
        body="{{ job_result }}"
    when: job_result.attempts >= {{ timeout_retries }}
  
  - name: wait for task to finish
    async_status: jid={{ long_task.ansible_job_id }}
    register: job_result
    until: job_result.finished

  - name: check status
    debug: var=job_result

  # failed mail
  - local_action: mail
        host="localhost" port=25
        from="adba@{{ ansible_hostname }}"
        to="{{ email_list }}"
        subject='FAILED "{{ inventory_hostname }}" long running task'
        body="{{ job_result }}"
    when: job_result.rc != 0

  # ok mail
  - local_action: mail
        host="localhost" port=25
        from="adba@{{ ansible_hostname }}"
        to="{{ email_list }}"
        subject='SUCCESFUL "{{ inventory_hostname }}" long running task'
        body="{{ job_result }}"
    when: job_result.rc = 0

Above what i have now.
It looks ugly (at best).
Any suggestions?
Probably OK/Failed should be done via callback plugin (does one exists 
already for that?)

On Saturday, November 14, 2015 at 2:22:16 AM UTC+3, Brian Coca wrote:
>
> you can set a subsequent task to poll for it and have that use 
> until/retry up to that limit, then register a result, next task can 
> conditionally mail depending on that result 
>
> -- 
> Brian Coca 
>

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/ff267a46-0ff1-466f-8baa-43e6159396c9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to