73 lines
2.1 KiB
YAML
73 lines
2.1 KiB
YAML
---
|
|
|
|
- name: Check if running on systemd
|
|
stat: path=/sbin/init
|
|
register: sbin_init
|
|
changed_when: false
|
|
check_mode: no
|
|
|
|
- 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] }}"
|
|
|
|
- name: Overwrite mongodb_version especially for Debian 9
|
|
set_fact:
|
|
mongodb_major_version: "3.2"
|
|
when: ansible_distribution_release == "stretch"
|
|
|
|
- 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
|
|
fail:
|
|
msg: "mongodb_version variable should be '2.6', '3.0' or '3.2'"
|
|
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[item] }}" update_cache=yes
|
|
with_items: "{{ mongodb_major_version }}"
|
|
when: mongodb_package == 'mongodb-org'
|
|
|
|
- name: Install MongoDB package
|
|
apt: name={{item}} state=present
|
|
with_items:
|
|
- "{{mongodb_package}}"
|
|
- numactl
|
|
|
|
- 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
|
|
|
|
- name: reload systemd
|
|
shell: systemctl daemon-reload
|
|
when: mongodb_is_systemd and mongodb_manage_service
|
|
|
|
- meta: flush_handlers
|
|
when: mongodb_is_systemd
|
|
|
|
- name: Install PyMongo package
|
|
apt: pkg=python-pymongo state=latest
|
|
when: not mongodb_pymongo_from_pip
|
|
|
|
- name: Install PIP
|
|
apt: pkg={{ item }}
|
|
with_items:
|
|
- python-dev
|
|
- python-pip
|
|
when: mongodb_pymongo_from_pip
|
|
|
|
- name: Install PyMongo from PIP
|
|
pip: name=pymongo state=latest
|
|
when: mongodb_pymongo_from_pip
|