2014-06-04 19:03:58 +04:00
|
|
|
---
|
2016-09-29 09:09:02 +02:00
|
|
|
- name: Establish some role-related facts
|
|
|
|
set_fact:
|
|
|
|
mongodb_major_version: "{{ mongodb_version[0:3] }}"
|
2015-02-25 08:57:36 +01:00
|
|
|
|
2018-12-18 10:50:38 +01:00
|
|
|
- name: Disable transparent huge pages on systemd systems
|
|
|
|
include_tasks: disable_transparent_hugepages.yml
|
|
|
|
when:
|
2019-05-25 22:52:10 -04:00
|
|
|
- mongodb_disable_transparent_hugepages | bool
|
2019-05-21 15:42:02 -04:00
|
|
|
- ansible_service_mgr == "systemd"
|
2018-12-18 10:50:38 +01:00
|
|
|
|
2014-06-04 19:03:58 +04:00
|
|
|
- name: Add APT key
|
2016-04-17 19:43:00 +06:00
|
|
|
apt_key:
|
2017-06-16 13:58:39 +02:00
|
|
|
keyserver: "{{ mongodb_apt_keyserver }}"
|
|
|
|
id: "{{ mongodb_apt_key_id[mongodb_major_version] }}"
|
2016-04-17 19:43:00 +06:00
|
|
|
when: mongodb_package == 'mongodb-org'
|
2016-09-29 09:09:02 +02:00
|
|
|
|
2018-07-12 18:43:56 -04:00
|
|
|
- name: Fail when used wrong mongodb_version variable with Debian Stretch
|
|
|
|
fail:
|
2019-05-09 22:57:34 +02:00
|
|
|
msg: "mongodb_version variable should be '3.6' or '4.0' for Debian Stretch"
|
2019-05-27 15:00:59 -04:00
|
|
|
when:
|
|
|
|
- mongodb_package == 'mongodb-org'
|
|
|
|
- (mongodb_major_version != '3.6' and mongodb_major_version != '4.0')
|
|
|
|
- ansible_distribution_release == 'stretch'
|
2018-07-13 18:50:23 -04:00
|
|
|
|
2018-07-13 18:59:35 -04:00
|
|
|
- name: Fail when used wrong mongodb_version variable with Ubuntu 18.04
|
2018-07-13 18:50:23 -04:00
|
|
|
fail:
|
2019-05-20 19:53:38 +02:00
|
|
|
msg: "mongodb_version variable should be '4.0' or else mongodb_package should be 'mongodb' for Ubuntu 18.04"
|
2019-05-21 09:43:56 +02:00
|
|
|
when:
|
|
|
|
- mongodb_package == 'mongodb-org'
|
2019-05-27 15:00:59 -04:00
|
|
|
- mongodb_major_version != '4.0'
|
2019-05-21 09:43:56 +02:00
|
|
|
- ansible_distribution_release == "bionic"
|
2018-07-12 18:43:56 -04:00
|
|
|
|
2016-03-04 01:20:08 +06:00
|
|
|
- name: Fail when used wrong mongodb_version variable
|
|
|
|
fail:
|
2019-05-09 22:57:34 +02:00
|
|
|
msg: "mongodb_version variable should be '3.4', '3.6' or '4.0'"
|
2016-04-17 19:43:00 +06:00
|
|
|
when: (mongodb_package == 'mongodb-org' and
|
|
|
|
(mongodb_version is not defined
|
2016-09-29 09:09:02 +02:00
|
|
|
or mongodb_repository[mongodb_major_version] is not defined))
|
|
|
|
|
2015-01-07 14:31:53 +03:00
|
|
|
- name: Add APT repository
|
2019-05-23 00:37:39 -04:00
|
|
|
apt_repository:
|
|
|
|
repo: "{{ mongodb_repository[version_item] }}"
|
2019-05-27 15:00:59 -04:00
|
|
|
update_cache: true
|
2016-09-29 09:09:02 +02:00
|
|
|
with_items: "{{ mongodb_major_version }}"
|
2019-05-23 00:37:39 -04:00
|
|
|
loop_control:
|
|
|
|
loop_var: version_item
|
2016-04-17 19:43:00 +06:00
|
|
|
when: mongodb_package == 'mongodb-org'
|
2015-01-05 14:37:28 +01:00
|
|
|
|
2019-05-27 15:00:59 -04:00
|
|
|
- name: Install MongoDB package
|
2019-05-21 15:42:02 -04:00
|
|
|
apt:
|
2019-05-27 15:00:59 -04:00
|
|
|
name: "{{ mongodb_package }}{% if (mongodb_version | length > 3) %}={{ mongodb_version }}{% endif %}"
|
2019-05-21 16:39:59 -04:00
|
|
|
state: "{{ mongodb_package_state }}"
|
2019-05-21 15:42:02 -04:00
|
|
|
update_cache: true
|
2015-02-25 08:57:36 +01:00
|
|
|
|
2019-05-27 15:00:59 -04:00
|
|
|
- name: Install numactl package
|
|
|
|
apt:
|
|
|
|
name: numactl
|
|
|
|
state: present
|
|
|
|
|
2018-02-23 19:35:03 +07:00
|
|
|
- name: Add systemd configuration if present
|
2019-06-14 15:10:03 +02:00
|
|
|
copy: src=mongodb.service dest=/lib/systemd/system/{{mongodb_daemon_name}}.service owner=root group=root mode=0644
|
2019-05-21 15:42:02 -04:00
|
|
|
when: ansible_service_mgr == "systemd"
|
2019-05-28 13:39:54 -04:00
|
|
|
notify:
|
|
|
|
- reload systemd
|
2018-02-23 19:35:03 +07:00
|
|
|
|
|
|
|
- name: Add symlink for systemd
|
2019-06-14 15:10:03 +02:00
|
|
|
file: src=/lib/systemd/system/{{mongodb_daemon_name}}.service dest=/etc/systemd/system/multi-user.target.wants/{{mongodb_daemon_name}}.service state=link
|
2019-05-21 15:42:02 -04:00
|
|
|
when: ansible_service_mgr == "systemd"
|
2019-05-23 00:37:39 -04:00
|
|
|
notify:
|
|
|
|
- reload systemd
|
2015-01-05 14:37:28 +01:00
|
|
|
|
2015-04-06 19:38:52 +03:00
|
|
|
- name: Install PyMongo package
|
2019-05-21 15:42:02 -04:00
|
|
|
apt:
|
|
|
|
name: python-pymongo
|
2015-04-06 19:38:52 +03:00
|
|
|
when: not mongodb_pymongo_from_pip
|
|
|
|
|
2015-04-06 19:51:47 +03:00
|
|
|
- name: Install PIP
|
2019-04-09 10:00:17 +02:00
|
|
|
apt:
|
|
|
|
pkg:
|
|
|
|
- python-dev
|
|
|
|
- python-pip
|
2019-05-25 22:52:10 -04:00
|
|
|
when: mongodb_pymongo_from_pip | bool
|
2015-04-06 19:38:52 +03:00
|
|
|
|
|
|
|
- name: Install PyMongo from PIP
|
2018-06-27 11:57:28 +02:00
|
|
|
pip:
|
|
|
|
name: pymongo
|
|
|
|
state: "{{ mongodb_pymongo_pip_version is defined | ternary('present', 'latest') }}"
|
|
|
|
version: "{{ mongodb_pymongo_pip_version | default(omit) }}"
|
2019-05-25 22:52:10 -04:00
|
|
|
when: mongodb_pymongo_from_pip | bool
|