# Host o

**URL:** <https://forum.ansible.com/t/host-o/13221>\
**Category:** Ansible Project\
**Created:** [July 30, 2013, 7:32pm UTC](https://forum.ansible.com/t/host-o/13221 "2013-07-30T19:32:32Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![bjunity](https://avatars.discourse-cdn.com/v4/letter/b/e9bcb4/32.png) [@bjunity](https://forum.ansible.com/u/bjunity)\
**Post date:** [July 30, 2013, 7:32pm UTC](https://forum.ansible.com/t/host-o/13221/1 "2013-07-30T19:32:32Z")

</div>

Hi,

i’ve a question regarding the following situation.

We’ve many mongodb sharding/repl - clusters. Here’s an example:

ansible hosts file: (serial: 1 in playbooks)  
.  
.  
[mongo\_data\_servers]  
mg-rs01-arb  
mg-rs01-b  
mg-rs01-a  
.  
.

This is a mongodb sharding/replicaset (with Arbiter, Secondary, Primary) , so ordering is very important.

I’ve assumed that the hosts are processed in the same order as they are written, but the ansible execution order is:

mg-rs01-b  
mg-rs01-arb  
mg-rs01-a

Is this intended behavior ? I think it would be much better if the hosts are processed in order.

Aliases aren’t a solution (unnecessary overhead of manage ip + alias entries etc.)

Thanks in advance and for ansible, it’s truly a great piece of sotfware.

Bjoern

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Michael\_DeHaan](https://forum.ansible.com/u/Michael_DeHaan)\
**Post date:** [July 30, 2013, 7:47pm UTC](https://forum.ansible.com/t/host-o/13221/2 "2013-07-30T19:47:14Z")

</div>

Group membership is sorted.

If you want to list them explicitly in the host spec instead of using groups, you of course could do that.

---

<div class="post-metadata">

**Author:** ![bjunity](https://avatars.discourse-cdn.com/v4/letter/b/e9bcb4/32.png) [@bjunity](https://forum.ansible.com/u/bjunity)\
**Post date:** [July 30, 2013, 8:00pm UTC](https://forum.ansible.com/t/host-o/13221/3 "2013-07-30T20:00:31Z")

</div>

Hi Michael,

thanks for quick reply.

If i understand you correctly, i cant’t use groups ?

Unfortunately this isn’t possible, example hosts-file:

[mongos\_servers]  
…  
…

[mongo\_config\_servers]  
…  
…  
…

[mongo\_data\_servers]  
…  
…

.  
.

All of these groups have different tasks in playbook, therefore working without groups is nearly not possible.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Michael\_DeHaan](https://forum.ansible.com/u/Michael_DeHaan)\
**Post date:** [July 30, 2013, 8:15pm UTC](https://forum.ansible.com/t/host-o/13221/4 "2013-07-30T20:15:08Z")

</div>

You may wish to take a look at how grouping is handled here:

[https://github.com/ansible/ansible-examples/tree/master/mongodb](https://github.com/ansible/ansible-examples/tree/master/mongodb)

Ansible is a parallel system so you should not rely on order.

However I ran a quick test:

- hosts: zog:bog:slog  
serial: 1  
tasks:
- shell: echo hi {{ inventory\_hostname }}

With:

[zog]  
z  
g  
a

[slog]  
z2  
g2  
a2

[bog]  
z3  
g3  
a3

I get order running as z3, z2, z, g3, g2, g, a3, a2, a … which implies it’s actually not sorted.

However, don’t rely on that, there’s nothing spec’d about that behavior.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Michael\_DeHaan](https://forum.ansible.com/u/Michael_DeHaan)\
**Post date:** [July 30, 2013, 8:16pm UTC](https://forum.ansible.com/t/host-o/13221/5 "2013-07-30T20:16:34Z")

</div>

This may actually imply serialized batches are reverse sorted.

Yeah, don’t rely on that 🙂

---

<div class="post-metadata">

**Author:** ![bjunity](https://avatars.discourse-cdn.com/v4/letter/b/e9bcb4/32.png) [@bjunity](https://forum.ansible.com/u/bjunity)\
**Post date:** [July 30, 2013, 8:34pm UTC](https://forum.ansible.com/t/host-o/13221/6 "2013-07-30T20:34:15Z")

</div>

Hi,

thanks.

[https://github.com/ansible/ansible-examples/tree/master/mongodb](https://github.com/ansible/ansible-examples/tree/master/mongodb)

My playbook for example is for rolling restarts/upgrades of a mongodb-cluster (not only for initial deployment), so ordering there is very important to avoid downtime and data corruption/loss.

I know many HA - setups/applications where ordering is essential (master/slave, active/standy etc.), for example in initial deployments, rolling restarts/upgrades and so on.

It would be great if ansible would order the hosts, then you don’t have to write extra complex scripts with logic for every application to handle this.

With correct ordering you can keep it simple and use ansible for it.

Thanks in advance.
