Skip to content

Commit 1ac754c

Browse files
committed
last changes
1 parent a0a404e commit 1ac754c

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

roles/mongo/defaults/main.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,5 +75,8 @@ mongo_data_path: "/var/lib/mongo"
7575
# votes: 1
7676
# arbiterOnly: true
7777

78+
mongo_cluster_write_concern: "majority"
79+
mongo_cluster_write_timeout: 5000
80+
7881
# to avoid surprises only initiate or reconfigure cluster if this is true (safest option is to use -e mongo_configure_cluster=true with your deployment when cluster configuration is necessary)
7982
mongo_configure_cluster: false

roles/mongo/tasks/clusterconfig.yml

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,4 +111,44 @@
111111
- name: Debug cluster reconfiguration
112112
ansible.builtin.debug:
113113
msg: "{{ rs_reconfigure }}"
114-
verbosity: 2
114+
verbosity: 2
115+
116+
- name: Wait for the replicaset to stabilise
117+
community.mongodb.mongodb_status:
118+
replica_set: "{{ mongo_replica_set_name }}"
119+
login_host: localhost
120+
login_user: admin
121+
login_password: "{{ mongo_admin_password }}"
122+
login_port: "{{ mongo_port }}"
123+
poll: 5
124+
interval: 30
125+
126+
# Cluster settings that cannot be changed with mongodb_replicaset
127+
128+
- name: Get current default write concern
129+
community.mongodb.mongodb_shell:
130+
login_host: localhost
131+
login_port: 27017
132+
login_user: admin
133+
login_password: "{{ mongo_admin_password }}"
134+
eval: "db.adminCommand({ getDefaultRWConcern: 1 })"
135+
#transform: raw
136+
register: current_write_concern
137+
changed_when: false
138+
139+
- name: Debug write concern check
140+
ansible.builtin.debug:
141+
msg: "{{ current_write_concern.transformed_output.defaultWriteConcern }}"
142+
verbosity: 2
143+
144+
- name: Set default write concern
145+
community.mongodb.mongodb_shell:
146+
login_host: localhost
147+
login_user: admin
148+
login_password: "{{ mongo_admin_password }}"
149+
login_port: "{{ mongo_port }}"
150+
eval: "db.adminCommand({ setDefaultRWConcern: 1, defaultWriteConcern: { w: {{ mongo_cluster_write_concern | default('majority') }}, wtimeout: {{ mongo_cluster_write_timeout | default(5000) }} } })"
151+
when: >
152+
current_write_concern.transformed_output.defaultWriteConcern.w | string != mongo_cluster_write_concern | default('majority') | string
153+
or
154+
current_write_concern.transformed_output.defaultWriteConcern.wtimeout | int != mongo_cluster_write_timeout | default(5000) | int

0 commit comments

Comments
 (0)