Resolved conflicts between Daniel White's redhat-support branch and UnderGreen master

This commit is contained in:
jsaliba 2017-09-13 16:26:32 +02:00
commit e034149e2d
16 changed files with 169 additions and 56 deletions

View File

@ -17,15 +17,15 @@ env:
MONGODB_VERSION=2.6
- >
DISTRIBUTION=ubuntu-upstart
DIST_VERSION=12.04
DIST_VERSION=12.04-builded
MONGODB_VERSION=3.2
- >
DISTRIBUTION=ubuntu-upstart
DIST_VERSION=12.04
DIST_VERSION=12.04-builded
MONGODB_VERSION=3.0
- >
DISTRIBUTION=ubuntu-upstart
DIST_VERSION=12.04
DIST_VERSION=12.04-builded
MONGODB_VERSION=2.6
- >
DISTRIBUTION=centos
@ -68,17 +68,30 @@ before_install:
- sudo apt-get update
- sudo apt-get install ansible python-pip -y
- sudo pip install docker-py==1.5.0
# Pull docker image
- sudo docker pull ${DISTRIBUTION}:${DIST_VERSION}
# Pull docker image or build it
- >
if [ -f tests/Dockerfile.${DISTRIBUTION}_${DIST_VERSION} ]; then
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
<<<<<<< HEAD
- 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}
# 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'
>>>>>>> 9ba2bbc86a637ae1250cab42ce4f1192f6979fb6
&& (echo 'Idempotence test: pass' && exit 0)
|| (echo 'Idempotence test: fail' && exit 1)

View File

@ -1,6 +1,6 @@
Ansible role for MongoDB [![Build Status](https://travis-ci.org/UnderGreen/ansible-role-mongodb.svg?branch=master)](https://travis-ci.org/UnderGreen/ansible-role-mongodb)
============
Ansible role which manage [MongoDB](http://www.mongodb.org/).
Ansible role which manages [MongoDB](http://www.mongodb.org/).
* Install and configure the MongoDB;
* Configure mongodb users
@ -10,17 +10,15 @@ Ansible role which manage [MongoDB](http://www.mongodb.org/).
MongoDB support matrix:
| Distribution | MongoDB 2.4 | MongoDB 2.6 | MongoDB 3.0 | MongoDB 3.2 |
| ------------ |:-----------:|:-----------:|:-----------:|:-----------:|
| Ubuntu 14.04 | :no_entry: | :white_check_mark: | :white_check_mark: | :white_check_mark:|
| Ubuntu 12.04 | :no_entry: | :white_check_mark: | :white_check_mark: | :white_check_mark:|
| Ubuntu 16.04 | :no_entry: | :x: | :x: | :x:|
| Debian 7.x | :no_entry: | :interrobang: | :interrobang: | :interrobang:|
| Debian 8.x | :no_entry: | :x: | :x: | :x:|
| CentOS 6.x | :no_entry: | :interrobang: | :interrobang: | :interrobang: |
| CentOS 7.x | :no_entry: | :interrobang: | :interrobang: | :interrobang: |
| RHEL 6.x | :no_entry: | :interrobang: | :interrobang: | :interrobang: |
| RHEL 7.x | :no_entry: | :interrobang: | :interrobang: | :interrobang: |
| Distribution | MongoDB 2.4 | MongoDB 2.6 | MongoDB 3.0 | MongoDB 3.2 | MongoDB 3.4 |
| ------------ |:-----------:|:-----------:|:-----------:|:-----------:|:-----------:|
| Ubuntu 14.04 | :no_entry: | :white_check_mark: | :white_check_mark: | :white_check_mark:| :x:|
| Ubuntu 12.04 | :no_entry: | :white_check_mark: | :white_check_mark: | :white_check_mark:| :x:|
| 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
@ -36,9 +34,9 @@ MongoDB support matrix:
mongodb_package: mongodb-org
# You can control installed version via this param.
# Should be '2.6', '3.0' or '3.2'. This role does't support MongoDB < 2.4.
# Should be '2.6', '3.0', '3.2' or '3.4'. This role does't support MongoDB < 2.4.
# I will recommend you to use latest version of MongoDB.
mongodb_version: "3.2"
mongodb_version: "3.4"
mongodb_force_wait_for_port: false # When not forced, the role will wait for mongod port to become available only with systemd
mongodb_pymongo_from_pip: true # Install latest PyMongo via PIP or package manager
@ -139,7 +137,7 @@ Add `greendayonfire.mongodb` to your roles and set vars in your playbook file.
Example vars for authorization:
```yaml
mongodb_security_authorization: true
mongodb_security_authorization: "enabled"
mongodb_users:
- {
name: testUser,

View File

@ -1,9 +1,14 @@
---
mongodb_package: mongodb-org
mongodb_version: "3.2"
mongodb_version: "3.4"
mongodb_apt_keyserver: keyserver.ubuntu.com
mongodb_apt_key_id: "{{ 'EA312927' if mongodb_version[0:3] == '3.2' else '7F0CEB10' }}"
mongodb_apt_key_id:
"2.6": "7F0CEB10"
"3.0": "7F0CEB10"
"3.2": "EA312927"
"3.4": "0C49F3730359A14518585931BC711F9BA15703C6"
mongodb_pymongo_from_pip: true # Install latest PyMongo via PIP or package manager
mongodb_force_wait_for_port: false

View File

@ -5,6 +5,8 @@ Documentation=man:mongod(1)
[Service]
User=mongodb
ExecStart=/usr/bin/mongod --config /etc/mongod.conf
LimitNOFILE=65535
LimitNPROC=65535
[Install]
WantedBy=multi-user.target

View File

@ -14,7 +14,7 @@
- name: reload systemd
shell: systemctl daemon-reload
when: systemd.stat.exists == true and mongodb_manage_service
when: mongodb_is_systemd and mongodb_manage_service
- name: restart sysfsutils
service: name=sysfsutils state=restarted

View File

@ -23,7 +23,7 @@ module: mongodb_replication
short_description: Adds or removes a node from a MongoDB Replica Set.
description:
- Adds or removes host from a MongoDB replica set. Initialize replica set if it needed.
version_added: "2.1"
version_added: "2.2"
options:
login_user:
description:
@ -56,7 +56,7 @@ options:
required: true
host_port:
description:
- The port of the host
- The port of the host, which should be added/deleted from RS
required: true
default: null
host_type:
@ -128,6 +128,23 @@ EXAMPLES = '''
- mongodb_replication: replica_set=replSet host_name=mongo4.dev host_port=27017 state=absent
'''
RETURN = '''
host_name:
description: The name of the host to add/remove from replica set
returned: success
type: string
sample: "mongo3.dev"
host_port:
description: The port of the host, which should be added/deleted from RS
returned: success
type: int
sample: 27017
host_type:
description: The type of the host in replica set
returned: success
type: string
sample: "replica"
'''
import ConfigParser
import time
from distutils.version import LooseVersion

View File

@ -33,6 +33,7 @@
password: "{{ mongodb_user_admin_password }}",
roles: "userAdminAnyDatabase"
}
no_log: true
- name: create administrative user siteRootAdmin
mongodb_user:
@ -48,6 +49,7 @@
password: "{{ mongodb_root_admin_password }}",
roles: "root"
}
no_log: true
- name: create backup user "backupuser"
mongodb_user:
@ -63,6 +65,7 @@
password: "{{ mongodb_root_backup_password }}",
roles: "backup,clusterMonitor"
}
no_log: true
- name: Move back mongod.conf
template: src=mongod.conf.j2 dest=/etc/mongod.conf owner=root group=root mode=0644
@ -71,8 +74,9 @@
service: name={{ mongodb_daemon_name }} state=restarted
when: mongodb_manage_service
- name: wait MongoDB port is listening
wait_for: host="{{ mongodb_net_bindip }}" port="{{ mongodb_net_port }}" delay=5 state=started
- name: Wait MongoDB port is listening
wait_for: host="{{ item }}" port="{{ mongodb_net_port }}" delay=5 state=started
with_items: "{{ mongodb_net_bindip.split(',') | map('replace', '0.0.0.0', '127.0.0.1') | list }}"
- name: stop mongodb if was not started
shell: "kill {{ pidof_mongod.stdout }}"

View File

@ -47,13 +47,12 @@
service: name={{ mongodb_daemon_name }} state=restarted
when: config_result|changed and mongodb_manage_service
- name: Set fact about wait_for host address
set_fact:
wait_for_host: 127.0.0.1
when: mongodb_net_bindip == "0.0.0.0"
- name: Ensure service is started
service: name={{ mongodb_daemon_name }} state=started
- name: Wait when mongodb is started
wait_for:
host: "{{ wait_for_host | default(mongodb_net_bindip) }}"
host: "{{ item }}"
port: "{{ mongodb_net_port }}"
timeout: 120
with_items: "{{ mongodb_net_bindip.split(',') | map('replace', '0.0.0.0', '127.0.0.1') | list }}"

View File

@ -1,39 +1,44 @@
---
- name: Check if running on systemd
command: cat /proc/1/cmdline
register: systemd
stat: path=/sbin/init
register: sbin_init
changed_when: false
always_run: yes # side-effect free, so it can be run in check-mode as well
- 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: Add systemd configuration if present
copy: src=mongodb.service dest=/lib/systemd/system/mongodb.service owner=root group=root mode=0640
when: "'systemd' in systemd.stdout"
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: "'systemd' in systemd.stdout"
when: mongodb_is_systemd
notify: reload systemd
- meta: flush_handlers
when: "'systemd' in systemd.stdout"
when: mongodb_is_systemd
- name: Add APT key
apt_key:
keyserver: "{{mongodb_apt_keyserver}}"
id: "{{mongodb_apt_key_id}}"
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[item] is not defined))
with_items: "{{ mongodb_version[0:3] }}"
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_version[0:3] }}"
with_items: "{{ mongodb_major_version }}"
when: mongodb_package == 'mongodb-org'
- name: Install MongoDB package
@ -45,7 +50,7 @@
- name: reload systemd
shell: systemctl daemon-reload
changed_when: false
when: "'systemd' in systemd.stdout"
when: mongodb_is_systemd
- name: Install PyMongo package
apt: pkg=python-pymongo state=latest

View File

@ -30,13 +30,16 @@
- name: Check user admin is exists
command: >
mongo --quiet -u {{ mongodb_user_admin_name }} \
-p {{ mongodb_user_admin_password }} --eval 'db.version()' admin
-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
ignore_errors: true
when: ( mongodb_security_authorization == 'enabled'
and (not mongodb_replication_replset
or mongodb_replication_replset == '') )
no_log: true
tags: [mongodb]
- name: Include authorization configuration
@ -64,6 +67,7 @@
and mongodb_replication_replset != ''
and mongodb_security_authorization == 'enabled'
and mongodb_master is defined and mongodb_master )
no_log: true
tags: [mongodb]
- name: create normal users without replicaset
@ -81,6 +85,7 @@
when: ( mongodb_security_authorization == 'enabled'
and (not mongodb_replication_replset
or mongodb_replication_replset == '') )
no_log: true
tags: [mongodb]
- name: Include MMS Agent configuration

View File

@ -22,7 +22,7 @@ replication:
secondaryIndexPrefetch: {{ mongodb_replication_replindexprefetch }}
{% endif %}
{% endif %}
security:
authorization: {{ mongodb_security_authorization }}
{% if mongodb_replication_replset and mongodb_security_authorization == 'enabled' -%}
@ -31,7 +31,7 @@ security:
storage:
dbPath: {{ mongodb_storage_dbpath }}
{% if mongodb_version[0:3]|float >= 3.0 -%}
{% if mongodb_major_version|float >= 3.0 -%}
engine: {{ mongodb_storage_engine }}
{% endif -%}
journal:
@ -43,7 +43,7 @@ storage:
maxFilesPerDB: {{ mongodb_storage_quota_maxfiles }}
smallFiles: {{ mongodb_storage_smallfiles | to_nice_json }}
{% endif -%}
{% if mongodb_version[0:3] == '2.6' -%}
{% if mongodb_major_version == '2.6' -%}
quota:
enforced: {{ mongodb_storage_quota_enforced | to_nice_json }}
maxFilesPerDB: {{ mongodb_storage_quota_maxfiles }}
@ -55,4 +55,3 @@ systemLog:
destination: {{ mongodb_systemlog_destination }}
logAppend: {{ mongodb_systemlog_logappend | to_nice_json }}
path: {{ mongodb_systemlog_path }}

View File

@ -19,7 +19,7 @@ security:
storage:
dbPath: {{ mongodb_storage_dbpath }}
{% if mongodb_version[0:3]|float >= 3.0 -%}
{% if mongodb_major_version|float >= 3.0 -%}
engine: {{ mongodb_storage_engine }}
{% endif -%}
journal:
@ -31,7 +31,7 @@ storage:
maxFilesPerDB: {{ mongodb_storage_quota_maxfiles }}
smallFiles: {{ mongodb_storage_smallfiles | to_nice_json }}
{% endif -%}
{% if mongodb_version[0:3] == '2.6' -%}
{% if mongodb_major_version == '2.6' -%}
quota:
enforced: {{ mongodb_storage_quota_enforced | to_nice_json }}
maxFilesPerDB: {{ mongodb_storage_quota_maxfiles }}

View File

@ -0,0 +1,53 @@
FROM ubuntu:12.04
# much of this was gleaned from https://github.com/lxc/lxc/blob/lxc-0.8.0/templates/lxc-ubuntu.in
# and then heavily modified and hacked like crazy
# we're going to want this bad boy installed so we can connect :)
RUN apt-get update && apt-get install -y ssh python
ADD builds/init-fake.conf /etc/init/fake-container-events.conf
# undo some leet hax of the base image
RUN rm /usr/sbin/policy-rc.d; \
rm /sbin/initctl; dpkg-divert --rename --remove /sbin/initctl
# generate a nice UTF-8 locale for our use
RUN locale-gen en_US.UTF-8 && update-locale LANG=en_US.UTF-8
# remove some pointless services
RUN /usr/sbin/update-rc.d -f ondemand remove; \
for f in \
/etc/init/u*.conf \
/etc/init/mounted-dev.conf \
/etc/init/mounted-proc.conf \
/etc/init/mounted-run.conf \
/etc/init/mounted-tmp.conf \
/etc/init/mounted-var.conf \
/etc/init/hostname.conf \
/etc/init/networking.conf \
/etc/init/tty*.conf \
/etc/init/plymouth*.conf \
/etc/init/hwclock*.conf \
/etc/init/module*.conf\
; do \
dpkg-divert --local --rename --add "$f"; \
done; \
echo '# /lib/init/fstab: cleared out for bare-bones Docker' > /lib/init/fstab
# small fix for SSH in 13.10 (that's harmless everywhere else)
RUN sed -ri 's/^session\s+required\s+pam_loginuid.so$/session optional pam_loginuid.so/' /etc/pam.d/sshd
RUN sed -ri 's/^PermitRootLogin\s+.*/PermitRootLogin yes/' /etc/ssh/sshd_config
# let Upstart know it's in a container
ENV container docker
# set a cheap, simple password for great convenience
RUN echo 'root:docker.io' | chpasswd
# we can has SSH
EXPOSE 22
# pepare for takeoff
CMD ["/sbin/init"]

View File

@ -0,0 +1,13 @@
# fake some events needed for correct startup other services
description "In-Container Upstart Fake Events"
start on startup
script
rm -rf /var/run/*.pid
rm -rf /var/run/network/*
/sbin/initctl emit stopped JOB=udevtrigger --no-wait
/sbin/initctl emit started JOB=udev --no-wait
/sbin/initctl emit runlevel RUNLEVEL=3 --no-wait
end script

View File

@ -1,6 +1,6 @@
---
mongodb_repository:
"2.6": "deb http://downloads-distro.mongodb.org/repo/debian-sysvinit dist 10gen"
"3.0": "deb http://repo.mongodb.org/apt/debian wheezy/mongodb-org/3.0 main"
"3.2": "deb http://repo.mongodb.org/apt/debian wheezy/mongodb-org/3.2 main"
"3.2": "deb http://repo.mongodb.org/apt/debian {{ ansible_distribution_release }}/mongodb-org/3.2 main"
"3.4": "deb http://repo.mongodb.org/apt/debian {{ ansible_distribution_release }}/mongodb-org/3.4 main"

View File

@ -1,6 +1,6 @@
---
mongodb_repository:
"2.6": "deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen"
"3.0": "deb http://repo.mongodb.org/apt/ubuntu {{ ansible_distribution_release }}/mongodb-org/3.0 multiverse"
"3.2": "deb http://repo.mongodb.org/apt/ubuntu {{ ansible_distribution_release }}/mongodb-org/3.2 multiverse"
"3.4": "deb http://repo.mongodb.org/apt/ubuntu {{ ansible_distribution_release }}/mongodb-org/3.4 multiverse"