mirror of
https://github.com/status-im/ansible-role-mongodb.git
synced 2025-02-10 12:06:23 +00:00
Merge pull request #42 from davidcaste/davidcaste-replicaset-with-priorities
Add support for hidden repl members and priorities
This commit is contained in:
commit
c996d6eaf7
@ -300,8 +300,8 @@ def main():
|
||||
host_port=dict(default='27017'),
|
||||
host_type=dict(default='replica', choices=['replica','arbiter']),
|
||||
ssl=dict(default=False),
|
||||
build_indexes = dict(type='bool', choices=BOOLEANS, default='yes'),
|
||||
hidden = dict(type='bool', choices=BOOLEANS, default='no'),
|
||||
build_indexes = dict(type='bool', default='yes'),
|
||||
hidden = dict(type='bool', default='no'),
|
||||
priority = dict(default='1.0'),
|
||||
slave_delay = dict(type='int', default='0'),
|
||||
votes = dict(type='int', default='1'),
|
||||
@ -322,6 +322,7 @@ def main():
|
||||
host_type = module.params['host_type']
|
||||
ssl = module.params['ssl']
|
||||
state = module.params['state']
|
||||
priority = float(module.params['priority'])
|
||||
|
||||
replica_set_created = False
|
||||
|
||||
@ -340,7 +341,9 @@ def main():
|
||||
client = MongoClient(login_host, int(login_port), ssl=ssl)
|
||||
authenticate(client, login_user, login_password)
|
||||
if state == 'present':
|
||||
config = { '_id': "{0}".format(replica_set), 'members': [{ '_id': 0, 'host': "{0}:{1}".format(host_name, host_port)}] }
|
||||
new_host = { '_id': 0, 'host': "{0}:{1}".format(host_name, host_port) }
|
||||
if priority != 1.0: new_host['priority'] = priority
|
||||
config = { '_id': "{0}".format(replica_set), 'members': [new_host] }
|
||||
client['admin'].command('replSetInitiate', config)
|
||||
wait_for_ok_and_master(module, client)
|
||||
replica_set_created = True
|
||||
|
@ -10,6 +10,8 @@
|
||||
host_name: "{{ item.host_name }}"
|
||||
host_port: "{{ item.host_port|default(27017) }}"
|
||||
host_type: "{{ item.host_type|default('replica') }}"
|
||||
hidden: "{{ item.hidden|default(false) }}"
|
||||
priority: "{{ item.priority|default(1.0) }}"
|
||||
when: mongodb_conf_auth and mongodb_replication_params is defined
|
||||
with_items:
|
||||
- "{{ mongodb_replication_params }}"
|
||||
@ -22,6 +24,8 @@
|
||||
host_name: "{{ item.host_name }}"
|
||||
host_port: "{{ item.host_port|default(27017) }}"
|
||||
host_type: "{{ item.host_type|default('replica') }}"
|
||||
hidden: "{{ item.hidden|default(false) }}"
|
||||
priority: "{{ item.priority|default(1.0) }}"
|
||||
when: not mongodb_conf_auth and mongodb_replication_params is defined
|
||||
with_items:
|
||||
- "{{ mongodb_replication_params }}"
|
||||
|
@ -1,5 +1,4 @@
|
||||
---
|
||||
|
||||
- name: Replication configuration
|
||||
mongodb_replication:
|
||||
login_host: "{{ mongodb_login_host|default('localhost') }}"
|
||||
@ -10,6 +9,8 @@
|
||||
host_name: "{{ item.host_name }}"
|
||||
host_port: "{{ item.host_port|default(27017) }}"
|
||||
host_type: "{{ item.host_type|default('replica') }}"
|
||||
hidden: "{{ item.hidden|default(false) }}"
|
||||
priority: "{{ item.priority|default(1.0) }}"
|
||||
with_items:
|
||||
- "{{ mongodb_replication_params }}"
|
||||
register: mongodb_replica_init
|
||||
@ -28,6 +29,8 @@
|
||||
host_name: "{{ item.host_name }}"
|
||||
host_port: "{{ item.host_port|default(27017) }}"
|
||||
host_type: "{{ item.host_type|default('replica') }}"
|
||||
hidden: "{{ item.hidden|default(false) }}"
|
||||
priority: "{{ item.priority|default(1.0) }}"
|
||||
with_items:
|
||||
- "{{ mongodb_replication_params }}"
|
||||
when: mongodb_replica_init|failed
|
||||
|
Loading…
x
Reference in New Issue
Block a user