ansible-role-mongodb/tasks/auth_initialization.yml

84 lines
2.6 KiB
YAML
Raw Normal View History

2015-02-09 12:39:32 +00:00
---
- name: Move back mongod.conf
template: src=mongod_init.conf.j2 dest=/etc/mongod.conf owner=root group=root mode=0644
2015-02-09 12:39:32 +00:00
- name: Restart mongodb service
service: name={{ mongodb_daemon_name }} state=restarted
when: mongodb_manage_service
2015-11-22 09:58:35 +00:00
- name: wait MongoDB port is listening
2016-04-17 13:43:00 +00:00
wait_for: host=127.0.0.1 port="{{ mongodb_net_port }}" delay=5 state=started
2015-11-22 09:58:35 +00:00
- 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
2015-03-02 10:07:44 +00:00
- name: create administrative user siteUserAdmin
2015-02-10 07:45:52 +00:00
mongodb_user:
2015-02-09 12:39:32 +00:00
database: admin
name: "{{ item.name }}"
password: "{{ item.password }}"
2016-04-17 13:43:00 +00:00
update_password: "{{ mongodb_user_update_password }}"
2015-02-09 12:39:32 +00:00
roles: "{{ item.roles }}"
2016-04-17 13:43:00 +00:00
login_port: "{{ mongodb_net_port }}"
2015-02-09 12:39:32 +00:00
with_items:
2015-02-10 07:45:52 +00:00
- {
2015-03-02 10:07:44 +00:00
name: "{{ mongodb_user_admin_name }}",
password: "{{ mongodb_user_admin_password }}",
roles: "userAdminAnyDatabase"
2015-02-09 12:39:32 +00:00
}
no_log: true
2015-02-09 12:39:32 +00:00
2015-03-02 10:07:44 +00:00
- name: create administrative user siteRootAdmin
2015-02-10 07:45:52 +00:00
mongodb_user:
2015-02-09 12:39:32 +00:00
database: admin
name: "{{ item.name }}"
password: "{{ item.password }}"
2016-04-17 13:43:00 +00:00
update_password: "{{ mongodb_user_update_password }}"
2015-02-09 12:39:32 +00:00
roles: "{{ item.roles }}"
2016-04-17 13:43:00 +00:00
login_port: "{{ mongodb_net_port }}"
2015-02-09 12:39:32 +00:00
with_items:
2015-02-10 07:45:52 +00:00
- {
2015-03-02 10:07:44 +00:00
name: "{{ mongodb_root_admin_name }}",
password: "{{ mongodb_root_admin_password }}",
roles: "root"
2015-02-09 12:39:32 +00:00
}
no_log: true
2015-02-09 12:39:32 +00:00
2015-11-17 06:14:41 +00:00
- name: create backup user "backupuser"
mongodb_user:
database: admin
name: "{{ item.name }}"
password: "{{ item.password }}"
2016-04-18 13:08:24 +00:00
update_password: "{{ mongodb_user_update_password }}"
2015-11-17 06:14:41 +00:00
roles: "{{ item.roles }}"
2016-04-18 13:08:24 +00:00
login_port: "{{ mongodb_net_port }}"
2015-11-17 06:14:41 +00:00
with_items:
- {
name: "{{ mongodb_root_backup_name }}",
password: "{{ mongodb_root_backup_password }}",
roles: "backup,clusterMonitor"
}
no_log: true
2015-11-17 06:14:41 +00:00
- 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 }}"
2015-11-22 09:58:35 +00:00
- name: stop mongodb if was not started
shell: "kill {{ pidof_mongod.stdout }}"
when: mongodb_manage_service == false and pidof_mongod.rc == 0