Skip to content

Instantly share code, notes, and snippets.

@shadyrudy
Created July 7, 2022 21:16
Show Gist options
  • Save shadyrudy/c01ee2253c9a59bef0b95e8b85f0fb2e to your computer and use it in GitHub Desktop.
Save shadyrudy/c01ee2253c9a59bef0b95e8b85f0fb2e to your computer and use it in GitHub Desktop.
A j2 file for initilzing a MongoDB replica set. Needs an ansible inventory lists of hosts to work.
rs.initiate(
{
_id: "{{ group_names[0] }}",
members: [
{% for h in groups[group_names[0] ]%}
{ _id: {{ loop.index }}, host : "{{ h }}":
{%if hostvars[inventory_hostname].group_names[0].startswith('shard') %}
{{ shard_port }}
{% else %}
{{ cfgserver_port }}
{% endif %}",
priority: 1 } {% if not loop.last %},{% endif %}
{% endfor %}
]
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment