Skip to content

Commit

Permalink
Merge pull request #83 from justinsaliba/redhat-support
Browse files Browse the repository at this point in the history
Redhat support
  • Loading branch information
UnderGreen authored Sep 19, 2017
2 parents 9ba2bbc + 7c3cfd2 commit 54a2e1e
Show file tree
Hide file tree
Showing 16 changed files with 195 additions and 21 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
tests/*.retry
*~
\#*\#
.\#*
/.python-version
/.python-version
55 changes: 50 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@

sudo: required
env:
- >
DISTRIBUTION=ubuntu-upstart
DIST_VERSION=14.04
MONGODB_VERSION=3.4
- >
DISTRIBUTION=ubuntu-upstart
DIST_VERSION=14.04
Expand All @@ -15,6 +19,10 @@ env:
DISTRIBUTION=ubuntu-upstart
DIST_VERSION=14.04
MONGODB_VERSION=2.6
- >
DISTRIBUTION=ubuntu-upstart
DIST_VERSION=12.04-builded
MONGODB_VERSION=3.4
- >
DISTRIBUTION=ubuntu-upstart
DIST_VERSION=12.04-builded
Expand All @@ -27,6 +35,44 @@ env:
DISTRIBUTION=ubuntu-upstart
DIST_VERSION=12.04-builded
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:
- docker
Expand All @@ -44,16 +90,15 @@ before_install:
sudo docker build --rm=true --file=tests/Dockerfile.${DISTRIBUTION}_${DIST_VERSION}
--tag ${DISTRIBUTION}:${DIST_VERSION} tests; else sudo docker pull ${DISTRIBUTION}:${DIST_VERSION}; fi
- sudo ln -s ${PWD} /etc/ansible/roles/greendayonfire.mongodb

script:
# Test 1
- >
sudo ansible-playbook -i tests/hosts tests/site.yml -e target=mongo1 -e mongodb_version=${MONGODB_VERSION}
-e image_name=${DISTRIBUTION}:${DIST_VERSION}
sudo ansible-playbook -i tests/hosts tests/site.yml -e target=mongo1 -e mongodb_version=${MONGODB_VERSION} -e image_name=${DISTRIBUTION}:${DIST_VERSION}
# Idempotence test
- >
sudo ansible-playbook -i tests/hosts tests/site.yml -e target=mongo1 -e mongodb_version=${MONGODB_VERSION}
-e image_name=${DISTRIBUTION}:${DIST_VERSION} | grep -q 'changed=0.*failed=0'
sudo ansible-playbook -i tests/hosts tests/site.yml -e target=mongo1 -e mongodb_version=${MONGODB_VERSION} -e image_name=${DISTRIBUTION}:${DIST_VERSION}
| grep -q 'changed=0.*failed=0'
&& (echo 'Idempotence test: pass' && exit 0)
|| (echo 'Idempotence test: fail' && exit 1)
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ MongoDB support matrix:
| Ubuntu 16.04 | :no_entry: | :x: | :x: | :x:| :x:|
| Debian 7.x | :no_entry: | :interrobang: | :interrobang: | :interrobang:| :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
:interrobang: - will be added testing suite soon
Expand All @@ -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_manage_service: true

mongodb_user: mongodb
mongodb_user: "{{ 'mongod' if ('RedHat' == ansible_os_family) else 'mongodb' }}"
mongodb_uid:
mongodb_gid:
mongodb_daemon_name: "{{ 'mongod' if ('mongodb-org' in mongodb_package) else 'mongodb' }}"
Expand Down
6 changes: 4 additions & 2 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ mongodb_force_wait_for_port: false
mongodb_user_update_password: "on_create" # MongoDB user password update default policy
mongodb_manage_service: true

mongodb_user: mongodb
mongodb_user: "{{ 'mongod' if ('RedHat' == ansible_os_family) else 'mongodb' }}"
mongodb_uid:
mongodb_gid:
mongodb_daemon_name: "{{ 'mongod' if ('mongodb-org' in mongodb_package) else 'mongodb' }}"
Expand All @@ -28,7 +28,9 @@ mongodb_net_maxconns: 65536 # Max number of simultaneous co
mongodb_net_port: 27017 # Specify port number

## 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
# Disable or enable security. Possible values: 'disabled', 'enabled'
Expand Down
4 changes: 4 additions & 0 deletions meta/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ galaxy_info:
- name: Debian
versions:
- wheezy
- name: EL
versions:
- 6
- 7
galaxy_tags:
- database
- database:nosql
2 changes: 0 additions & 2 deletions tasks/install.deb.yml → tasks/install.debian.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
---

- include_vars: "{{ansible_distribution}}.yml"

- name: Check if running on systemd
stat: path=/sbin/init
register: sbin_init
Expand Down
46 changes: 46 additions & 0 deletions tasks/install.redhat.yml
Original file line number Diff line number Diff line change
@@ -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
12 changes: 8 additions & 4 deletions tasks/main.yml
Original file line number Diff line number Diff line change
@@ -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
include: install.deb.yml
when: ansible_os_family == 'Debian'
include: "install.{{ ansible_os_family | lower }}.yml"
tags: [mongodb]

- name: Include configuration.yml
Expand All @@ -22,11 +27,10 @@
when: mongodb_replication_replset and mongodb_replication_replset != ''
tags: [mongodb]

- name: Check user admin is exists
- name: Check where admin user already exists
command: >
mongo --quiet -u {{ mongodb_user_admin_name }} \
-p {{ mongodb_user_admin_password }} --port {{ mongodb_net_port }} --eval 'db.version()' admin
register: mongodb_user_admin_check
changed_when: false
always_run: yes # side-effect free, so it can be run in check-mode as well
Expand Down
21 changes: 17 additions & 4 deletions tasks/mms-agent.yml
Original file line number Diff line number Diff line change
@@ -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
register: mongodb_mms_agent_loaded
when: ansible_distribution == 'Debian' or ansible_distribution == 'Ubuntu'

- name: Install MMS agent pt. 2
apt: deb={{mongodb_storage_dbpath}}/mms-agent.deb
when: mongodb_mms_agent_loaded.changed
- name: Download MMS Agent (RHEL)
get_url: url={{mongodb_mms_agent_pkg}} dest={{mongodb_storage_dbpath}}/mms-agent.rpm
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
file: state=directory path=/etc/mongodb-mms owner={{mongodb_user}} group={{mongodb_user}} mode=0755
Expand Down
3 changes: 3 additions & 0 deletions templates/mongod.conf.j2
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ net:

processManagement:
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 -%}
replication:
Expand Down
5 changes: 4 additions & 1 deletion templates/mongod_init.conf.j2
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ net:

processManagement:
fork: {{ mongodb_processmanagement_fork | to_nice_json }}

{% if mongodb_pidfile_path is defined and mongodb_pidfile_path != '' -%}
pidFilePath: {{ mongodb_pidfile_path }}
{% endif %}

security:
authorization: 'disabled'

Expand Down
8 changes: 8 additions & 0 deletions templates/mongodb.repo.j2
Original file line number Diff line number Diff line change
@@ -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
13 changes: 13 additions & 0 deletions tests/Dockerfile.centos_6-builded
Original file line number Diff line number Diff line change
@@ -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"]
17 changes: 17 additions & 0 deletions tests/Dockerfile.centos_7-builded
Original file line number Diff line number Diff line change
@@ -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"]
4 changes: 3 additions & 1 deletion tests/site.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,16 @@
image: "{{ image_name }}"
command: "/sbin/init"
state: started
privileged: true
with_items:
- mongo1
- mongo2
- mongo3

- hosts: "{{ target }}"
become: no
gather_facts: yes

roles:
- role: greendayonfire.mongodb
when: "'mongo_master' in group_names"
Expand Down
13 changes: 13 additions & 0 deletions vars/RedHat.yml
Original file line number Diff line number Diff line change
@@ -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 '' }}"

0 comments on commit 54a2e1e

Please sign in to comment.