xoxys.mongodb/tasks/auth.yml

48 lines
1.0 KiB
YAML
Raw Normal View History

2018-07-07 16:53:03 +00:00
---
- block:
2019-01-12 13:40:16 +00:00
- name: Backup current config file
copy:
src: /etc/mongod.conf
dest: /etc/mongod.conf.bak
remote_src: True
changed_when: False
2018-07-07 16:53:03 +00:00
2019-01-12 13:40:16 +00:00
- name: Deploy config file without auth
template:
src: etc/mongod_init.conf.j2
dest: /etc/mongod.conf
mode: 0644
changed_when: False
2018-07-07 16:53:03 +00:00
2019-01-12 13:40:16 +00:00
- name: Restart service to disable auth
service:
name: mongod
state: restarted
changed_when: False
2018-07-07 16:53:03 +00:00
become: True
2019-01-12 13:40:16 +00:00
become_user: root
2018-07-07 16:53:03 +00:00
- name: Create admin user
mongodb_user:
database: admin
name: "{{ mongodb_user_admin_name }}"
password: "{{ mongodb_user_admin_password }}"
roles: readWriteAnyDatabase
state: present
- block:
2019-01-12 13:40:16 +00:00
- name: Restore config file
copy:
src: /etc/mongod.conf.bak
dest: /etc/mongod.conf
remote_src: True
changed_when: False
2018-07-07 16:53:03 +00:00
2019-01-12 13:40:16 +00:00
- name: Restart service to re-enable auth
service:
name: mongod
state: restarted
changed_when: False
2018-07-07 16:53:03 +00:00
become: True
2019-01-12 13:40:16 +00:00
become_user: root