diff --git a/.gitignore b/.gitignore index f57a070..a1d8754 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ +tests/*.retry *~ \#*\# .\#* -/.python-version \ No newline at end of file +/.python-version diff --git a/.travis.yml b/.travis.yml index 9906851..e5dfc26 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 @@ -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 @@ -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 @@ -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) diff --git a/README.md b/README.md index 8255257..7d5b569 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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' }}" diff --git a/defaults/main.yml b/defaults/main.yml index 77fdda2..4f81ac2 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -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' }}" @@ -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' diff --git a/meta/main.yml b/meta/main.yml index 16fda1d..c2eb4a4 100644 --- a/meta/main.yml +++ b/meta/main.yml @@ -16,6 +16,10 @@ galaxy_info: - name: Debian versions: - wheezy + - name: EL + versions: + - 6 + - 7 galaxy_tags: - database - database:nosql diff --git a/tasks/install.deb.yml b/tasks/install.debian.yml similarity index 97% rename from tasks/install.deb.yml rename to tasks/install.debian.yml index 1f66443..ae966a0 100644 --- a/tasks/install.deb.yml +++ b/tasks/install.debian.yml @@ -1,7 +1,5 @@ --- -- include_vars: "{{ansible_distribution}}.yml" - - name: Check if running on systemd stat: path=/sbin/init register: sbin_init diff --git a/tasks/install.redhat.yml b/tasks/install.redhat.yml new file mode 100644 index 0000000..668a0de --- /dev/null +++ b/tasks/install.redhat.yml @@ -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 diff --git a/tasks/main.yml b/tasks/main.yml index 6e56976..94d1121 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -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 @@ -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 diff --git a/tasks/mms-agent.yml b/tasks/mms-agent.yml index c8658e1..f2d8fc2 100644 --- a/tasks/mms-agent.yml +++ b/tasks/mms-agent.yml @@ -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 diff --git a/templates/mongod.conf.j2 b/templates/mongod.conf.j2 index acf7734..ab19f0f 100644 --- a/templates/mongod.conf.j2 +++ b/templates/mongod.conf.j2 @@ -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: diff --git a/templates/mongod_init.conf.j2 b/templates/mongod_init.conf.j2 index 607f231..9624f5f 100644 --- a/templates/mongod_init.conf.j2 +++ b/templates/mongod_init.conf.j2 @@ -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' diff --git a/templates/mongodb.repo.j2 b/templates/mongodb.repo.j2 new file mode 100644 index 0000000..1a28431 --- /dev/null +++ b/templates/mongodb.repo.j2 @@ -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 diff --git a/tests/Dockerfile.centos_6-builded b/tests/Dockerfile.centos_6-builded new file mode 100644 index 0000000..06fb3b3 --- /dev/null +++ b/tests/Dockerfile.centos_6-builded @@ -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"] diff --git a/tests/Dockerfile.centos_7-builded b/tests/Dockerfile.centos_7-builded new file mode 100644 index 0000000..671e8e3 --- /dev/null +++ b/tests/Dockerfile.centos_7-builded @@ -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"] diff --git a/tests/site.yml b/tests/site.yml index 1ab4162..f6d861f 100644 --- a/tests/site.yml +++ b/tests/site.yml @@ -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" diff --git a/vars/RedHat.yml b/vars/RedHat.yml new file mode 100644 index 0000000..f61e2df --- /dev/null +++ b/vars/RedHat.yml @@ -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 '' }}"