mongodb

Ansible Role - mongodb

Configure the components of a MongoDB Cluster

Available on Ansible Galaxy: isaackehle.mongodb

Variables

Required definitions are as follows:

cfg_server:
  name: "my-cfg" # (Required)
  group: "my-cfg-servers" # (Required) Always pass in the group id used for the config servers

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

Host Definitions typically contain the following:

Replica Set Only

cluster_role: "replicaSet"

Router Server

cluster_role: "router"

Config Server

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

Shard Server

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

Tags/Flags

I use a system of flags and tags that allow the calling playbook to specify which roles are run. As an example:

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 mongo packages
save_config Basic initialization. Stop Services, push service/config files, restart services
reset_storage Clear directories and logs
init_replica_set Initialize the replica set configuration
add_shard_to_cluster Add a replica set of a shard server to the cluster of shard servers
create_database Do an initial database creation, with 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 replicate set to add

Examples

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

    # For when initializing 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

About

Configure the components of a MongoDB Cluster

Install
ansible-galaxy install pgkehle/ansible-mongodb
GitHub repository
License
mit
Downloads
184
Owner