ansible-role-mongodb/tasks/auth_initialization.yml

62 lines
2.2 KiB
YAML

---
- include: auth_initialization_ald.yml
when: ansible_local.mongodb.mongodb.mongodb_login_port is defined
- name: create administrative user siteUserAdmin
mongodb_user:
database: admin
name: "{{ item.name }}"
password: "{{ item.password }}"
roles: "{{ item.roles }}"
login_host: "{{ mongodb_listen_ip }}"
with_items:
- {
name: "{{ mongodb_user_admin_name }}",
password: "{{ mongodb_user_admin_password }}",
roles: "userAdminAnyDatabase"
}
register: useradmin_user_result
when: ansible_local.mongodb.mongodb.mongodb_login_port is undefined
- name: create administrative user siteRootAdmin
mongodb_user:
database: admin
name: "{{ item.name }}"
password: "{{ item.password }}"
roles: "{{ item.roles }}"
login_host: "{{ mongodb_listen_ip }}"
login_user: "{{ mongodb_user_admin_name }}"
login_password: "{{ mongodb_user_admin_password }}"
with_items:
- {
name: "{{ mongodb_root_admin_name }}",
password: "{{ mongodb_root_admin_password }}",
roles: "root"
}
register: rootadmin_user_result
when: ansible_local.mongodb.mongodb.mongodb_login_port is undefined
- name: create normal users
mongodb_user:
database: "{{ item.database }}"
name: "{{ item.name }}"
password: "{{ item.password }}"
roles: "{{ item.roles }}"
replica_set: "{{ mongodb_conf_replSet }}"
login_host: "{{ mongodb_listen_ip }}"
login_user: "{{ mongodb_user_admin_name }}"
login_password: "{{ mongodb_user_admin_password }}"
with_items:
- "{{ mongodb_users }}"
when: mongodb_users is defined and ansible_local.mongodb.mongodb.mongodb_login_port is undefined
- name: Create facts.d directory
file: path=/etc/ansible/facts.d state=directory recurse=yes
when: (ansible_local.mongodb.mongodb.mongodb_login_port is undefined) and (rootadmin_user_result|changed or useradmin_user_result|changed or config_result|changed)
- name: Create facts file for mongodb
template: src=mongodb.fact.j2 dest=/etc/ansible/facts.d/mongodb.fact
when: (ansible_local.mongodb.mongodb.mongodb_login_port is undefined) and (rootadmin_user_result|changed or useradmin_user_result|changed or config_result|changed)