68
68
description:
69
69
- Whether to use an SSL connection when connecting to the database
70
70
default: False
71
+ build_indexes:
72
+ description:
73
+ - Determines whether the mongod builds indexes on this member.
74
+ required: false
75
+ default: true
76
+ hidden:
77
+ description:
78
+ - When this value is true, the replica set hides this instance,
79
+ and does not include the member in the output of db.isMaster()
80
+ or isMaster
81
+ required: false
82
+ default: false
83
+ priority:
84
+ description:
85
+ - A number that indicates the relative eligibility of a member
86
+ to become a primary
87
+ required: false
88
+ default: 1.0
89
+ slave_delay:
90
+ description:
91
+ - The number of seconds behind the primary that this replica set
92
+ member should lag
93
+ required: false
94
+ default: 0
95
+ votes:
96
+ description:
97
+ - The number of votes a server will cast in a replica set election
98
+ default: 1
71
99
state:
72
100
state:
73
101
description:
74
- - The database user state
102
+ - The replica set member state
75
103
required: false
76
104
default: present
77
105
choices: [ "present", "absent" ]
@@ -146,7 +174,7 @@ def check_members(state, module, client, host_name, host_port, host_type):
146
174
if "{0}:{1}" .format (host_name , host_port ) not in member ['host' ] and member ['arbiterOnly' ]:
147
175
module .exit_json (changed = False , host_name = host_name , host_port = host_port , host_type = host_type )
148
176
149
- def add_host (module , client , host_name , host_port , host_type , timeout = 180 ):
177
+ def add_host (module , client , host_name , host_port , host_type , timeout = 180 , ** kwargs ):
150
178
while True :
151
179
try :
152
180
admin_db = client ['admin' ]
@@ -165,6 +193,21 @@ def add_host(module, client, host_name, host_port, host_type, timeout=180):
165
193
if host_type == 'arbiter' :
166
194
new_host ['arbiterOnly' ] = True
167
195
196
+ if not kwargs ['build_indexes' ]:
197
+ new_host ['buildIndexes' ] = False
198
+
199
+ if kwargs ['hidden' ]:
200
+ new_host ['hidden' ] = True
201
+
202
+ if kwargs ['priority' ] != 1.0 :
203
+ new_host ['priority' ] = kwargs ['priority' ]
204
+
205
+ if kwargs ['slave_delay' ] != 0 :
206
+ new_host ['slaveDelay' ] = kwargs ['slave_delay' ]
207
+
208
+ if kwargs ['votes' ] != 1 :
209
+ new_host ['votes' ] = kwargs ['votes' ]
210
+
168
211
cfg ['members' ].append (new_host )
169
212
admin_db .command ('replSetReconfig' , cfg )
170
213
return
@@ -230,18 +273,6 @@ def wait_for_ok_and_master(module, client, timeout = 60):
230
273
231
274
time .sleep (1 )
232
275
233
- def reconfigure (module ,client , rs_config , timeout = 180 ):
234
- while True :
235
- try :
236
- client ['admin' ].command ('replSetReconfig' , rs_config )
237
- return
238
- except (OperationFailure , AutoReconnect ) as e :
239
- print e
240
- timeout = timeout - 5
241
- if timeout <= 0 :
242
- module .fail_json (msg = 'reached timeout while waiting for rs.reconfig()' )
243
- time .sleep (5 )
244
-
245
276
def authenticate (client , login_user , login_password ):
246
277
if login_user is None and login_password is None :
247
278
mongocnf_creds = load_mongocnf ()
@@ -269,6 +300,11 @@ def main():
269
300
host_port = dict (default = '27017' ),
270
301
host_type = dict (default = 'replica' , choices = ['replica' ,'arbiter' ]),
271
302
ssl = dict (default = False ),
303
+ build_indexes = dict (type = 'bool' , choices = BOOLEANS , default = 'yes' ),
304
+ hidden = dict (type = 'bool' , choices = BOOLEANS , default = 'no' ),
305
+ priority = dict (default = '1.0' ),
306
+ slave_delay = dict (type = 'int' , default = '0' ),
307
+ votes = dict (type = 'int' , default = '1' ),
272
308
state = dict (default = 'present' , choices = ['absent' , 'present' ]),
273
309
)
274
310
)
@@ -320,7 +356,12 @@ def main():
320
356
321
357
try :
322
358
if not replica_set_created :
323
- add_host (module , client , host_name , host_port , host_type )
359
+ add_host (module , client , host_name , host_port , host_type ,
360
+ build_indexes = module .params ['build_indexes' ],
361
+ hidden = module .params ['hidden' ],
362
+ priority = float (module .params ['priority' ]),
363
+ slave_delay = module .params ['slave_delay' ],
364
+ votes = module .params ['votes' ])
324
365
except OperationFailure , e :
325
366
module .fail_json (msg = 'Unable to add new member to replica set: %s' % str (e ))
326
367
0 commit comments