--- - name: Move back mongod.conf template: src=mongod_init.conf.j2 dest=/etc/mongod.conf owner=root group=root mode=0644 - name: Restart mongodb service service: name={{ mongodb_daemon_name }} state=restarted when: mongodb_manage_service - name: wait MongoDB port is listening wait_for: host=127.0.0.1 port="{{ mongodb_net_port }}" delay=5 state=started - name: get pid of mongodb for non daemon mode shell: "pidof mongod" register: pidof_mongod when: mongodb_manage_service == false ignore_errors: yes - name: start mongodb daemon shell: "LC_ALL=C /usr/bin/mongod --config /etc/mongod.conf --fork" when: mongodb_manage_service == false and pidof_mongod.rc == 1 - name: create administrative user siteUserAdmin mongodb_user: database: admin name: "{{ item.name }}" password: "{{ item.password }}" update_password: "{{ mongodb_user_update_password }}" roles: "{{ item.roles }}" login_port: "{{ mongodb_net_port }}" with_items: - { name: "{{ mongodb_user_admin_name }}", password: "{{ mongodb_user_admin_password }}", roles: "userAdminAnyDatabase" } no_log: true - name: create administrative user siteRootAdmin mongodb_user: database: admin name: "{{ item.name }}" password: "{{ item.password }}" update_password: "{{ mongodb_user_update_password }}" roles: "{{ item.roles }}" login_port: "{{ mongodb_net_port }}" with_items: - { name: "{{ mongodb_root_admin_name }}", password: "{{ mongodb_root_admin_password }}", roles: "root" } no_log: true - name: create backup user "backupuser" mongodb_user: database: admin name: "{{ item.name }}" password: "{{ item.password }}" update_password: "{{ mongodb_user_update_password }}" roles: "{{ item.roles }}" login_port: "{{ mongodb_net_port }}" with_items: - { name: "{{ mongodb_root_backup_name }}", password: "{{ mongodb_root_backup_password }}", roles: "backup,clusterMonitor" } no_log: true - name: Move back mongod.conf template: src=mongod.conf.j2 dest=/etc/mongod.conf owner=root group=root mode=0644 - name: Restart mongodb service service: name={{ mongodb_daemon_name }} state=restarted when: mongodb_manage_service - name: Wait MongoDB port is listening wait_for: host="{{ item }}" port="{{ mongodb_net_port }}" delay=5 state=started with_items: "{{ mongodb_net_bindip.split(',') | map('replace', '0.0.0.0', '127.0.0.1') | list }}" - name: stop mongodb if was not started shell: "kill {{ pidof_mongod.stdout }}" when: mongodb_manage_service == false and pidof_mongod.rc == 0