--- # tasks file for ansible-role-mongod2.6 - assert: that: - ansible_os_family == 'Debian' - ansible_distribution_release == 'trusty' - mongod_config is defined - name: Add APT repository key apt_key: keyserver: hkp://keyserver.ubuntu.com:80 id: 7F0CEB10 - name: Add APT repository apt_repository: repo: deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen state: present update_cache: yes - name: APT install with_items: - mongodb-org-server - mongodb-org-shell - mongodb-org-tools - python-pymongo apt: name: '{{ item }}' state: present update_cache: yes cache_valid_time: 3600 - name: Enable service service: name: mongod enabled: yes - name: Set mail alias when: mongod_mail_alias is defined lineinfile: dest: /etc/aliases regexp: mongodb create: yes line: 'mongod: {{ mongod_mail_alias }}' - name: Create dbpath when: mongod_config.dbpath is defined file: dest: '{{ mongod_config.dbpath }}' owner: mongodb group: mongodb state: directory mode: 0o0750 - name: Create key file when: mongod_keyFile is defined template: dest: /etc/mongod.key src: mongod.key owner: mongodb group: mongodb mode: 0o0400 - name: Configure with_dict: '{{ mongod_config }}' ini_file: dest: /etc/mongod.conf option: '{{ item.key }}' value: '{{ item.value }}' state: present notify: - Restart mongod - meta: flush_handlers - name: Wait for service to start wait_for: port: 27017 - name: Login without authentication (will fail if accounts were created) command: mongo admin --eval 'help' ignore_errors: True changed_when: False register: mongod_login_noauth - name: Set fact if authentication is required set_fact: mongod_auth: '{{ mongod_login_noauth|failed }}' - name: Check if part of replica set - name: Find replica set primary - name: Initialize replica set - name: Add members - name: Add admin account