xoxys.mongodb/tasks/auth.yml
Robert Kaussow c7419cb829
All checks were successful
continuous-integration/drone/push Build is passing
fix: solve linting issues
2021-02-06 15:53:36 +01:00

50 lines
1.1 KiB
YAML

---
- block:
- name: Backup current config file
copy:
src: /etc/mongod.conf
dest: /etc/mongod.conf.bak
mode: 0640
remote_src: True
changed_when: False
- name: Deploy config file without auth
template:
src: etc/mongod_init.conf.j2
dest: /etc/mongod.conf
mode: 0640
changed_when: False
- name: Restart service to disable auth
service:
name: mongod
state: restarted
changed_when: False
become: True
become_user: root
- name: Create admin user
mongodb_user:
database: admin
name: "{{ mongodb_user_admin_name }}"
password: "{{ mongodb_user_admin_password }}"
roles: readWriteAnyDatabase
state: present
- block:
- name: Restore config file
copy:
src: /etc/mongod.conf.bak
dest: /etc/mongod.conf
mode: 0640
remote_src: True
changed_when: False
- name: Restart service to re-enable auth
service:
name: mongod
state: restarted
changed_when: False
become: True
become_user: root