64 lines
2.1 KiB
YAML
64 lines
2.1 KiB
YAML
---
|
|
|
|
- name: Create keyFile
|
|
copy:
|
|
dest: "{{ mongodb_security_keyfile }}"
|
|
content: "{{ mongodb_keyfile_content }}"
|
|
owner: "{{ mongodb_user }}"
|
|
group: "root"
|
|
mode: 0600
|
|
when: mongodb_replication_replset and mongodb_replication_replset != ''
|
|
|
|
- name: set mongodb gid
|
|
group: name=mongodb gid={{ mongodb_gid }} state=present
|
|
when: mongodb_gid
|
|
|
|
- name: set mongodb uid
|
|
user: name=mongodb uid={{ mongodb_uid }} group=mongodb state=present
|
|
when: mongodb_uid
|
|
|
|
- name: reset mongodb folder and subfolders with new uid
|
|
file: path={{ mongodb_storage_dbpath }} owner=mongodb group=mongodb follow=yes recurse=yes state=directory
|
|
when: mongodb_uid
|
|
|
|
- name: Create log dir if missing
|
|
file: state=directory recurse=yes dest={{ mongodb_systemlog_path|dirname }} owner={{ mongodb_user }} group={{mongodb_user}} mode=0755
|
|
when: mongodb_systemlog_destination == "file"
|
|
|
|
- name: Check than logfile exists
|
|
stat: path={{ mongodb_systemlog_path }}
|
|
register: logfile_stat
|
|
when: mongodb_systemlog_destination == "file"
|
|
|
|
- name: Create log if missing
|
|
file: state=touch dest={{ mongodb_systemlog_path }} owner={{ mongodb_user }} group={{mongodb_user}} mode=0755
|
|
when: ( logfile_stat is defined
|
|
and not logfile_stat.stat.exists
|
|
and mongodb_systemlog_destination == "file" )
|
|
|
|
- name: Ensure dbpath directory
|
|
file:
|
|
path: "{{ mongodb_storage_dbpath }}"
|
|
state: directory
|
|
owner: "{{ mongodb_user }}"
|
|
setype: 'mongod_var_lib_t'
|
|
recurse: yes
|
|
|
|
- name: Configure mongodb
|
|
template: src=mongod.conf.j2 dest=/etc/mongod.conf backup=yes owner=root group=root mode=0644
|
|
register: config_result
|
|
|
|
- name: mongodb restart
|
|
service: name={{ mongodb_daemon_name }} state=restarted
|
|
when: config_result is is changed and mongodb_manage_service
|
|
|
|
- name: Ensure service is started
|
|
service: name={{ mongodb_daemon_name }} state=started
|
|
|
|
- name: Wait when mongodb is started
|
|
wait_for:
|
|
host: "{{ item }}"
|
|
port: "{{ mongodb_net_port }}"
|
|
timeout: 120
|
|
with_items: "{{ mongodb_net_bindip.split(',') | map('replace', '0.0.0.0', '127.0.0.1') | list }}"
|