diff --git a/defaults/main.yml b/defaults/main.yml index c7e6284..0ff2841 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -82,3 +82,10 @@ mongodb_logrotate_options: - dateext - rotate 7 - size 10M + +mongodb_users: + - name: mongo_user + password: password + role: readWrite + databases: + - sample_database diff --git a/tasks/configure.yml b/tasks/configure.yml index 736cf6b..e30aa64 100644 --- a/tasks/configure.yml +++ b/tasks/configure.yml @@ -27,3 +27,15 @@ - name: Run mongoshell commands command: mongo {{ item.key }} --eval "{{ item.value|join('\n') }}" with_dict: "{{mongodb_shell}}" + +- name: Create necesary users with access to databases + mongodb_user: + name: "{{ item.0.name }}" + password: "{{ item.0.password }}" + database: "{{ item.1 }}" + state: present + roles: + - { db: "{{ item.1 }}", role: "{{ item.0.role }}" } + with_subelements: + - "{{ mongodb_users }}" + - databases