Commit c7de4d76 by Feanil Patel

Add support for dynamically generating the replica set configuration for mongo.

parent 2bb6f370
mongo_logappend: true
mongo_version: 2.4.7
mongo_bind_ip: 127.0.0.1
mongo_port: "27017"
mongo_extra_conf: ''
mongo_key_file: '/etc/mongodb_key'
mongo_repl_set: rs0
mongo_cluster_members:
mongo_cluster_members: []
mongo_data_dir: "{{ COMMON_DATA_DIR }}/mongo"
mongo_log_dir: "{{ COMMON_LOG_DIR }}/mongo"
......@@ -19,3 +20,8 @@ MONGO_USERS:
mongo_logpath: "{{ mongo_log_dir }}/mongodb.log"
mongo_dbpath: "{{ mongo_data_dir }}/mongodb"
# If the system is running out of an Amazon Web Services
# cloudformation stack, this group name can used to pull out
# the name of the stack the mongo server resides in.
mongo_aws_stack_name: "tag_aws_cloudformation_stack-name_"
......@@ -9,8 +9,14 @@ logpath={{ mongo_logpath }}
logappend={{ mongo_logappend }}
{# Bind to all ips(default) if in clustered mode,
otherwise only to the specified local ip.
#}
{% if mongo_clustered is not defined %}
bind_ip = {{ mongo_bind_ip }}
#port = 27017
{% endif %}
port = {{ mongo_port }}
# Enable journaling, http://www.mongodb.org/display/DOCS/Journaling
journal=true
......
{# Generate a list of hosts if no cluster members are give. Otherwise use the
hosts provided in the variable.
#}
{%- if mongo_cluster_members|length == 0 -%}
{%- set hosts = [] -%}
{%- set all_mongo_hosts = [] -%}
{%- do all_mongo_hosts.extend(groups.tag_role_mongo) -%}
{%- do all_mongo_hosts.extend(groups.tag_group_mongo) -%}
{%- for name in group_names -%}
{%- if name.startswith(mongo_aws_stack_name) -%}
{%- for host in all_mongo_hosts -%}
{%- if host in groups[name] -%}
{% do hosts.append("ip-" + host.replace('.','-') + ":" + mongo_port) %}
{%- endif -%}
{%- endfor -%}
{%- endif -%}
{%- endfor -%}
{%- else -%}
{%- set hosts = mongo_cluster_members -%}
{%- endif -%}
config = {_id: '{{ mongo_repl_set }}', members: [
{% for host in mongo_cluster_members %}
{%- for host in hosts -%}
{_id: {{ loop.index }}, host: '{{ host }}'}{% if not loop.last %},{% endif %}
{% endfor %}
{%- endfor -%}
]};
rs.initiate(config)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment