ansible-role-mongodb/tasks/auth_initialization.yml

66 lines
2.0 KiB
YAML
Raw Normal View History

2015-02-09 12:39:32 +00:00
---
- include: auth_initialization_ald.yml
when: ansible_local.mongodb.mongodb.mongodb_login_port is defined
2015-03-02 10:07:44 +00:00
- name: create administrative user siteUserAdmin
2015-02-10 07:45:52 +00:00
mongodb_user:
2015-02-09 12:39:32 +00:00
database: admin
name: "{{ item.name }}"
password: "{{ item.password }}"
roles: "{{ item.roles }}"
2015-02-17 07:26:56 +00:00
login_host: 127.0.0.1
2015-02-09 12:39:32 +00:00
with_items:
2015-02-10 07:45:52 +00:00
- {
2015-03-02 10:07:44 +00:00
name: "{{ mongodb_user_admin_name }}",
password: "{{ mongodb_user_admin_password }}",
roles: "userAdminAnyDatabase"
2015-02-09 12:39:32 +00:00
}
2015-03-02 10:07:44 +00:00
register: useradmin_user_result
when: ansible_local.mongodb.mongodb.mongodb_login_port is undefined
2015-02-09 12:39:32 +00:00
2015-03-02 10:07:44 +00:00
- name: create administrative user siteRootAdmin
2015-02-10 07:45:52 +00:00
mongodb_user:
2015-02-09 12:39:32 +00:00
database: admin
name: "{{ item.name }}"
password: "{{ item.password }}"
roles: "{{ item.roles }}"
2015-02-17 07:26:56 +00:00
login_host: 127.0.0.1
2015-03-03 05:21:25 +00:00
login_user: "{{ mongodb_user_admin_name }}"
login_password: "{{ mongodb_user_admin_password }}"
2015-02-09 12:39:32 +00:00
with_items:
2015-02-10 07:45:52 +00:00
- {
2015-03-02 10:07:44 +00:00
name: "{{ mongodb_root_admin_name }}",
password: "{{ mongodb_root_admin_password }}",
roles: "root"
2015-02-09 12:39:32 +00:00
}
2015-03-02 10:07:44 +00:00
register: rootadmin_user_result
when: ansible_local.mongodb.mongodb.mongodb_login_port is undefined
2015-02-09 12:39:32 +00:00
- name: create normal users
mongodb_user:
database: "{{ item.database }}"
name: "{{ item.name }}"
password: "{{ item.password }}"
roles: "{{ item.roles }}"
2015-02-17 07:26:56 +00:00
replica_set: "{{ mongodb_conf_replSet }}"
login_host: 127.0.0.1
login_user: "{{ mongodb_user_admin_name }}"
login_password: "{{ mongodb_user_admin_password }}"
2015-02-09 12:39:32 +00:00
with_items:
2015-02-10 07:45:52 +00:00
- "{{ mongodb_users }}"
2015-02-17 13:43:13 +00:00
when: mongodb_users is defined and ansible_local.mongodb.mongodb.mongodb_login_port is undefined
- name: Create facts.d directory
file:
state: directory
recurse: yes
path: /etc/ansible/facts.d
when: rootadmin_user_result|changed or useradmin_user_result|changed
- name: Create facts file for mongodb
copy:
dest: /etc/ansible/facts.d/mongodb.fact
2015-03-02 10:07:44 +00:00
content: "[mongodb]\nmongodb_login_port={{ mongodb_conf_port }}\n\n"
when: rootadmin_user_result|changed or useradmin_user_result|changed