xoxys.mongodb/tasks/auth.yml

50 lines
1.1 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
2021-02-06 14:53:36 +00:00
mode: 0640
2019-01-12 13:40:16 +00:00
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
2021-02-06 14:53:36 +00:00
mode: 0640
2019-01-12 13:40:16 +00:00
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
2021-02-06 14:53:36 +00:00
mode: 0640
2019-01-12 13:40:16 +00:00
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