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