How to run Ansible tasks in parallel

76 views
Skip to first unread message

Prathap Dasari

unread,
Nov 25, 2020, 12:56:57 PM11/25/20
to Ansible Project
Hi Team ,

Is it possible to  run Ansible tasks in parallel ? If yes , Kindly let me know How?

Regards,
Prathap

Kundan Singh

unread,
Nov 25, 2020, 1:01:36 PM11/25/20
to ansible...@googlegroups.com
By default ansible run tasks parallel .but if you feel latency from one host you can use.

Strategy: free

In your play and execute it parallel 


Hope that clears your doubts

Regards
Kundan singh

--
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 ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/a3fe3987-fbe8-4558-8dd3-0afc24622709n%40googlegroups.com.

Prathap Dasari

unread,
Nov 25, 2020, 1:06:42 PM11/25/20
to Ansible Project
Ok . That was not my question .. apologies for that ..

I would like to run playbooks parallel . is it possible ?


Regards,
Prathap

Vladimir Botka

unread,
Nov 25, 2020, 1:56:37 PM11/25/20
to Prathap Dasari, ansible...@googlegroups.com
On Wed, 25 Nov 2020 10:06:41 -0800 (PST)
Prathap Dasari <pratha...@gmail.com> wrote:

> I would like to run playbooks parallel . is it possible ?

No. It's not possible. The utility "ansible-playbook" is not able to
run playbooks in parallel. Only serial execution of plays or imported
playbooks is available. See "import_playbook"
https://docs.ansible.com/ansible/latest/collections/ansible/builtin/import_playbook_module.html

Hypothetical asynchronous task "include_playbook" is probably what you
might be looking for. There is no such module and there are no
options how to create such task. Only tasks can be run in parallel.
See "Asynchronous actions and polling"
https://docs.ansible.com/ansible/latest/user_guide/playbooks_async.html

You'll have to start "ansible-playbook" for each playbook you want to
run in parallel.

--
Vladimir Botka

Prathap Dasari

unread,
Nov 25, 2020, 1:59:37 PM11/25/20
to Vladimir Botka, ansible...@googlegroups.com
Ok .. Thank you for the clarification 👌

Mauricio Tavares

unread,
Nov 25, 2020, 2:22:17 PM11/25/20
to ansible...@googlegroups.com
That was exactly what I was going to suggest: start multiple
"ansible-playbook" instances in parallel.

> --
> Vladimir Botka
>
> --
> 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 ansible-proje...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/20201125195606.611d27f2%40gmail.com.

Prathap Dasari

unread,
Nov 25, 2020, 2:42:11 PM11/25/20
to ansible...@googlegroups.com
Ok . But I have below two yml files. 
There is no dependence between both yml files . Now How can I run them parallel at the same time ? Any advice please ?

i.e :

patching.yml
---
  - hosts: soa_admin
    tasks:
     - include_role:
         name: patching
createdomainwldt.yml
---
 - hosts: soa_admin
   tasks:
     - include_role:
         name: osbdomain


Regards,
Prathap

Stefan Hornburg (Racke)

unread,
Nov 25, 2020, 2:45:33 PM11/25/20
to ansible...@googlegroups.com
On 11/25/20 8:41 PM, Prathap Dasari wrote:
> Ok . But I have below two yml files. 
> There is no dependence between both yml files . Now How can I run them parallel at the same time ? Any advice please ?
>

Why do you want them to run in parallel? What are these roles are doing?

Regards
Racke

> i.e :
>
> *patching.yml*
> ---
>   - hosts: soa_admin
>     tasks:
>      - include_role:
>          name: patching
> *createdomainwldt.yml*
> ---
>  - hosts: soa_admin
>    tasks:
>      - include_role:
>          name: osbdomain
>
>
> Regards,
> Prathap
>
> On Wed, Nov 25, 2020 at 8:22 PM Mauricio Tavares <raub...@gmail.com <mailto:raub...@gmail.com>> wrote:
>
> On Wed, Nov 25, 2020 at 1:56 PM Vladimir Botka <vbo...@gmail.com <mailto:vbo...@gmail.com>> wrote:
> >
> > On Wed, 25 Nov 2020 10:06:41 -0800 (PST)
> > Prathap Dasari <pratha...@gmail.com <mailto:pratha...@gmail.com>> wrote:
> >
> > > I would like to run playbooks parallel . is it possible ?
> >
> > No. It's not possible. The utility "ansible-playbook" is not able to
> > run playbooks in parallel. Only serial execution of plays or imported
> > playbooks is available. See "import_playbook"
> > https://docs.ansible.com/ansible/latest/collections/ansible/builtin/import_playbook_module.html
> <https://docs.ansible.com/ansible/latest/collections/ansible/builtin/import_playbook_module.html>
> >
> > Hypothetical asynchronous task "include_playbook" is probably what you
> > might be looking for. There is no such module and there are no
> > options how to create such task. Only tasks can be run in parallel.
> > See "Asynchronous actions and polling"
> > https://docs.ansible.com/ansible/latest/user_guide/playbooks_async.html
> <https://docs.ansible.com/ansible/latest/user_guide/playbooks_async.html>
> >
> > You'll have to start "ansible-playbook" for each playbook you want to
> > run in parallel.
> >
>       That was exactly what I was going to suggest: start multiple
> "ansible-playbook" instances in parallel.
>
> > --
> > Vladimir Botka
> >
> > --
> > 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
> ansible-proje...@googlegroups.com <mailto:ansible-project%2Bunsu...@googlegroups.com>.
> <https://groups.google.com/d/msgid/ansible-project/20201125195606.611d27f2%40gmail.com>.
>
> --
> 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
> ansible-proje...@googlegroups.com <mailto:ansible-project%2Bunsu...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/CAHEKYV7t6jja1yuTL1XAV4%3DpcmfHi1ANXxjx41tjuwyka9a_wQ%40mail.gmail.com
> <https://groups.google.com/d/msgid/ansible-project/CAHEKYV7t6jja1yuTL1XAV4%3DpcmfHi1ANXxjx41tjuwyka9a_wQ%40mail.gmail.com>.
>
> --
> 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
> ansible-proje...@googlegroups.com <mailto:ansible-proje...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/CANCC9rL7tUwCCZKN_gpbW0aEJUSs29vJ1nxbYXU5NnFe3XYjNQ%40mail.gmail.com
> <https://groups.google.com/d/msgid/ansible-project/CANCC9rL7tUwCCZKN_gpbW0aEJUSs29vJ1nxbYXU5NnFe3XYjNQ%40mail.gmail.com?utm_medium=email&utm_source=footer>.


--
Ecommerce and Linux consulting + Perl and web application programming.
Debian and Sympa administration. Provisioning with Ansible.

OpenPGP_signature

Vladimir Botka

unread,
Nov 25, 2020, 3:03:33 PM11/25/20
to Prathap Dasari, ansible...@googlegroups.com
On Wed, 25 Nov 2020 20:41:32 +0100
Prathap Dasari <pratha...@gmail.com> wrote:

> I have below two yml files.
> Now How can I run them parallel at the same time ?

There is plenty of options. See for example "how to run multiple
shell scripts in parallel"
https://serverfault.com/questions/374131/how-to-run-multiple-shell-scripts-in-parallel

--
Vladimir Botka

Prathap Dasari

unread,
Nov 25, 2020, 3:35:33 PM11/25/20
to Ansible Project
Hi ,

There is no dependency between below two yaml file and also the patching.yaml and second yaml files  will be  taking  at 20 mins to complete task ,hence I am planning to run both yaml file at the same, to reduce the time if it´s possible.

Regards,
Prathap 

Reply all
Reply to author
Forward
0 new messages