# multiple async actions (background tasks) question

**URL:** <https://forum.ansible.com/t/multiple-async-actions-background-tasks-question/15529>\
**Category:** Ansible Project\
**Created:** [June 23, 2014, 7:39pm UTC](https://forum.ansible.com/t/multiple-async-actions-background-tasks-question/15529 "2014-06-23T19:39:07Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dimon](https://avatars.discourse-cdn.com/v4/letter/d/eb8c5e/32.png) [@Dimon](https://forum.ansible.com/u/Dimon)\
**Post date:** [June 23, 2014, 7:39pm UTC](https://forum.ansible.com/t/multiple-async-actions-background-tasks-question/15529/1 "2014-06-23T19:39:07Z")

</div>

Hi, I’m trying to reconfigure a running OS to use bridge vs the actual interface. My playbook so far:

- name: copy bridge config  
template: src=if-br.j2 dest=/etc/sysconfig/network-scripts/if-{{ bridge\_name }} backup=yes

- name: copy interface config  
template: src=if-nic.j2 dest=/etc/sysconfig/network-scripts/if-{{ nic\_name }} backup=yes

# we will lose connectivity right after this

- name: add OVS port  
openvswitch\_port: bridge={{ bridge\_name }} port={{ nic\_name }} state=present  
async: 60  
poll: 30

# we should recover connectivity right after this

- name: restart network  
service: name=network state=restarted  
async: 60  
poll: 30

As you can see last two actions should be run async (due to loss of connectivity) however they also need to be executed sequentially. I like the way those tasks are defined using Ansible (with some add-on built logic for checking whether bridge exists etc. that I don’t have to implement) and would prefer it not to be a shell script instead. Are there any good options for doing it within ansible without resorting to “outsorcing” for that last chunk to a shell script?

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [June 24, 2014, 1:19pm UTC](https://forum.ansible.com/t/multiple-async-actions-background-tasks-question/15529/2 "2014-06-24T13:19:49Z")

</div>

If you are polling on an async job, they will still be executed sequentially.

I do not see where you are calling a shell script in your example, so I can’t tell what you mean by the last part of your question. Can you elaborate or show that part?

---

<div class="post-metadata">

**Author:** ![Dimon](https://avatars.discourse-cdn.com/v4/letter/d/eb8c5e/32.png) [@Dimon](https://forum.ansible.com/u/Dimon)\
**Post date:** [June 25, 2014, 3:28pm UTC](https://forum.ansible.com/t/multiple-async-actions-background-tasks-question/15529/3 "2014-06-25T15:28:49Z")

</div>

Sorry for being unclear - I meant that I can implement above functionality either via ansible (albeit I have no clue on how to make certain things run in the background as per my question) or write a script that does all of that and have a single ansible statement like this:

- shell: reconfigure\_nic.sh {{ nic\_name }} {{bridge\_name}}

I’m leaving out details of that script implementation because I both don’t have it and do not have inclination to implement it with all bells and whistles to match ansible functionality, but something along the lines of:

ovs-vsctl --may-exist add-port {{ bridge\_name }} {{nic\_name}}  
service network restart

and run it in the background…
