Merge pull request #83 from justinsaliba/redhat-support

Redhat support
This commit is contained in:
Sergei Antipov 2017-09-19 11:15:33 +07:00 committed by GitHub
commit 54a2e1ea3b
16 changed files with 195 additions and 21 deletions

3
.gitignore vendored
View File

@ -1,4 +1,5 @@
tests/*.retry
*~ *~
\#*\# \#*\#
.\#* .\#*
/.python-version /.python-version

View File

@ -3,6 +3,10 @@
sudo: required sudo: required
env: env:
- >
DISTRIBUTION=ubuntu-upstart
DIST_VERSION=14.04
MONGODB_VERSION=3.4
- > - >
DISTRIBUTION=ubuntu-upstart DISTRIBUTION=ubuntu-upstart
DIST_VERSION=14.04 DIST_VERSION=14.04
@ -15,6 +19,10 @@ env:
DISTRIBUTION=ubuntu-upstart DISTRIBUTION=ubuntu-upstart
DIST_VERSION=14.04 DIST_VERSION=14.04
MONGODB_VERSION=2.6 MONGODB_VERSION=2.6
- >
DISTRIBUTION=ubuntu-upstart
DIST_VERSION=12.04-builded
MONGODB_VERSION=3.4
- > - >
DISTRIBUTION=ubuntu-upstart DISTRIBUTION=ubuntu-upstart
DIST_VERSION=12.04-builded DIST_VERSION=12.04-builded
@ -27,6 +35,44 @@ env:
DISTRIBUTION=ubuntu-upstart DISTRIBUTION=ubuntu-upstart
DIST_VERSION=12.04-builded DIST_VERSION=12.04-builded
MONGODB_VERSION=2.6 MONGODB_VERSION=2.6
- >
DISTRIBUTION=centos
DIST_VERSION=6-builded
MONGODB_VERSION=2.6
- >
DISTRIBUTION=centos
DIST_VERSION=6-builded
MONGODB_VERSION=3.0
- >
DISTRIBUTION=centos
DIST_VERSION=6-builded
MONGODB_VERSION=3.2
- >
DISTRIBUTION=centos
DIST_VERSION=6-builded
MONGODB_VERSION=3.4
- >
DISTRIBUTION=centos
DIST_VERSION=7-builded
MONGODB_VERSION=2.6
- >
DISTRIBUTION=centos
DIST_VERSION=7-builded
MONGODB_VERSION=3.0
- >
DISTRIBUTION=centos
DIST_VERSION=7-builded
MONGODB_VERSION=3.2
- >
DISTRIBUTION=centos
DIST_VERSION=7-builded
MONGODB_VERSION=3.4
# - >
# distribution=ubuntu-upstart
# version=12.04
# - >
# distribution=debian
# version=7
services: services:
- docker - docker
@ -44,16 +90,15 @@ before_install:
sudo docker build --rm=true --file=tests/Dockerfile.${DISTRIBUTION}_${DIST_VERSION} sudo docker build --rm=true --file=tests/Dockerfile.${DISTRIBUTION}_${DIST_VERSION}
--tag ${DISTRIBUTION}:${DIST_VERSION} tests; else sudo docker pull ${DISTRIBUTION}:${DIST_VERSION}; fi --tag ${DISTRIBUTION}:${DIST_VERSION} tests; else sudo docker pull ${DISTRIBUTION}:${DIST_VERSION}; fi
- sudo ln -s ${PWD} /etc/ansible/roles/greendayonfire.mongodb - sudo ln -s ${PWD} /etc/ansible/roles/greendayonfire.mongodb
script: script:
# Test 1 # Test 1
- > - >
sudo ansible-playbook -i tests/hosts tests/site.yml -e target=mongo1 -e mongodb_version=${MONGODB_VERSION} sudo ansible-playbook -i tests/hosts tests/site.yml -e target=mongo1 -e mongodb_version=${MONGODB_VERSION} -e image_name=${DISTRIBUTION}:${DIST_VERSION}
-e image_name=${DISTRIBUTION}:${DIST_VERSION}
# Idempotence test # Idempotence test
- > - >
sudo ansible-playbook -i tests/hosts tests/site.yml -e target=mongo1 -e mongodb_version=${MONGODB_VERSION} sudo ansible-playbook -i tests/hosts tests/site.yml -e target=mongo1 -e mongodb_version=${MONGODB_VERSION} -e image_name=${DISTRIBUTION}:${DIST_VERSION}
-e image_name=${DISTRIBUTION}:${DIST_VERSION} | grep -q 'changed=0.*failed=0' | grep -q 'changed=0.*failed=0'
&& (echo 'Idempotence test: pass' && exit 0) && (echo 'Idempotence test: pass' && exit 0)
|| (echo 'Idempotence test: fail' && exit 1) || (echo 'Idempotence test: fail' && exit 1)

View File

@ -17,6 +17,8 @@ MongoDB support matrix:
| Ubuntu 16.04 | :no_entry: | :x: | :x: | :x:| :x:| | Ubuntu 16.04 | :no_entry: | :x: | :x: | :x:| :x:|
| Debian 7.x | :no_entry: | :interrobang: | :interrobang: | :interrobang:| :x:| | Debian 7.x | :no_entry: | :interrobang: | :interrobang: | :interrobang:| :x:|
| Debian 8.x | :no_entry: | :x: | :x: | :x:| :x:| | Debian 8.x | :no_entry: | :x: | :x: | :x:| :x:|
| RHEL 6.x | :no_entry: | :interrobang: | :interrobang: | :interrobang: | :interrobang: |
| RHEL 7.x | :no_entry: | :interrobang: | :interrobang: | :interrobang: | :interrobang: |
:white_check_mark: - fully tested, should work fine :white_check_mark: - fully tested, should work fine
:interrobang: - will be added testing suite soon :interrobang: - will be added testing suite soon
@ -41,7 +43,7 @@ mongodb_pymongo_from_pip: true # Install latest PyMongo via PI
mongodb_user_update_password: "on_create" # MongoDB user password update default policy mongodb_user_update_password: "on_create" # MongoDB user password update default policy
mongodb_manage_service: true mongodb_manage_service: true
mongodb_user: mongodb mongodb_user: "{{ 'mongod' if ('RedHat' == ansible_os_family) else 'mongodb' }}"
mongodb_uid: mongodb_uid:
mongodb_gid: mongodb_gid:
mongodb_daemon_name: "{{ 'mongod' if ('mongodb-org' in mongodb_package) else 'mongodb' }}" mongodb_daemon_name: "{{ 'mongod' if ('mongodb-org' in mongodb_package) else 'mongodb' }}"

View File

@ -15,7 +15,7 @@ mongodb_force_wait_for_port: false
mongodb_user_update_password: "on_create" # MongoDB user password update default policy mongodb_user_update_password: "on_create" # MongoDB user password update default policy
mongodb_manage_service: true mongodb_manage_service: true
mongodb_user: mongodb mongodb_user: "{{ 'mongod' if ('RedHat' == ansible_os_family) else 'mongodb' }}"
mongodb_uid: mongodb_uid:
mongodb_gid: mongodb_gid:
mongodb_daemon_name: "{{ 'mongod' if ('mongodb-org' in mongodb_package) else 'mongodb' }}" mongodb_daemon_name: "{{ 'mongod' if ('mongodb-org' in mongodb_package) else 'mongodb' }}"
@ -28,7 +28,9 @@ mongodb_net_maxconns: 65536 # Max number of simultaneous co
mongodb_net_port: 27017 # Specify port number mongodb_net_port: 27017 # Specify port number
## processManagement Options ## processManagement Options
mongodb_processmanagement_fork: false # Fork server process # Fork server process
# Enabled by default for RedHat as the init scripts assume forking is enabled.
mongodb_processmanagement_fork: "{{ 'RedHat' == ansible_os_family }}"
## security Options ## security Options
# Disable or enable security. Possible values: 'disabled', 'enabled' # Disable or enable security. Possible values: 'disabled', 'enabled'

View File

@ -16,6 +16,10 @@ galaxy_info:
- name: Debian - name: Debian
versions: versions:
- wheezy - wheezy
- name: EL
versions:
- 6
- 7
galaxy_tags: galaxy_tags:
- database - database
- database:nosql - database:nosql

View File

@ -1,7 +1,5 @@
--- ---
- include_vars: "{{ansible_distribution}}.yml"
- name: Check if running on systemd - name: Check if running on systemd
stat: path=/sbin/init stat: path=/sbin/init
register: sbin_init register: sbin_init

46
tasks/install.redhat.yml Normal file
View File

@ -0,0 +1,46 @@
---
- name: Establish some role-related facts
set_fact:
mongodb_major_version: "{{ mongodb_version[0:3] }}"
- name: Install EPEL release repository
package:
name: epel-release
state: present
- name: Add YUM repository
template:
src: mongodb.repo.j2
dest: /etc/yum.repos.d/mongodb.repo
mode: 0644
with_items: "{{ mongodb_version[0:3] }}"
when: mongodb_package == 'mongodb-org'
- name: Install MongoDB package
yum:
name: "{{ item }}"
state: present
with_items:
- "{{ mongodb_package }}"
- numactl
- name: Install PyMongo package
yum:
name: python-pymongo
state: latest
when: not mongodb_pymongo_from_pip
- name: Install PIP
yum:
name: "{{ item }}"
with_items:
- python-devel
- python-pip
when: mongodb_pymongo_from_pip
- name: Install PyMongo from PIP
pip:
name: pymongo
state: latest
when: mongodb_pymongo_from_pip

View File

@ -1,8 +1,13 @@
--- ---
- name: Include OS-specific variables
include_vars: "{{ item }}"
with_first_found:
- "{{ ansible_distribution }}.yml"
- "{{ ansible_os_family }}.yml"
- name: Include installation on Debian-based OS - name: Include installation on Debian-based OS
include: install.deb.yml include: "install.{{ ansible_os_family | lower }}.yml"
when: ansible_os_family == 'Debian'
tags: [mongodb] tags: [mongodb]
- name: Include configuration.yml - name: Include configuration.yml
@ -22,11 +27,10 @@
when: mongodb_replication_replset and mongodb_replication_replset != '' when: mongodb_replication_replset and mongodb_replication_replset != ''
tags: [mongodb] tags: [mongodb]
- name: Check user admin is exists - name: Check where admin user already exists
command: > command: >
mongo --quiet -u {{ mongodb_user_admin_name }} \ mongo --quiet -u {{ mongodb_user_admin_name }} \
-p {{ mongodb_user_admin_password }} --port {{ mongodb_net_port }} --eval 'db.version()' admin -p {{ mongodb_user_admin_password }} --port {{ mongodb_net_port }} --eval 'db.version()' admin
register: mongodb_user_admin_check register: mongodb_user_admin_check
changed_when: false changed_when: false
always_run: yes # side-effect free, so it can be run in check-mode as well always_run: yes # side-effect free, so it can be run in check-mode as well

View File

@ -1,12 +1,25 @@
--- ---
- name: Install MMS agent pt. 1 - name: Download MMS Agent (Debian)
get_url: url={{mongodb_mms_agent_pkg}} dest={{mongodb_storage_dbpath}}/mms-agent.deb get_url: url={{mongodb_mms_agent_pkg}} dest={{mongodb_storage_dbpath}}/mms-agent.deb
register: mongodb_mms_agent_loaded register: mongodb_mms_agent_loaded
when: ansible_distribution == 'Debian' or ansible_distribution == 'Ubuntu'
- name: Install MMS agent pt. 2 - name: Download MMS Agent (RHEL)
apt: deb={{mongodb_storage_dbpath}}/mms-agent.deb get_url: url={{mongodb_mms_agent_pkg}} dest={{mongodb_storage_dbpath}}/mms-agent.rpm
when: mongodb_mms_agent_loaded.changed register: mongodb_mms_agent_loaded
when: ansible_distribution == 'CentOS' or ansible_distribution == 'Red Hat Enterprise Linux'
- name: Install MMS agent (Debian)
apt:
deb: "{{mongodb_storage_dbpath}}/mms-agent.deb"
when: mongodb_mms_agent_loaded.changed and (ansible_distribution == 'Debian' or ansible_distribution == 'Ubuntu')
- name: Install MMS agent (RHEL)
yum:
name: "{{mongodb_storage_dbpath}}/mms-agent.rpm"
state: present
when: mongodb_mms_agent_loaded.changed and (ansible_distribution == 'CentOS' or ansible_distribution == 'Red Hat Enterprise Linux')
- name: Configure the MMS agent pt. 1 - name: Configure the MMS agent pt. 1
file: state=directory path=/etc/mongodb-mms owner={{mongodb_user}} group={{mongodb_user}} mode=0755 file: state=directory path=/etc/mongodb-mms owner={{mongodb_user}} group={{mongodb_user}} mode=0755

View File

@ -10,6 +10,9 @@ net:
processManagement: processManagement:
fork: {{ mongodb_processmanagement_fork | to_nice_json}} fork: {{ mongodb_processmanagement_fork | to_nice_json}}
{% if mongodb_pidfile_path is defined and mongodb_pidfile_path != '' -%}
pidFilePath: {{ mongodb_pidfile_path }}
{% endif %}
{% if mongodb_replication_replset -%} {% if mongodb_replication_replset -%}
replication: replication:

View File

@ -10,7 +10,10 @@ net:
processManagement: processManagement:
fork: {{ mongodb_processmanagement_fork | to_nice_json }} fork: {{ mongodb_processmanagement_fork | to_nice_json }}
{% if mongodb_pidfile_path is defined and mongodb_pidfile_path != '' -%}
pidFilePath: {{ mongodb_pidfile_path }}
{% endif %}
security: security:
authorization: 'disabled' authorization: 'disabled'

View File

@ -0,0 +1,8 @@
[mongodb-org-{{ mongodb_version }}]
name=MongoDB {{ mongodb_version }} Repository
baseurl={{ mongodb_repository[item] }}
gpgcheck={{ mongodb_repository_gpgkey[item] is defined | ternary(1,0) }}
{% if mongodb_repository_gpgkey[item] is defined %}
gpgkey={{ mongodb_repository_gpgkey[item] }}
{% endif %}
enabled=1

View File

@ -0,0 +1,13 @@
FROM centos:6
# This is needed so that ansible managed to read "ansible_default_ipv4"
RUN yum install iproute -y
# This step is needed since standard CentOS docker image does not come with EPEL installed by default
RUN yum install epel-release -y
# we can has SSH
EXPOSE 22
# pepare for takeoff
CMD ["/usr/sbin/init"]

View File

@ -0,0 +1,17 @@
FROM centos:7
# This is needed so that ansible managed to read "ansible_default_ipv4"
RUN yum install iproute -y
# This step is needed since standard CentOS docker image does not come with EPEL installed by default
RUN yum install epel-release -y
# This step is needed since standard CentOS docker image does not come with init-functions installed by default.
# This package seems to be required for Mongo 3.2 and downwards
RUN yum install initscripts -y
# we can has SSH
EXPOSE 22
# pepare for takeoff
CMD ["/usr/sbin/init"]

View File

@ -11,14 +11,16 @@
image: "{{ image_name }}" image: "{{ image_name }}"
command: "/sbin/init" command: "/sbin/init"
state: started state: started
privileged: true
with_items: with_items:
- mongo1 - mongo1
- mongo2 - mongo2
- mongo3 - mongo3
- hosts: "{{ target }}" - hosts: "{{ target }}"
become: no become: no
gather_facts: yes gather_facts: yes
roles: roles:
- role: greendayonfire.mongodb - role: greendayonfire.mongodb
when: "'mongo_master' in group_names" when: "'mongo_master' in group_names"

13
vars/RedHat.yml Normal file
View File

@ -0,0 +1,13 @@
---
mongodb_repository:
"2.6": "http://downloads-distro.mongodb.org/repo/redhat/os/$basearch/"
"3.0": "https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/3.0/$basearch/"
"3.2": "https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/3.2/$basearch/"
"3.4": "https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/3.4/$basearch/"
mongodb_repository_gpgkey:
"3.2": "https://www.mongodb.org/static/pgp/server-3.2.asc"
"3.4": "https://www.mongodb.org/static/pgp/server-3.4.asc"
mongodb_pidfile_path: "{{ '/var/run/mongodb/mongod.pid' if ('mongodb-org' in mongodb_package) else '' }}"