Host o

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

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.

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.

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

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.

This may actually imply serialized batches are reverse sorted.

Yeah, don’t rely on that :slight_smile:

Hi,

thanks.

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.