# Calling URI task to 10 servers in parallel

**URL:** <https://forum.ansible.com/t/calling-uri-task-to-10-servers-in-parallel/25650>\
**Category:** Ansible Project\
**Tags:** windows\
**Created:** [October 1, 2017, 1:16pm UTC](https://forum.ansible.com/t/calling-uri-task-to-10-servers-in-parallel/25650 "2017-10-01T13:16:28Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Marc\_L](https://avatars.discourse-cdn.com/v4/letter/m/85f322/32.png) [@Marc\_L](https://forum.ansible.com/u/Marc_L)\
**Post date:** [October 1, 2017, 1:16pm UTC](https://forum.ansible.com/t/calling-uri-task-to-10-servers-in-parallel/25650/1 "2017-10-01T13:16:28Z")

</div>

Ansible newbie…

We run a large enterprise web app load balanced over 10 servers in a customer environment (windows servers)The app exposes a set of Webservices to manage config, such as applying new binaries, exporting config as XML etc.

Sometimes we need to update the application, and this is done by uploading a large ZIP (200mb) to each node, and sometimes we need to export the full config from each node.  
Both these things can take a short while (30 secs or so)  
Previously we had a set of bash scripts we ran to upload/export the zips, but it ran in a linear fashion, so the script running was 10 x the time to perform the function. It could end up taking a while.

We are now looking at Ansible, and ideally, we would want to do these upload or export tasks in parallel to minimise downtime for the client.  
We have the uri-module working to call the webservices but not sure on the best way to run the 10 uri tasks in parallel?

I was thinking of calling uri with the async “call and forget, then check later” method, and just call 10 tasks, one for each node?

Something like this (the below example just runs for 2 nodes).  
It looks like it might work, but i don’t like having this repetition?

Is there any other way to do this?

`

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [October 1, 2017, 3:11pm UTC](https://forum.ansible.com/t/calling-uri-task-to-10-servers-in-parallel/25650/2 "2017-10-01T15:11:19Z")

</div>

- hosts: node1,node2  
&nbsp;&nbsp;&nbsp;gather\_facts: no

&nbsp;&nbsp;&nbsp;vars:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ohp\_auth\_user: "username"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ohp\_auth\_password: "password"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;backup\_folder: "./backups-async"

&nbsp;&nbsp;&nbsp;tasks:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- name: Export node 1 config  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;uri:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;url: "https://{{ inventory\_hostname}}:19043/configuration/config/export/all"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;headers:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"accept": "application/vnd.AdminConfiguration.6\_9+zip"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"Content-Type": "application/x-www-form-urlencoded"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"X-Requested-With": "ansible"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;method: POST  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;user: "{{ ohp\_auth\_user }}"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;password: "{{ ohp\_auth\_password }}"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;force\_basic\_auth: yes  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;validate\_certs: no  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;status\_code: 200  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;timeout: 20  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return\_content: yes  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dest: "{{ backup\_folder }}/{{ inventory\_hostname}}\_config.zip"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;delegate\_to: localhost

This will do the same in parallel for node1 to node2.  
Ansible run default a task in parallel on 5 hosts, but this can be adjusted with forks on command line or in ansible.cfg

---

<div class="post-metadata">

**Author:** ![Marc\_L](https://avatars.discourse-cdn.com/v4/letter/m/85f322/32.png) [@Marc\_L](https://forum.ansible.com/u/Marc_L)\
**Post date:** [October 1, 2017, 3:34pm UTC](https://forum.ansible.com/t/calling-uri-task-to-10-servers-in-parallel/25650/3 "2017-10-01T15:34:18Z")

</div>

Ah, many thanks. I had totally overlooked the delegate\_to functionality.  
A lot of the tasks I need to run in a “local” context and simply call the remote server webservices - so this delegate\_to functionality is a key piece of the puzzle.

Thanks!
