Skip to content

Commit 111069f

Browse files
committed
Add support for hidden repl members and priorities
Currently ansible-role-mongodb does not support replicaset member attributes as "hidden" and "priority". This commit attempts to solve the problem described above. Support for attributes "hidden" and "priority" has been added.
1 parent 4884874 commit 111069f

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

library/mongodb_replication.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -300,8 +300,8 @@ def main():
300300
host_port=dict(default='27017'),
301301
host_type=dict(default='replica', choices=['replica','arbiter']),
302302
ssl=dict(default=False),
303-
build_indexes = dict(type='bool', choices=BOOLEANS, default='yes'),
304-
hidden = dict(type='bool', choices=BOOLEANS, default='no'),
303+
build_indexes = dict(type='bool', default='yes'),
304+
hidden = dict(type='bool', default='no'),
305305
priority = dict(default='1.0'),
306306
slave_delay = dict(type='int', default='0'),
307307
votes = dict(type='int', default='1'),
@@ -322,6 +322,7 @@ def main():
322322
host_type = module.params['host_type']
323323
ssl = module.params['ssl']
324324
state = module.params['state']
325+
priority = float(module.params['priority'])
325326

326327
replica_set_created = False
327328

@@ -340,7 +341,9 @@ def main():
340341
client = MongoClient(login_host, int(login_port), ssl=ssl)
341342
authenticate(client, login_user, login_password)
342343
if state == 'present':
343-
config = { '_id': "{0}".format(replica_set), 'members': [{ '_id': 0, 'host': "{0}:{1}".format(host_name, host_port)}] }
344+
new_host = { '_id': 0, 'host': "{0}:{1}".format(host_name, host_port) }
345+
if priority != 1.0: new_host['priority'] = priority
346+
config = { '_id': "{0}".format(replica_set), 'members': [new_host] }
344347
client['admin'].command('replSetInitiate', config)
345348
wait_for_ok_and_master(module, client)
346349
replica_set_created = True

tasks/replication.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
host_name: "{{ item.host_name }}"
1111
host_port: "{{ item.host_port|default(27017) }}"
1212
host_type: "{{ item.host_type|default('replica') }}"
13+
hidden: "{{ item.hidden|default(false) }}"
14+
priority: "{{ item.priority|default(1.0) }}"
1315
when: mongodb_conf_auth and mongodb_replication_params is defined
1416
with_items:
1517
- "{{ mongodb_replication_params }}"
@@ -22,6 +24,8 @@
2224
host_name: "{{ item.host_name }}"
2325
host_port: "{{ item.host_port|default(27017) }}"
2426
host_type: "{{ item.host_type|default('replica') }}"
27+
hidden: "{{ item.hidden|default(false) }}"
28+
priority: "{{ item.priority|default(1.0) }}"
2529
when: not mongodb_conf_auth and mongodb_replication_params is defined
2630
with_items:
2731
- "{{ mongodb_replication_params }}"

tasks/replication_init_auth.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
---
2-
32
- name: Replication configuration
43
mongodb_replication:
54
login_host: "{{ mongodb_login_host|default('localhost') }}"
@@ -10,6 +9,8 @@
109
host_name: "{{ item.host_name }}"
1110
host_port: "{{ item.host_port|default(27017) }}"
1211
host_type: "{{ item.host_type|default('replica') }}"
12+
hidden: "{{ item.hidden|default(false) }}"
13+
priority: "{{ item.priority|default(1.0) }}"
1314
with_items:
1415
- "{{ mongodb_replication_params }}"
1516
register: mongodb_replica_init
@@ -28,6 +29,8 @@
2829
host_name: "{{ item.host_name }}"
2930
host_port: "{{ item.host_port|default(27017) }}"
3031
host_type: "{{ item.host_type|default('replica') }}"
32+
hidden: "{{ item.hidden|default(false) }}"
33+
priority: "{{ item.priority|default(1.0) }}"
3134
with_items:
3235
- "{{ mongodb_replication_params }}"
3336
when: mongodb_replica_init|failed

0 commit comments

Comments
 (0)