I am creating a role in Ansible to let mongodb cluster with other machines. I am using the mongodb_replicaset collection for this use case.
I want to build the member list of the cluster with Ansible.
Imagine there are 7 hosts in the play. The variables are set like this:
host-1 # secondary
host-2 # secondary
host-3 # secondary
host-4 # primary
host-5 # arbiter
host-6 # arbiter
host-7 # secondary
How can I configure Ansible so that it will build the members list based on the amount of hosts in the play, and set a priority based on the role. In this case, host-4 should contain the variable, because that is the primary and will eventually execute the task.
E.g. primary = 1, secondary = 0.5 and arbiter = 0.1
Desired output:
- host: host-1
priority: 0.5
- host: host-2
priority: 0.5
- host: host-3
priority: 0.5
- host: host-3
priority: 0.5
- host: host-4
priority: 1.0
- host: host-5
priority: 0.1
- host: host-6
priority: 0.1
- host: host-7
priority: 0.5