ansible/ansible — pull request #274 by jhoekx (2012-04-29 16:20:49+00:00)
Title: Improve async output, refactor async code

This improves async output in playbooks and in `ansible`. Async operations are now pleasant and straightforward to use from script (#254 ).

If playbooks and cli should diverge in the future, it's granular enough to allow this (both in callbacks and the polling code).

It's mostly additions in `runner.py` and `callback.py`, but a lot of code was removed from `playbook.py` and `/bin/ansible` for a moderate overall reduction.

Any existing script using the old way of async operations should still work, since that was left untouched.

Playbook example:

```
(ansible)[jeroen@firefly work]$ ansible-playbook ../rh6clu/playbooks/sleep.yml

PLAY [oracle] ****************************

SETUP PHASE ****************************

ok: [rh6oranode1]

ok: [rh6oranode2]

TASK: [command /root/longrun.sh] *********

ok: [rh6oranode1] => async_wrapper /root/longrun.sh

ok: [rh6oranode2] => async_wrapper /root/longrun.sh

polling on rh6oranode2, 28 remaining
polling on rh6oranode1, 28 remaining
polling on rh6oranode2, 26 remaining
polling on rh6oranode1, 26 remaining
finished on rh6oranode1
polling on rh6oranode2, 24 remaining
finished on rh6oranode2

PLAY RECAP **********************

rh6oranode1 : ok= 3 changed= 1 unreachable= 0 failed= 0
rh6oranode2 : ok= 3 changed= 1 unreachable= 0 failed= 0
```

If it times out:

```
polling on rh6oranode2, 10 remaining
polling on rh6oranode2, 8 remaining
polling on rh6oranode2, 6 remaining
polling on rh6oranode2, 4 remaining
polling on rh6oranode2, 2 remaining
polling on rh6oranode2, 0 remaining
failed: [rh6oranode2] => {"failed": 1, "msg": "timed out", "rc": null}
```

Command line example:

```
(ansible)[jeroen@firefly work]$ ansible oracle -a '/root/longrun.sh' --background=30 --poll=2
background launch...

rh6oranode1 | success >> {
"ansible_job_id": "696048164456",
"results_file": "/root/.ansible_async/696048164456",
"started": 1
}

rh6oranode2 | success >> {
"ansible_job_id": "696048164456",
"results_file": "/root/.ansible_async/696048164456",
"started": 1
}

polling on rh6oranode2, 28 remaining
polling on rh6oranode1, 28 remaining
polling on rh6oranode2, 26 remaining
polling on rh6oranode1, 26 remaining
finished on rh6oranode1 => {
"ansible_job_id": "696048164456",
"changed": true,
"cmd": [
"/root/longrun.sh"
],
"delta": "0:00:08.014740",
"end": "2012-04-29 17:48:51.200269",
"finished": 1,
"rc": 0,
"start": "2012-04-29 17:48:43.185529",
"stderr": "",
"stdout": ""
}
polling on rh6oranode2, 24 remaining
finished on rh6oranode2 => {
"ansible_job_id": "696048164456",
"changed": true,
"cmd": [
"/root/longrun.sh"
],
"delta": "0:00:11.014929",
"end": "2012-04-29 17:48:54.620449",
"finished": 1,
"rc": 0,
"start": "2012-04-29 17:48:43.605520",
"stderr": "",
"stdout": ""
}
```