create_mongo_users.yml 1.36 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
#
# This play expects PyMongo to be installed locally.  You need to provide
# the hostname or IP address of one of the mongo hosts, 
#
# ansible-playbook -i localhost, create_mongo_users.yml -e@edx.yml -e@stage-edx.yml -e@db/edxapp-mongo.yml
#
# edxapp-mongo.yml should define MONGO_USERS with the following format
#
# MONGO_USERS:
#   - user: edxapp001
#     password: secret
#     database: edxapp
#     roles: readWrite
# 
# It should also define a login_host and repl_set.  You can set login_host to
# be any member of your cluster as this code will find and connect to the
# primary.
#
# login_host: 10.17.90.123
# repl_set: prod-edx-edxapp

- name: Create mongo users
  hosts: all
  gather_facts: False
  connection: local
# This allows you to use your virtualenv's pymongo instead of installing it globally
  vars:
    ansible_python_interpreter: "/usr/bin/env python"
  tasks:
    - name: install python mongo module
      pip: name=pymongo state=present

    - name: create a mongodb user
      mongodb_user:
        database: "{{ item.database }}"
        login_user: "{{ MONGO_ADMIN_USER }}"
        login_password: "{{ MONGO_ADMIN_PASSWORD }}"
        login_host: "{{ login_host }}"
        name: "{{ item.user }}"
        password: "{{ item.password }}"
        roles: "{{ item.roles }}"
        state: present
        replica_set: "{{ repl_set }}"
      with_items: MONGO_USERS