pgkehle.mongodb

Ansible Role - mongodb

Set up the parts of a MongoDB Cluster

Available on Ansible Galaxy: isaackehle.mongodb

Variables

Here are the required settings:

cfg_server:
  name: "my-cfg" # (Required)
  group: "my-cfg-servers" # (Required) Always provide the group ID for the config servers

replica_set:
  name: "my-cfg" # The name of the replica set for the config server (prefix of fqdn)
  group: "my-cfg-servers" # The group name for all servers in the replica set

Host Definitions usually include:

Replica Set Only

cluster_role: "replicaSet"

Router Server

cluster_role: "router"

Config Server

cluster_role: "config"
replica_set:
  name: "my-cfg" # The name of the replica set for the config server (prefix of fqdn)
  group: "my-cfg-servers" # The group name for all servers in the replica set

Shard Server

cluster_role: "shard"
replica_set:
  name: "db-data" # The name of the replica set for the shard server (prefix of fqdn)
  group: "db-data-servers" # The group name for all servers in the replica set

Tags/Flags

I use tags and flags that let the calling playbook choose which roles to run. For instance:

ansible-playbook playbooks/mongodb.yml -e "{'flags': ['install']}"
ansible-playbook playbooks/mongodb.yml -e "{'flags': ['save_config']}"
ansible-playbook playbooks/mongodb.yml -e "{'flags': ['reset_storage']}"
ansible-playbook playbooks/mongodb.yml -e "{'flags': ['init_replica_set']}"
ansible-playbook playbooks/mongodb.yml -e "{'flags': ['add_shard_to_cluster']}"
ansible-playbook playbooks/mongodb.yml -e "{'flags': ['create_database']}"

Flags and Variables

Flag Purpose
install Install MongoDB packages
save_config Basic setup. Stop Services, copy config files, restart services
reset_storage Clear directories and logs
init_replica_set Set up the replica set configuration
add_shard_to_cluster Add a replica set of a shard server to the cluster
create_database Create an initial database with a username and password
vars:
  flags: ["install"]
  new_shard:
    name: # Name of the replica set to add to the config server
    server: # One of the members of the new replica set

Examples

- hosts: all
  vars:
    auth_db: ""
    adminUser: ""
    adminPass: ""
    tgt_db: ""
    userName: ""
    userPass: ""
    roles: ["readWrite", "userAdmin"]

    # For when setting up the replica set
    adminUser: ''
    adminPass: ''

  roles:
    - { role: isaackehle.mongodb, flags: ['install'] }
    - { role: isaackehle.mongodb, flags: ['save_config'] }
    - { role: isaackehle.mongodb, flags: ['reset_storage'] }
    - { role: isaackehle.mongodb, flags: ['init_replica_set'] }
    - { role: isaackehle.mongodb, flags: ['add_shard_to_cluster'] }
    - { role: isaackehle.mongodb, flags: ['create_database'] }

Linting

yamllint -c yamllint.yaml .
ansible-lint .

License

MIT

Author Information

Isaac Kehle @isaackehle (twitter, github, linkedin)

References

Informazioni sul progetto

Configure the components of a MongoDB Cluster

Installa
ansible-galaxy install pgkehle.mongodb
Licenza
mit
Download
194
Proprietario