# Ansible : Deploy task in round robin fashion

**URL:** <https://forum.ansible.com/t/ansible-deploy-task-in-round-robin-fashion/29228>\
**Category:** Ansible Project\
**Created:** [December 9, 2018, 4:37am UTC](https://forum.ansible.com/t/ansible-deploy-task-in-round-robin-fashion/29228 "2018-12-09T04:37:17Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tejas\_Gadaria1](https://avatars.discourse-cdn.com/v4/letter/t/7993a0/32.png) [@Tejas\_Gadaria1](https://forum.ansible.com/u/Tejas_Gadaria1)\
**Post date:** [December 9, 2018, 4:37am UTC](https://forum.ansible.com/t/ansible-deploy-task-in-round-robin-fashion/29228/1 "2018-12-09T04:37:17Z")

</div>

Hello all,

I have group `tgt-cluster` includes 3 hosts. I have written down role to deploy container which is executing on `tgt-cluster` group. I am controlling the number of containers to deploy with `with_sequence`. My tasks looks like this.

```auto
- name: Deploy Container 
  docker_container:
    name: "C{{ item }}"
    image: "{{ image_name }}:{{ image_tag }}"
    recreate: yes
    detach: yes
    tty: yes
    interactive: yes
  with_sequence: count="{{ number_of_container_to_deploy }}" 

```

> `I`f I want to deploy one container, currently playbook is executing on all 3 hosts in `tgt-cluster`group and I end up with 3 containers. So How should I created nested loop in this case to control the task execution on hosts on round robin fashion.

Say if we want to deploy 4 container… 1st container should be deployed on 1st host in group, 2nd container should be deployed on 2nd host in group, 3rd should be deployed on 3rd hosts in group and 4th container should be deployed back to the 1st host in group.

Need your help on this,

Thanks,

Tejas

---

<div class="post-metadata">

**Author:** ![Tejas\_Gadaria1](https://avatars.discourse-cdn.com/v4/letter/t/7993a0/32.png) [@Tejas\_Gadaria1](https://forum.ansible.com/u/Tejas_Gadaria1)\
**Post date:** [December 10, 2018, 4:18pm UTC](https://forum.ansible.com/t/ansible-deploy-task-in-round-robin-fashion/29228/2 "2018-12-10T16:18:32Z")

</div>

I tried jinja to loop over the group of hosts to serve my purpose but didn’t get expected result.  
Need your help on this.

---

<div class="post-metadata">

**Author:** ![Eric\_Brewer](https://avatars.discourse-cdn.com/v4/letter/e/a5b964/32.png) [@Eric\_Brewer](https://forum.ansible.com/u/Eric_Brewer)\
**Post date:** [December 17, 2018, 7:05pm UTC](https://forum.ansible.com/t/ansible-deploy-task-in-round-robin-fashion/29228/3 "2018-12-17T19:05:41Z")

</div>

So you could probably approach this a few different ways. If you know the host in the group, you could apply a when conditional

`when: inventory_hostname == ""`

That would allow you to evaluate which server to run it on for the given group. If you don’t care which one it gets run on, and you have a way to only run this on one group at a time, you could also probably use this:

`run_once: yes`

That way it would just run against the first server it came across, whichever one that was…
