2014-06-04 19:03:58 +04:00
|
|
|
---
|
2015-04-06 23:37:34 +02:00
|
|
|
|
2015-02-13 18:27:38 +06:00
|
|
|
- name: Create keyFile
|
|
|
|
copy:
|
2016-04-17 19:43:00 +06:00
|
|
|
dest: "{{ mongodb_security_keyfile }}"
|
2015-02-13 18:27:38 +06:00
|
|
|
content: "{{ mongodb_keyfile_content }}"
|
|
|
|
owner: "{{ mongodb_user }}"
|
|
|
|
group: "root"
|
|
|
|
mode: 0600
|
2016-04-17 19:43:00 +06:00
|
|
|
when: mongodb_replication_replset and mongodb_replication_replset != ''
|
2015-02-13 18:27:38 +06:00
|
|
|
|
2015-06-22 14:59:25 +06:00
|
|
|
- name: set mongodb gid
|
|
|
|
group: name=mongodb gid={{ mongodb_gid }} state=present
|
|
|
|
when: mongodb_gid
|
2015-02-17 19:17:50 +06:00
|
|
|
|
2015-06-22 14:59:25 +06:00
|
|
|
- name: set mongodb uid
|
|
|
|
user: name=mongodb uid={{ mongodb_uid }} group=mongodb state=present
|
|
|
|
when: mongodb_uid
|
2014-12-11 22:09:31 +03:00
|
|
|
|
2015-06-22 14:59:25 +06:00
|
|
|
- name: reset mongodb folder and subfolders with new uid
|
2016-04-17 19:43:00 +06:00
|
|
|
file: path={{ mongodb_storage_dbpath }} owner=mongodb group=mongodb follow=yes recurse=yes state=directory
|
2015-06-22 14:59:25 +06:00
|
|
|
when: mongodb_uid
|
2014-12-11 22:09:31 +03:00
|
|
|
|
2015-04-04 14:26:31 +03:00
|
|
|
- name: Create log dir if missing
|
2016-04-17 19:43:00 +06:00
|
|
|
file: state=directory recurse=yes dest={{ mongodb_systemlog_path|dirname }} owner={{ mongodb_user }} group={{mongodb_user}} mode=0755
|
2018-01-19 12:05:24 -02:00
|
|
|
when: mongodb_systemlog_destination == "file"
|
2015-04-04 14:26:31 +03:00
|
|
|
|
2015-06-16 17:32:39 +06:00
|
|
|
- name: Check than logfile exists
|
2016-04-17 19:43:00 +06:00
|
|
|
stat: path={{ mongodb_systemlog_path }}
|
2015-06-16 17:32:39 +06:00
|
|
|
register: logfile_stat
|
2018-01-19 12:05:24 -02:00
|
|
|
when: mongodb_systemlog_destination == "file"
|
2015-06-16 17:32:39 +06:00
|
|
|
|
2015-04-04 14:26:31 +03:00
|
|
|
- name: Create log if missing
|
2016-04-17 19:43:00 +06:00
|
|
|
file: state=touch dest={{ mongodb_systemlog_path }} owner={{ mongodb_user }} group={{mongodb_user}} mode=0755
|
2019-04-25 11:02:09 -03:00
|
|
|
when: ( mongodb_systemlog_destination == "file"
|
|
|
|
and logfile_stat is defined
|
|
|
|
and not logfile_stat.stat.exists )
|
2014-12-26 18:32:50 +03:00
|
|
|
|
2016-04-27 14:14:55 +10:00
|
|
|
- name: Ensure dbpath directory
|
|
|
|
file:
|
|
|
|
path: "{{ mongodb_storage_dbpath }}"
|
|
|
|
state: directory
|
|
|
|
owner: "{{ mongodb_user }}"
|
2019-01-29 08:07:45 -05:00
|
|
|
setype: 'mongod_var_lib_t'
|
2016-04-27 14:14:55 +10:00
|
|
|
recurse: yes
|
|
|
|
|
2015-02-17 13:28:24 +06:00
|
|
|
- name: Configure mongodb
|
2015-04-04 14:26:31 +03:00
|
|
|
template: src=mongod.conf.j2 dest=/etc/mongod.conf backup=yes owner=root group=root mode=0644
|
2015-02-17 13:28:24 +06:00
|
|
|
register: config_result
|
|
|
|
|
|
|
|
- name: mongodb restart
|
|
|
|
service: name={{ mongodb_daemon_name }} state=restarted
|
2019-04-09 10:37:54 +02:00
|
|
|
when: config_result is changed and mongodb_manage_service
|
2016-03-04 01:18:01 +06:00
|
|
|
|
2016-05-04 11:09:05 +02:00
|
|
|
- name: Ensure service is started
|
|
|
|
service: name={{ mongodb_daemon_name }} state=started
|
|
|
|
|
2016-03-04 01:18:01 +06:00
|
|
|
- name: Wait when mongodb is started
|
|
|
|
wait_for:
|
2017-03-11 16:38:48 +03:00
|
|
|
host: "{{ item }}"
|
2016-04-17 19:43:00 +06:00
|
|
|
port: "{{ mongodb_net_port }}"
|
2016-03-04 01:18:01 +06:00
|
|
|
timeout: 120
|
2017-03-11 16:38:48 +03:00
|
|
|
with_items: "{{ mongodb_net_bindip.split(',') | map('replace', '0.0.0.0', '127.0.0.1') | list }}"
|