From 36bdb6379be3c2c59b031a8c4920c68e3b186d93 Mon Sep 17 00:00:00 2001 From: AAlvz Date: Tue, 13 Sep 2016 14:27:50 -0500 Subject: [PATCH 1/2] Include creation of users with access to databases --- tasks/configure.yml | 12 ++++++++++++ 1 file changed, 12 insertions(+) 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 From c5197d889a4de940376deba361b23d83baa4853b Mon Sep 17 00:00:00 2001 From: AAlvz Date: Tue, 13 Sep 2016 14:28:16 -0500 Subject: [PATCH 2/2] Include example to create users with database --- defaults/main.yml | 7 +++++++ 1 file changed, 7 insertions(+) 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