Help with async tasks.

76 views
Skip to first unread message

Guannan Sun

unread,
Aug 31, 2020, 5:38:38 AM8/31/20
to Ansible Project
Dear Tech Team,

I'm Guannan from China. I'm new to Ansible and looking for some technical help.
Actually I'm looking for a method to execute one role in parallel with loops of different configuration files. For example, I want to create 100 sites using role "create_site" with 100 different configuration files. I simply write a playbook like this:

- hosts: localhost
  gather_facts: no
  tasks:
    - name: register files
      shell: "find /tmp/site_files -name '*.yml' | sort"
      register: file_names

    - include_role:
        name: create_site
        vars_from: "{{ item }}"
      with_items: "{{ file_names.stdout_lines }}"

This will create 100 sites in serial. If create one site take 2 minutes, then the whole playbook will take over 200 minutes. I found 'async' option when execute tasks, however it seems only used for async jobs on different hosts. Do you guys have experience or methods on how to execute one role with different configuration files in parallel? Please send me E-mails.
Much thanks for your help!

Stefan Hornburg (Racke)

unread,
Aug 31, 2020, 5:45:56 AM8/31/20
to ansible...@googlegroups.com
What is the "create_site" role actually doing?

Regards
Racke

>
> --
> 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/7d012eec-95de-48c3-8b8a-d32928170eacn%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/7d012eec-95de-48c3-8b8a-d32928170eacn%40googlegroups.com?utm_medium=email&utm_source=footer>.


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

signature.asc

Guannan Sun

unread,
Aug 31, 2020, 5:57:01 AM8/31/20
to Ansible Project
Thank you for your response.
Well, in my condition, I using 'create_site' role to create a site in a netbox. It will create a site with name, region, and some other fields, associate some devices and vlans with the site.
You may just treat 'create_site' as a role execute some tasks in serial.

Martin Etcheverry

unread,
Aug 31, 2020, 4:10:14 PM8/31/20
to ansible...@googlegroups.com

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/4a67d662-278a-4070-9091-18778ae53befn%40googlegroups.com.


--

                  :::
(\(\
                  *: (=
' :') :*        
                  ... (,('')('')....
          mar...@etcheverri.com
          Consultoria de sistemas
                     
           


Guannan Sun

unread,
Sep 1, 2020, 3:19:35 AM9/1/20
to Ansible Project
Thank you for your response. 
I've tried to add 'strategy: free' in my playbook, however it seems not work as my expectation. I think it may because there is only single host in my scenario, while 'strategy: free' works well in scenario of multi hosts and multi tasks.
We're now trying to run multi jobs at the same time on AWX. One jobs call the role 'create_site' and loop for 5 configuration files, so that 20 jobs will cover 100 configuration files. It seems work in my scenario.
Thank you anyway, and good-looking signiture :)

Martin Etcheverry

unread,
Sep 1, 2020, 8:07:53 PM9/1/20
to ansible...@googlegroups.com
well other option (i used only once) is run the shell command with gnu parallel .
its pretty amazing! but i pretty stiff learning curve.
maybe you could , give it a chance.

best regards!

Guannan Sun

unread,
Sep 2, 2020, 9:31:40 PM9/2/20
to Ansible Project
Thank you!
Even I have not used gnu parallel before, I'll also take it into consideration.
If have any progress, I'd like to share.
Best reagards!
Reply all
Reply to author
Forward
0 new messages