2014-06-04 15:03:58 +00:00
|
|
|
---
|
|
|
|
|
2015-03-04 10:05:08 +00:00
|
|
|
- name: Check if running on systemd
|
2016-09-21 14:33:05 +00:00
|
|
|
stat: path=/sbin/init
|
|
|
|
register: sbin_init
|
2015-06-16 08:19:58 +00:00
|
|
|
changed_when: false
|
2018-02-15 06:14:31 +00:00
|
|
|
check_mode: no
|
2015-02-25 07:57:36 +00:00
|
|
|
|
2016-09-29 07:09:02 +00:00
|
|
|
- name: Establish some role-related facts
|
|
|
|
set_fact:
|
|
|
|
mongodb_is_systemd: "{{ sbin_init.stat.islnk is defined and sbin_init.stat.islnk }}"
|
|
|
|
mongodb_major_version: "{{ mongodb_version[0:3] }}"
|
2015-02-25 07:57:36 +00:00
|
|
|
|
2018-12-18 09:50:38 +00:00
|
|
|
- name: Disable transparent huge pages on systemd systems
|
|
|
|
include_tasks: disable_transparent_hugepages.yml
|
|
|
|
when:
|
|
|
|
- mongodb_disable_transparent_hugepages
|
|
|
|
- mongodb_is_systemd
|
|
|
|
|
2014-06-04 15:03:58 +00:00
|
|
|
- name: Add APT key
|
2016-04-17 13:43:00 +00:00
|
|
|
apt_key:
|
2017-06-16 11:58:39 +00:00
|
|
|
keyserver: "{{ mongodb_apt_keyserver }}"
|
|
|
|
id: "{{ mongodb_apt_key_id[mongodb_major_version] }}"
|
2016-04-17 13:43:00 +00:00
|
|
|
when: mongodb_package == 'mongodb-org'
|
2016-09-29 07:09:02 +00:00
|
|
|
|
2018-07-12 22:43:56 +00:00
|
|
|
- name: Fail when used wrong mongodb_version variable with Debian Stretch
|
|
|
|
fail:
|
|
|
|
msg: "mongodb_version variable should be '3.2' or '3.6' for Debian Stretch"
|
|
|
|
when: (mongodb_package == 'mongodb-org' and
|
|
|
|
(mongodb_version is not defined
|
|
|
|
or mongodb_repository[mongodb_major_version] is not defined
|
2018-07-13 22:50:23 +00:00
|
|
|
or mongodb_version != '3.6') and ansible_distribution_release == 'stretch')
|
|
|
|
|
2018-07-13 22:59:35 +00:00
|
|
|
- name: Fail when used wrong mongodb_version variable with Ubuntu 18.04
|
2018-07-13 22:50:23 +00:00
|
|
|
fail:
|
|
|
|
msg: "mongodb_version variable should be '3.6' and mongodb_package should be 'mongodb' for Ubuntu 18.04"
|
|
|
|
when: ((mongodb_package == 'mongodb-org' or mongodb_version != '3.6')
|
|
|
|
and ansible_distribution_release == "bionic")
|
2018-07-12 22:43:56 +00:00
|
|
|
|
2016-03-03 19:20:08 +00:00
|
|
|
- name: Fail when used wrong mongodb_version variable
|
|
|
|
fail:
|
2018-07-12 22:43:56 +00:00
|
|
|
msg: "mongodb_version variable should be '3.2', '3.4' or '3.6'"
|
2016-04-17 13:43:00 +00:00
|
|
|
when: (mongodb_package == 'mongodb-org' and
|
|
|
|
(mongodb_version is not defined
|
2016-09-29 07:09:02 +00:00
|
|
|
or mongodb_repository[mongodb_major_version] is not defined))
|
|
|
|
|
2015-01-07 11:31:53 +00:00
|
|
|
- name: Add APT repository
|
2016-03-03 19:20:08 +00:00
|
|
|
apt_repository: repo="{{ mongodb_repository[item] }}" update_cache=yes
|
2016-09-29 07:09:02 +00:00
|
|
|
with_items: "{{ mongodb_major_version }}"
|
2016-04-17 13:43:00 +00:00
|
|
|
when: mongodb_package == 'mongodb-org'
|
2015-01-05 13:37:28 +00:00
|
|
|
|
2015-01-07 11:31:53 +00:00
|
|
|
- name: Install MongoDB package
|
2019-04-09 08:00:17 +00:00
|
|
|
apt:
|
|
|
|
name:
|
|
|
|
- "{{mongodb_package}}"
|
|
|
|
- numactl
|
|
|
|
state: present
|
2015-02-25 07:57:36 +00:00
|
|
|
|
2018-02-23 12:35:03 +00:00
|
|
|
- name: Add systemd configuration if present
|
|
|
|
copy: src=mongodb.service dest=/lib/systemd/system/mongodb.service owner=root group=root mode=0640
|
|
|
|
when: mongodb_is_systemd
|
|
|
|
|
|
|
|
- name: Add symlink for systemd
|
|
|
|
file: src=/lib/systemd/system/mongodb.service dest=/etc/systemd/system/multi-user.target.wants/mongodb.service state=link
|
|
|
|
when: mongodb_is_systemd
|
|
|
|
notify: reload systemd
|
|
|
|
|
2015-02-26 14:11:22 +00:00
|
|
|
- name: reload systemd
|
|
|
|
shell: systemctl daemon-reload
|
2018-02-23 12:35:03 +00:00
|
|
|
when: mongodb_is_systemd and mongodb_manage_service
|
|
|
|
|
|
|
|
- meta: flush_handlers
|
2016-09-29 07:09:02 +00:00
|
|
|
when: mongodb_is_systemd
|
2015-01-05 13:37:28 +00:00
|
|
|
|
2015-04-06 16:38:52 +00:00
|
|
|
- name: Install PyMongo package
|
|
|
|
apt: pkg=python-pymongo state=latest
|
|
|
|
when: not mongodb_pymongo_from_pip
|
|
|
|
|
2015-04-06 16:51:47 +00:00
|
|
|
- name: Install PIP
|
2019-04-09 08:00:17 +00:00
|
|
|
apt:
|
|
|
|
pkg:
|
|
|
|
- python-dev
|
|
|
|
- python-pip
|
2015-04-06 16:38:52 +00:00
|
|
|
when: mongodb_pymongo_from_pip
|
|
|
|
|
|
|
|
- name: Install PyMongo from PIP
|
2018-06-27 09:57:28 +00:00
|
|
|
pip:
|
|
|
|
name: pymongo
|
|
|
|
state: "{{ mongodb_pymongo_pip_version is defined | ternary('present', 'latest') }}"
|
|
|
|
version: "{{ mongodb_pymongo_pip_version | default(omit) }}"
|
2015-04-06 16:38:52 +00:00
|
|
|
when: mongodb_pymongo_from_pip
|