2014-06-04 19:03:58 +04:00
|
|
|
---
|
|
|
|
|
2019-06-05 15:16:18 +03:00
|
|
|
- name: Check value of variable mongodb_net_ssl_host
|
|
|
|
fail:
|
|
|
|
msg: 'Set mongodb_net_ssl_mode is preferSSL or set valid hostname for mongodb_net_ssl_host!'
|
|
|
|
when: ( mongodb_net_ssl_mode == 'requireSSL'
|
|
|
|
and mongodb_net_ssl_host == '' )
|
|
|
|
|
|
|
|
- name: Check value of variable mongodb_login_host
|
|
|
|
fail:
|
|
|
|
msg: 'Set mongodb_login_host equal mongodb_net_ssl_host!'
|
|
|
|
when: ( mongodb_net_ssl_mode == 'requireSSL'
|
|
|
|
and mongodb_net_ssl_host != mongodb_login_host
|
|
|
|
and not mongodb_replication_replset )
|
|
|
|
|
2016-04-27 14:45:25 +10:00
|
|
|
- name: Include OS-specific variables
|
|
|
|
include_vars: "{{ item }}"
|
|
|
|
with_first_found:
|
2018-02-23 00:43:04 +07:00
|
|
|
- "{{ ansible_distribution_release }}.yml"
|
2016-04-27 14:45:25 +10:00
|
|
|
- "{{ ansible_distribution }}.yml"
|
|
|
|
- "{{ ansible_os_family }}.yml"
|
|
|
|
|
2018-02-23 00:43:04 +07:00
|
|
|
- name: Include installation tasks
|
2019-05-17 11:57:53 +02:00
|
|
|
include: "{{ item }}"
|
|
|
|
with_first_found:
|
|
|
|
- "install.{{ ansible_distribution | lower }}.yml"
|
|
|
|
- "install.{{ ansible_os_family | lower }}.yml"
|
2015-03-04 11:05:08 +01:00
|
|
|
tags: [mongodb]
|
2015-02-17 15:01:36 +06:00
|
|
|
|
2016-04-17 19:43:00 +06:00
|
|
|
- name: Include configuration.yml
|
2018-02-21 01:23:43 +07:00
|
|
|
include: configure.yml
|
2015-03-04 11:05:08 +01:00
|
|
|
tags: [mongodb]
|
2015-02-17 15:01:36 +06:00
|
|
|
|
2016-04-17 19:43:00 +06:00
|
|
|
- name: Include replication and auth configuration
|
2018-02-21 01:23:43 +07:00
|
|
|
include: replication_init_auth.yml
|
2019-05-25 22:52:10 -04:00
|
|
|
when: ( mongodb_replication_replset | length > 0
|
2016-04-17 19:43:00 +06:00
|
|
|
and mongodb_security_authorization == 'enabled'
|
2015-06-22 14:59:25 +06:00
|
|
|
and mongodb_master is defined and mongodb_master )
|
|
|
|
tags: [mongodb]
|
|
|
|
|
2016-04-17 19:43:00 +06:00
|
|
|
- name: Include replication configuration
|
2018-02-21 01:23:43 +07:00
|
|
|
include: replication.yml
|
2019-05-27 15:00:59 -04:00
|
|
|
when: mongodb_replication_replset | length > 0
|
2015-06-22 14:59:25 +06:00
|
|
|
tags: [mongodb]
|
|
|
|
|
2017-09-14 10:56:34 +02:00
|
|
|
- name: Check where admin user already exists
|
2016-04-17 19:43:00 +06:00
|
|
|
command: >
|
2019-06-05 15:16:18 +03:00
|
|
|
mongo --quiet {{ '--ssl --host ' + mongodb_net_ssl_host if mongodb_net_ssl_mode == 'requireSSL' else '' }} -u {{ mongodb_user_admin_name }} \
|
2017-04-10 16:04:24 +10:00
|
|
|
-p {{ mongodb_user_admin_password }} --port {{ mongodb_net_port }} --eval 'db.version()' admin
|
2016-04-17 19:43:00 +06:00
|
|
|
register: mongodb_user_admin_check
|
|
|
|
changed_when: false
|
2018-02-15 13:14:31 +07:00
|
|
|
check_mode: no
|
2016-04-17 19:43:00 +06:00
|
|
|
ignore_errors: true
|
|
|
|
when: ( mongodb_security_authorization == 'enabled'
|
2019-05-21 15:42:02 -04:00
|
|
|
and not mongodb_replication_replset )
|
2017-09-14 10:56:34 +02:00
|
|
|
no_log: true
|
2015-06-22 14:59:25 +06:00
|
|
|
tags: [mongodb]
|
|
|
|
|
2016-04-17 19:43:00 +06:00
|
|
|
- name: Include authorization configuration
|
2018-02-21 01:23:43 +07:00
|
|
|
include: auth_initialization.yml
|
2016-04-17 19:43:00 +06:00
|
|
|
when: ( mongodb_security_authorization == 'enabled'
|
2019-05-21 15:42:02 -04:00
|
|
|
and not mongodb_replication_replset
|
2016-04-17 19:43:00 +06:00
|
|
|
and mongodb_user_admin_check.rc != 0 )
|
|
|
|
tags: [mongodb]
|
|
|
|
|
2016-04-17 23:18:31 +06:00
|
|
|
- name: create normal users with replicaset
|
2019-05-23 00:37:39 -04:00
|
|
|
mongodb_user:
|
2016-04-17 19:43:00 +06:00
|
|
|
database: "{{ item.database }}"
|
|
|
|
name: "{{ item.name }}"
|
|
|
|
password: "{{ item.password }}"
|
|
|
|
update_password: "{{ mongodb_user_update_password }}"
|
|
|
|
roles: "{{ item.roles }}"
|
|
|
|
login_user: "{{ mongodb_user_admin_name }}"
|
|
|
|
login_password: "{{ mongodb_user_admin_password }}"
|
2016-04-17 23:18:31 +06:00
|
|
|
login_port: "{{ mongodb_login_port|default(27017) }}"
|
|
|
|
login_host: "{{ mongodb_login_host|default('localhost') }}"
|
2019-06-05 15:16:18 +03:00
|
|
|
ssl: "{{ True if mongodb_net_ssl_mode == 'requireSSL' else False }}"
|
2016-04-17 19:43:00 +06:00
|
|
|
with_items:
|
|
|
|
- "{{ mongodb_users | default([]) }}"
|
2016-04-17 23:18:31 +06:00
|
|
|
when: ( mongodb_replication_replset
|
|
|
|
and mongodb_security_authorization == 'enabled'
|
|
|
|
and mongodb_master is defined and mongodb_master )
|
2016-09-21 23:51:38 +02:00
|
|
|
no_log: true
|
2016-04-17 19:43:00 +06:00
|
|
|
tags: [mongodb]
|
|
|
|
|
2016-04-17 23:18:31 +06:00
|
|
|
- name: create normal users without replicaset
|
2019-05-23 00:37:39 -04:00
|
|
|
mongodb_user:
|
2016-04-17 23:18:31 +06:00
|
|
|
database: "{{ item.database }}"
|
|
|
|
name: "{{ item.name }}"
|
|
|
|
password: "{{ item.password }}"
|
|
|
|
update_password: "{{ mongodb_user_update_password }}"
|
|
|
|
roles: "{{ item.roles }}"
|
|
|
|
login_user: "{{ mongodb_user_admin_name }}"
|
|
|
|
login_password: "{{ mongodb_user_admin_password }}"
|
|
|
|
login_port: "{{ mongodb_net_port }}"
|
2019-06-05 15:16:18 +03:00
|
|
|
login_host: "{{ mongodb_login_host|default('localhost') }}"
|
|
|
|
ssl: "{{ True if mongodb_net_ssl_mode == 'requireSSL' else False }}"
|
2016-04-17 23:18:31 +06:00
|
|
|
with_items:
|
|
|
|
- "{{ mongodb_users | default([]) }}"
|
|
|
|
when: ( mongodb_security_authorization == 'enabled'
|
2019-05-21 15:42:02 -04:00
|
|
|
and not mongodb_replication_replset )
|
2016-09-21 23:51:38 +02:00
|
|
|
no_log: true
|
2016-04-17 23:18:31 +06:00
|
|
|
tags: [mongodb]
|
2016-04-17 19:43:00 +06:00
|
|
|
|
2018-09-03 23:06:22 +03:00
|
|
|
- name: create oplog user with replicaset
|
2019-05-23 00:37:39 -04:00
|
|
|
mongodb_user:
|
2018-09-03 23:06:22 +03:00
|
|
|
database: admin
|
|
|
|
user: "{{ item.user }}"
|
|
|
|
password: "{{ item.password }}"
|
|
|
|
update_password: "{{ mongodb_user_update_password }}"
|
|
|
|
roles:
|
|
|
|
- db: local
|
|
|
|
role: read
|
|
|
|
login_user: "{{ mongodb_user_admin_name }}"
|
|
|
|
login_password: "{{ mongodb_user_admin_password }}"
|
|
|
|
login_port: "{{ mongodb_login_port|default(27017) }}"
|
|
|
|
login_host: "{{ mongodb_login_host|default('localhost') }}"
|
2019-06-05 15:16:18 +03:00
|
|
|
ssl: "{{ True if mongodb_net_ssl_mode == 'requireSSL' else False }}"
|
2018-09-03 23:06:22 +03:00
|
|
|
with_items:
|
|
|
|
- "{{ mongodb_oplog_users | default([]) }}"
|
2019-05-27 15:00:59 -04:00
|
|
|
when: ( mongodb_replication_replset | length > 0
|
2018-09-03 23:06:22 +03:00
|
|
|
and mongodb_security_authorization == 'enabled'
|
|
|
|
and mongodb_master is defined and mongodb_master )
|
|
|
|
no_log: false
|
|
|
|
tags: [mongodb]
|
|
|
|
|
2016-04-17 19:43:00 +06:00
|
|
|
- name: Include MMS Agent configuration
|
2018-02-21 01:23:43 +07:00
|
|
|
include: mms-agent.yml
|
2019-05-27 15:00:59 -04:00
|
|
|
when: mongodb_mms_api_key | length > 0
|
2015-03-04 11:05:08 +01:00
|
|
|
tags: [mongodb]
|