run multiple tasks in parallel for multiple hosts

Hi all,

I have search around for this but they are all about running one task concurrently for multiple hosts. What I am trying to get is running multiple tasks concurrently, meaning if one host, for whatever reason, even ssh timeout, has slow execution, it should not block the task execution go on to the next for other hosts. How can I achieve this within ansible? I can do a wrapper of the ansible-playbook command but wonder if ansible supports this natively.

Thanks,

Tao

Hi,

Take a look at asynchronous actions: http://docs.ansible.com/playbooks_async.html

Hi Mark,

Thanks for the reply. I am aware of the async action but this is not what I am looking for. async kicks off task, but still blocks other tasks before all hosts have finished that particular task. Fire and forget is not an option for me either. What I am looking for is that when host 1 has finished task1, it will go on to task2 regardless host2 has finished task1 or not.

Thanks again.

Ansible is designed to work this way intentionally as it’s quite useful for inter-machine orchestration and extremely useful for fine grained control when we want to do things like work with load balancers.

You might possibly want to consider invoking ansible-pull (or just ansible in local mode) from ansible if you want that architecture.

It’s not going to be possible to do this with a “stock” push-mode ansible-playbook – also think about how messy the output would be trying to read it from the CLI! :slight_smile:

I should also mention that AWX has a nice callback feature that allows a node to phone home and request configuration that you might be interested in. Basically you just request a special URL via curl, AWX verifies the requesting system was in inventory, and then it will reach out and configure that system in standard push mode, but it doesn’t have to wait on other systems. (Note: this is not the standard way AWX operates, but it’s a supported feature).

I would probably recommend invoking ansible-pull via an async task for most basic use cases, though you’re not going to have as nice of standard output.