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.
This commit is contained in:
davidcaste 2015-12-14 09:17:37 +01:00
parent 4884874c99
commit 111069fbee
3 changed files with 14 additions and 4 deletions

View File

@ -300,8 +300,8 @@ def main():
host_port=dict(default='27017'), host_port=dict(default='27017'),
host_type=dict(default='replica', choices=['replica','arbiter']), host_type=dict(default='replica', choices=['replica','arbiter']),
ssl=dict(default=False), ssl=dict(default=False),
build_indexes = dict(type='bool', choices=BOOLEANS, default='yes'), build_indexes = dict(type='bool', default='yes'),
hidden = dict(type='bool', choices=BOOLEANS, default='no'), hidden = dict(type='bool', default='no'),
priority = dict(default='1.0'), priority = dict(default='1.0'),
slave_delay = dict(type='int', default='0'), slave_delay = dict(type='int', default='0'),
votes = dict(type='int', default='1'), votes = dict(type='int', default='1'),
@ -322,6 +322,7 @@ def main():
host_type = module.params['host_type'] host_type = module.params['host_type']
ssl = module.params['ssl'] ssl = module.params['ssl']
state = module.params['state'] state = module.params['state']
priority = float(module.params['priority'])
replica_set_created = False replica_set_created = False
@ -340,7 +341,9 @@ def main():
client = MongoClient(login_host, int(login_port), ssl=ssl) client = MongoClient(login_host, int(login_port), ssl=ssl)
authenticate(client, login_user, login_password) authenticate(client, login_user, login_password)
if state == 'present': 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) client['admin'].command('replSetInitiate', config)
wait_for_ok_and_master(module, client) wait_for_ok_and_master(module, client)
replica_set_created = True replica_set_created = True

View File

@ -10,6 +10,8 @@
host_name: "{{ item.host_name }}" host_name: "{{ item.host_name }}"
host_port: "{{ item.host_port|default(27017) }}" host_port: "{{ item.host_port|default(27017) }}"
host_type: "{{ item.host_type|default('replica') }}" 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 when: mongodb_conf_auth and mongodb_replication_params is defined
with_items: with_items:
- "{{ mongodb_replication_params }}" - "{{ mongodb_replication_params }}"
@ -22,6 +24,8 @@
host_name: "{{ item.host_name }}" host_name: "{{ item.host_name }}"
host_port: "{{ item.host_port|default(27017) }}" host_port: "{{ item.host_port|default(27017) }}"
host_type: "{{ item.host_type|default('replica') }}" 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 when: not mongodb_conf_auth and mongodb_replication_params is defined
with_items: with_items:
- "{{ mongodb_replication_params }}" - "{{ mongodb_replication_params }}"

View File

@ -1,5 +1,4 @@
--- ---
- name: Replication configuration - name: Replication configuration
mongodb_replication: mongodb_replication:
login_host: "{{ mongodb_login_host|default('localhost') }}" login_host: "{{ mongodb_login_host|default('localhost') }}"
@ -10,6 +9,8 @@
host_name: "{{ item.host_name }}" host_name: "{{ item.host_name }}"
host_port: "{{ item.host_port|default(27017) }}" host_port: "{{ item.host_port|default(27017) }}"
host_type: "{{ item.host_type|default('replica') }}" host_type: "{{ item.host_type|default('replica') }}"
hidden: "{{ item.hidden|default(false) }}"
priority: "{{ item.priority|default(1.0) }}"
with_items: with_items:
- "{{ mongodb_replication_params }}" - "{{ mongodb_replication_params }}"
register: mongodb_replica_init register: mongodb_replica_init
@ -28,6 +29,8 @@
host_name: "{{ item.host_name }}" host_name: "{{ item.host_name }}"
host_port: "{{ item.host_port|default(27017) }}" host_port: "{{ item.host_port|default(27017) }}"
host_type: "{{ item.host_type|default('replica') }}" host_type: "{{ item.host_type|default('replica') }}"
hidden: "{{ item.hidden|default(false) }}"
priority: "{{ item.priority|default(1.0) }}"
with_items: with_items:
- "{{ mongodb_replication_params }}" - "{{ mongodb_replication_params }}"
when: mongodb_replica_init|failed when: mongodb_replica_init|failed