2014-06-04 15:03:58 +00:00
|
|
|
---
|
2015-04-06 21:37:34 +00:00
|
|
|
|
2015-05-09 21:15:49 +00:00
|
|
|
- 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
|
|
|
|
|
2015-04-06 15:53:40 +00:00
|
|
|
- name: Register default MongoDB listen IP
|
|
|
|
set_fact: mongodb_listen_ip=127.0.0.1
|
|
|
|
when: ansible_local.mongodb.mongodb.mongodb_listen_ip is undefined
|
2015-04-04 11:26:31 +00:00
|
|
|
|
2015-04-06 15:53:40 +00:00
|
|
|
- name: Register MongoDB listen IP
|
|
|
|
set_fact: mongodb_listen_ip={{ ansible_local.mongodb.mongodb.mongodb_listen_ip }}
|
|
|
|
when: ansible_local.mongodb.mongodb.mongodb_listen_ip is defined
|
2015-04-04 11:26:31 +00:00
|
|
|
|
2015-02-13 12:27:38 +00:00
|
|
|
- name: Create keyFile
|
|
|
|
copy:
|
|
|
|
dest: "{{ mongodb_conf_keyFile }}"
|
|
|
|
content: "{{ mongodb_keyfile_content }}"
|
|
|
|
owner: "{{ mongodb_user }}"
|
|
|
|
group: "root"
|
|
|
|
mode: 0600
|
|
|
|
when: mongodb_conf_replSet != ''
|
|
|
|
|
2014-07-10 16:07:35 +00:00
|
|
|
- name: Configure log rotation
|
|
|
|
template: src=logrotate.conf.j2 dest=/etc/logrotate.d/mongodb.conf
|
|
|
|
when: mongodb_logrotate
|
2014-12-11 19:09:31 +00:00
|
|
|
|
2015-02-17 13:17:50 +00:00
|
|
|
- name: ensure mongodb started and enabled
|
|
|
|
service: name={{ mongodb_daemon_name }} state=started enabled=yes
|
2015-04-06 21:37:34 +00:00
|
|
|
when: mongodb_manage_service
|
|
|
|
|
|
|
|
- name: get pid of mongod
|
|
|
|
command: pidof mongod
|
|
|
|
register: mongod_pid
|
|
|
|
ignore_errors: True
|
|
|
|
|
|
|
|
- name: temporary start mongod if not started
|
|
|
|
command: '/usr/bin/mongod --config /etc/mongod.conf --fork'
|
|
|
|
when: mongod_pid.rc != 0
|
2015-02-17 13:17:50 +00:00
|
|
|
|
2015-02-25 07:57:36 +00:00
|
|
|
- name: wait MongoDB port is listening
|
2015-04-06 15:53:40 +00:00
|
|
|
wait_for: host="{{ mongodb_listen_ip }}" port="{{ mongodb_conf_port }}" delay=10 timeout=60 state=started
|
|
|
|
when: mongodb_force_wait_for_port or "'systemd' in systemd.stdout"
|
2015-02-25 07:57:36 +00:00
|
|
|
|
2015-02-17 13:17:50 +00:00
|
|
|
- include: auth_initialization.yml
|
|
|
|
when: mongodb_conf_auth
|
|
|
|
|
2014-12-11 19:09:31 +00:00
|
|
|
- name: Create mongodb user
|
2014-12-19 14:39:09 +00:00
|
|
|
user: name={{mongodb_user}} group={{mongodb_user}}
|
2014-12-11 19:09:31 +00:00
|
|
|
|
|
|
|
- name: Configure database directory
|
2014-12-19 14:39:09 +00:00
|
|
|
file: state=directory path={{ mongodb_conf_dbpath }} owner={{mongodb_user}} group={{mongodb_user}} mode=0755
|
2014-12-11 19:09:31 +00:00
|
|
|
|
2015-04-04 11:26:31 +00:00
|
|
|
- name: Create log dir if missing
|
|
|
|
file: state=directory recurse=yes dest={{ mongodb_conf_logpath|dirname }} owner={{ mongodb_user }} group={{mongodb_user}} mode=0755
|
|
|
|
|
|
|
|
- name: Create log if missing
|
|
|
|
file: state=touch dest={{ mongodb_conf_logpath }} owner={{ mongodb_user }} group={{mongodb_user}} mode=0755
|
|
|
|
|
|
|
|
- name: Configure log file
|
|
|
|
file: state=file path={{ mongodb_conf_logpath }} owner={{mongodb_user}} group={{mongodb_user}} mode=0755
|
2014-12-26 15:32:50 +00:00
|
|
|
|
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
|
|
|
|
|
2015-04-08 17:18:19 +00:00
|
|
|
- name: Install disable_thp script
|
|
|
|
copy: src=disable_thp.sh dest=/usr/local/bin/disable_thp.sh mode='u=rwx,g=rx,o=rx'
|
|
|
|
when: ansible_os_family == 'Debian' and mongodb_disable_thp
|
|
|
|
|
|
|
|
- name: Disable Linux transparent hugepages now
|
|
|
|
command: /usr/local/bin/disable_thp.sh
|
|
|
|
when: ansible_os_family == 'Debian' and mongodb_disable_thp
|
|
|
|
|
|
|
|
- name: Disable Linux transparent hugepages on boot
|
|
|
|
lineinfile: dest=/etc/rc.local regexp='/usr/local/bin/disable_thp.sh' line='if test -f '/usr/local/bin/disable_thp.sh'; /usr/local/bin/disable_thp.sh; fi'
|
|
|
|
when: ansible_os_family == 'Debian' and mongodb_disable_thp
|
|
|
|
|
2015-04-06 21:37:34 +00:00
|
|
|
- name: get pid of mongod
|
|
|
|
command: pidof mongod
|
|
|
|
register: mongod_new_pid
|
|
|
|
when: mongod_pid.rc != 0
|
|
|
|
|
|
|
|
- name: kill temporary mongod if started
|
|
|
|
command: kill {{ mongod_new_pid.stdout }}
|
|
|
|
when: mongod_pid.rc != 0
|
|
|
|
|
2015-02-17 07:28:24 +00:00
|
|
|
- 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
|