ansible-role-mongodb/tasks/auth_initialization.yml
2019-05-21 15:42:02 -04:00

70 lines
2.2 KiB
YAML

---
- name: Use different mongod.conf for auth initialization
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: 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 }}"