/ansible-mongodb

Configure the components of a MongoDB Mesh Network

Primary LanguageRubyMIT LicenseMIT

Ansible Role - mongodb

Configure the components of a MongoDB Cluster

Available on Ansible Galaxy: pgkehle.mongodb

Variables

Required definitions are as follows:

cfg_server_name:        "app-cfg"           # (Required)   
cfg_server_group_id:    "app-cfg-servers"   # (Required) Always pass in the group id used for the config servers 
replica_set_group_id:   "app-shd00-servers" # (Optional) If initializing a replica set as part of a MongoDB cluster

Host Definitions typically contain the following:

Query Server:

mongodb_type:           "shard"
cluster_role:           "querysvr"

Config Server:

mongodb_type:           "daemon"
cluster_role:           "configsvr"
replica_set_name:       "app-cfg"               # name of the replica set for the config server (prefix of fqdn)
replica_set_group_id:   "app-cfg-servers"       # group name for all servers in the replica set

Shard Server:

mongodb_type:           "daemon"
cluster_role:           "shardsvr"
replica_set_name:       "app-shd00"             # name of the replica set for the shard server (prefix of fqdn)
replica_set_group_id:   "app-shd00-servers"     # group name for all servers in the replica set

Flags and Variables

vars:
  flags:
    - init:           # Install mongo packages
    - config_save:    # Basic initialization.  Stop Services, push service/config files, restart services
    - storage_init:   # Clear directories and logs
    - rs_init:        # Initialize the replica set configuration
    - rs_shards:      # Add shard servers (replica sets) to the cluster
    - db_create:      # Do initial db creation

Examples

- hosts: all
  vars: 
    app_users:
      - { db_name: "", user: "", pwd: "", roles: ["readWrite", "userAdmin"] } 

  roles:
    - { role: pgkehle.mongodb, flags: ['init'] }        
    - { role: pgkehle.mongodb, flags: ['config_save'] }        
    - { role: pgkehle.mongodb, flags: ['storage_init'] }        
    - { role: pgkehle.mongodb, flags: ['rs_init'] }        
    - { role: pgkehle.mongodb, flags: ['rs_shards'] }        
    - { role: pgkehle.mongodb, flags: ['db_create'] }        
      
ansible-playbook playbooks/mongodb.yml -e "{'flags': ['init']}"
ansible-playbook playbooks/mongodb.yml -e "{'flags': ['config_save']}"
ansible-playbook playbooks/mongodb.yml -e "{'flags': ['storage_init']}"
ansible-playbook playbooks/mongodb.yml -e "{'flags': ['rs_init']}"
ansible-playbook playbooks/mongodb.yml -e "{'flags': ['rs_shards']}"
ansible-playbook playbooks/mongodb.yml -e "{'flags': ['db_create']}"

License

MIT

Author Information

Paul Kehle
@pgkehle (twitter, github, linkedin)

For local development testing

rsync -av --delete ~/code/ansible-mongodb/* ~/.ansible/roles/pgkehle.mongodb

References