diff --git a/docs/mongodb_guide.md b/docs/mongodb_guide.md index 2fda385e..48831659 100644 --- a/docs/mongodb_guide.md +++ b/docs/mongodb_guide.md @@ -291,6 +291,11 @@ all: To add an arbiter to the replica set, define a `mongodb_arbiter` group. Arbiters participate in elections but hold no data. +An existing data-bearing member cannot be converted to an arbiter by re-running the playbook. +MongoDB does not allow `arbiterOnly` to change in a reconfig, so the run fails at "Create or +reconfigure the replicaset". Remove the member with `rs.remove()`, delete its data directory, +restart `mongod`, and re-add it with `rs.addArb()`, or use a host that is not yet in the replica set. + ```yaml all: children: diff --git a/roles/mongodb/tasks/configure-mongodb-replicaset.yml b/roles/mongodb/tasks/configure-mongodb-replicaset.yml index bd88944c..a57a4032 100644 --- a/roles/mongodb/tasks/configure-mongodb-replicaset.yml +++ b/roles/mongodb/tasks/configure-mongodb-replicaset.yml @@ -117,7 +117,8 @@ - name: Add the arbiter to the list of servers when there is one ansible.builtin.set_fact: mongodb_servers: >- - {{ mongodb_servers + [{'host': item + ':' + (mongodb_port | string), 'priority': 0}] }} + {{ mongodb_servers + [{'host': item + ':' + (mongodb_port | string), + 'priority': 0, 'arbiterOnly': true}] }} loop: "{{ groups.mongodb_arbiter }}" when: - mongodb_is_primary_node