# config/roles/mongodb/tasks/main.yml
# Install and configure MongoDB

- name: Fetch apt signing key
  apt_key: keyserver=keyserver.ubuntu.com id=7F0CEB10 state=present

- name: Add 10gen Mongo repo
  apt_repository: >
    repo='deb http://repo.mongodb.org/apt/ubuntu trusty/mongodb-org/3.0 multiverse'
    state=present

- name: Update apt cache
  apt: update_cache=yes

- name: Install MongoDB
  apt: name=mongodb-org state=latest

- name: Start mongod
  service: name=mongod state=started

- name: Bind mongo to IP
  lineinfile: dest=/etc/mongod.conf regexp="^bind_ip =" line="bind_ip = {{ mongo_bind_ip }}"
  notify:
    - restart mongod

- name: Install pip (for adding mongo user)
  apt: name=python-pip state=latest

- name: Install pymongo (for adding mongo user)
  pip: name=pymongo state=latest

- name: Add mongo user
  mongodb_user: >
    database={{ mongo_database }}
    name={{ mongo_user }}
    password={{ mongo_password }}
    state=present
# config/roles/mongodb/tasks/main.yml
# Install and configure MongoDB

- name: Fetch apt signing key
  apt_key: keyserver=keyserver.ubuntu.com id=7F0CEB10 state=present

- name: Add 10gen Mongo repo
  apt_repository: >
    repo='deb http://repo.mongodb.org/apt/ubuntu trusty/mongodb-org/3.0 multiverse'
    state=present

- name: Update apt cache
  apt: update_cache=yes

- name: Install MongoDB
  apt: name=mongodb-org state=latest

- name: Start mongod
  service: name=mongod state=started

- name: Bind mongo to IP
  lineinfile: "dest=/etc/mongod.conf regexp=\"^  bindIp:\" line=\"  bindIp: {{ mongo_bind_ip }}\""
  notify:
    - restart mongod

- name: Install pip (for adding mongo user)
  apt: name=python-pip state=latest

- name: Install pymongo (for adding mongo user)
  pip: name=pymongo state=latest

- name: Add mongo user
  mongodb_user: >
    database={{ mongo_database }}
    name={{ mongo_user }}
    password={{ mongo_password }}
    state=present
Change mongod.conf bind_ip to bindIP
Change mongod.conf bind_ip to bindIP

- MongoDb changed bind_ip format at https://github.com/mongodb/mongo/commit/a459fcf9e758ebf6ef8c752d1972226121eda85d#diff-84a3d09123a9805ab8dc7eedde70c8df
