ansible-role-mongodb/tasks/install.debian.yml
Patrick Dreker b6b99e33ff Ensure the systemd file is created under the
correct name

When installing mongodb-org packages on Debian/Ubuntu the daemon name is
set to "mongod" but the .service file is unconditionally installed as
"mongodb.service". This PR ensures, that the systemd file (and the
accompanying symlink) are installed as "mongodb_dameon_name.service".
Otherwise installation fails with
fatal: [tmongo-02]: FAILED! => {"changed": false, "msg": "Could not find the requested service mongod: host"}
for every host, as the handler tries to restart mongod, but systemd only
sees mongodb
2019-06-14 15:10:03 +02:00

91 lines
2.9 KiB
YAML

---
- name: Establish some role-related facts
set_fact:
mongodb_major_version: "{{ mongodb_version[0:3] }}"
- name: Disable transparent huge pages on systemd systems
include_tasks: disable_transparent_hugepages.yml
when:
- mongodb_disable_transparent_hugepages | bool
- ansible_service_mgr == "systemd"
- name: Add APT key
apt_key:
keyserver: "{{ mongodb_apt_keyserver }}"
id: "{{ mongodb_apt_key_id[mongodb_major_version] }}"
when: mongodb_package == 'mongodb-org'
- name: Fail when used wrong mongodb_version variable with Debian Stretch
fail:
msg: "mongodb_version variable should be '3.6' or '4.0' for Debian Stretch"
when:
- mongodb_package == 'mongodb-org'
- (mongodb_major_version != '3.6' and mongodb_major_version != '4.0')
- ansible_distribution_release == 'stretch'
- name: Fail when used wrong mongodb_version variable with Ubuntu 18.04
fail:
msg: "mongodb_version variable should be '4.0' or else mongodb_package should be 'mongodb' for Ubuntu 18.04"
when:
- mongodb_package == 'mongodb-org'
- mongodb_major_version != '4.0'
- ansible_distribution_release == "bionic"
- name: Fail when used wrong mongodb_version variable
fail:
msg: "mongodb_version variable should be '3.4', '3.6' or '4.0'"
when: (mongodb_package == 'mongodb-org' and
(mongodb_version is not defined
or mongodb_repository[mongodb_major_version] is not defined))
- name: Add APT repository
apt_repository:
repo: "{{ mongodb_repository[version_item] }}"
update_cache: true
with_items: "{{ mongodb_major_version }}"
loop_control:
loop_var: version_item
when: mongodb_package == 'mongodb-org'
- name: Install MongoDB package
apt:
name: "{{ mongodb_package }}{% if (mongodb_version | length > 3) %}={{ mongodb_version }}{% endif %}"
state: "{{ mongodb_package_state }}"
update_cache: true
- name: Install numactl package
apt:
name: numactl
state: present
- name: Add systemd configuration if present
copy: src=mongodb.service dest=/lib/systemd/system/{{mongodb_daemon_name}}.service owner=root group=root mode=0644
when: ansible_service_mgr == "systemd"
notify:
- reload systemd
- name: Add symlink for systemd
file: src=/lib/systemd/system/{{mongodb_daemon_name}}.service dest=/etc/systemd/system/multi-user.target.wants/{{mongodb_daemon_name}}.service state=link
when: ansible_service_mgr == "systemd"
notify:
- reload systemd
- name: Install PyMongo package
apt:
name: python-pymongo
when: not mongodb_pymongo_from_pip
- name: Install PIP
apt:
pkg:
- python-dev
- python-pip
when: mongodb_pymongo_from_pip | bool
- name: Install PyMongo from PIP
pip:
name: pymongo
state: "{{ mongodb_pymongo_pip_version is defined | ternary('present', 'latest') }}"
version: "{{ mongodb_pymongo_pip_version | default(omit) }}"
when: mongodb_pymongo_from_pip | bool