Skip to content

Commit e034149

Browse files
committed
Resolved conflicts between Daniel White's redhat-support branch and UnderGreen master
2 parents 4b22cc4 + 9ba2bbc commit e034149

16 files changed

+169
-56
lines changed

.travis.yml

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@ env:
1717
MONGODB_VERSION=2.6
1818
- >
1919
DISTRIBUTION=ubuntu-upstart
20-
DIST_VERSION=12.04
20+
DIST_VERSION=12.04-builded
2121
MONGODB_VERSION=3.2
2222
- >
2323
DISTRIBUTION=ubuntu-upstart
24-
DIST_VERSION=12.04
24+
DIST_VERSION=12.04-builded
2525
MONGODB_VERSION=3.0
2626
- >
2727
DISTRIBUTION=ubuntu-upstart
28-
DIST_VERSION=12.04
28+
DIST_VERSION=12.04-builded
2929
MONGODB_VERSION=2.6
3030
- >
3131
DISTRIBUTION=centos
@@ -68,17 +68,30 @@ before_install:
6868
- sudo apt-get update
6969
- sudo apt-get install ansible python-pip -y
7070
- sudo pip install docker-py==1.5.0
71-
# Pull docker image
72-
- sudo docker pull ${DISTRIBUTION}:${DIST_VERSION}
71+
# Pull docker image or build it
72+
- >
73+
if [ -f tests/Dockerfile.${DISTRIBUTION}_${DIST_VERSION} ]; then
74+
sudo docker build --rm=true --file=tests/Dockerfile.${DISTRIBUTION}_${DIST_VERSION}
75+
--tag ${DISTRIBUTION}:${DIST_VERSION} tests; else sudo docker pull ${DISTRIBUTION}:${DIST_VERSION}; fi
7376
- sudo ln -s ${PWD} /etc/ansible/roles/greendayonfire.mongodb
7477

7578
script:
7679
# Test 1
80+
<<<<<<< HEAD
7781
- sudo ansible-playbook -i tests/hosts tests/site.yml -e target=mongo1 -e mongodb_version=${MONGODB_VERSION} -e image_name=${DISTRIBUTION}:${DIST_VERSION}
7882
# Idempotence test
7983
- >
8084
sudo ansible-playbook -i tests/hosts tests/site.yml -e target=mongo1 -e mongodb_version=${MONGODB_VERSION} -e image_name=${DISTRIBUTION}:${DIST_VERSION}
8185
| grep -q 'changed=0.*failed=0'
86+
=======
87+
- >
88+
sudo ansible-playbook -i tests/hosts tests/site.yml -e target=mongo1 -e mongodb_version=${MONGODB_VERSION}
89+
-e image_name=${DISTRIBUTION}:${DIST_VERSION}
90+
# Idempotence test
91+
- >
92+
sudo ansible-playbook -i tests/hosts tests/site.yml -e target=mongo1 -e mongodb_version=${MONGODB_VERSION}
93+
-e image_name=${DISTRIBUTION}:${DIST_VERSION} | grep -q 'changed=0.*failed=0'
94+
>>>>>>> 9ba2bbc86a637ae1250cab42ce4f1192f6979fb6
8295
&& (echo 'Idempotence test: pass' && exit 0)
8396
|| (echo 'Idempotence test: fail' && exit 1)
8497

README.md

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
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)
22
============
3-
Ansible role which manage [MongoDB](http://www.mongodb.org/).
3+
Ansible role which manages [MongoDB](http://www.mongodb.org/).
44

55
* Install and configure the MongoDB;
66
* Configure mongodb users
@@ -10,17 +10,15 @@ Ansible role which manage [MongoDB](http://www.mongodb.org/).
1010

1111
MongoDB support matrix:
1212

13-
| Distribution | MongoDB 2.4 | MongoDB 2.6 | MongoDB 3.0 | MongoDB 3.2 |
14-
| ------------ |:-----------:|:-----------:|:-----------:|:-----------:|
15-
| Ubuntu 14.04 | :no_entry: | :white_check_mark: | :white_check_mark: | :white_check_mark:|
16-
| Ubuntu 12.04 | :no_entry: | :white_check_mark: | :white_check_mark: | :white_check_mark:|
17-
| Ubuntu 16.04 | :no_entry: | :x: | :x: | :x:|
18-
| Debian 7.x | :no_entry: | :interrobang: | :interrobang: | :interrobang:|
19-
| Debian 8.x | :no_entry: | :x: | :x: | :x:|
20-
| CentOS 6.x | :no_entry: | :interrobang: | :interrobang: | :interrobang: |
21-
| CentOS 7.x | :no_entry: | :interrobang: | :interrobang: | :interrobang: |
22-
| RHEL 6.x | :no_entry: | :interrobang: | :interrobang: | :interrobang: |
23-
| RHEL 7.x | :no_entry: | :interrobang: | :interrobang: | :interrobang: |
13+
| Distribution | MongoDB 2.4 | MongoDB 2.6 | MongoDB 3.0 | MongoDB 3.2 | MongoDB 3.4 |
14+
| ------------ |:-----------:|:-----------:|:-----------:|:-----------:|:-----------:|
15+
| Ubuntu 14.04 | :no_entry: | :white_check_mark: | :white_check_mark: | :white_check_mark:| :x:|
16+
| Ubuntu 12.04 | :no_entry: | :white_check_mark: | :white_check_mark: | :white_check_mark:| :x:|
17+
| Ubuntu 16.04 | :no_entry: | :x: | :x: | :x:| :x:|
18+
| Debian 7.x | :no_entry: | :interrobang: | :interrobang: | :interrobang:| :x:|
19+
| Debian 8.x | :no_entry: | :x: | :x: | :x:| :x:|
20+
| RHEL 6.x | :no_entry: | :interrobang: | :interrobang: | :interrobang: | :interrobang |
21+
| RHEL 7.x | :no_entry: | :interrobang: | :interrobang: | :interrobang: | :interrobang |
2422

2523
:white_check_mark: - fully tested, should work fine
2624
:interrobang: - will be added testing suite soon
@@ -36,9 +34,9 @@ MongoDB support matrix:
3634
mongodb_package: mongodb-org
3735

3836
# You can control installed version via this param.
39-
# Should be '2.6', '3.0' or '3.2'. This role does't support MongoDB < 2.4.
37+
# Should be '2.6', '3.0', '3.2' or '3.4'. This role does't support MongoDB < 2.4.
4038
# I will recommend you to use latest version of MongoDB.
41-
mongodb_version: "3.2"
39+
mongodb_version: "3.4"
4240

4341
mongodb_force_wait_for_port: false # When not forced, the role will wait for mongod port to become available only with systemd
4442
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.
139137

140138
Example vars for authorization:
141139
```yaml
142-
mongodb_security_authorization: true
140+
mongodb_security_authorization: "enabled"
143141
mongodb_users:
144142
- {
145143
name: testUser,

defaults/main.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
---
22

33
mongodb_package: mongodb-org
4-
mongodb_version: "3.2"
4+
mongodb_version: "3.4"
55
mongodb_apt_keyserver: keyserver.ubuntu.com
6-
mongodb_apt_key_id: "{{ 'EA312927' if mongodb_version[0:3] == '3.2' else '7F0CEB10' }}"
6+
mongodb_apt_key_id:
7+
"2.6": "7F0CEB10"
8+
"3.0": "7F0CEB10"
9+
"3.2": "EA312927"
10+
"3.4": "0C49F3730359A14518585931BC711F9BA15703C6"
11+
712
mongodb_pymongo_from_pip: true # Install latest PyMongo via PIP or package manager
813

914
mongodb_force_wait_for_port: false

files/mongodb.service

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ Documentation=man:mongod(1)
55
[Service]
66
User=mongodb
77
ExecStart=/usr/bin/mongod --config /etc/mongod.conf
8+
LimitNOFILE=65535
9+
LimitNPROC=65535
810

911
[Install]
1012
WantedBy=multi-user.target

handlers/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
- name: reload systemd
1616
shell: systemctl daemon-reload
17-
when: systemd.stat.exists == true and mongodb_manage_service
17+
when: mongodb_is_systemd and mongodb_manage_service
1818

1919
- name: restart sysfsutils
2020
service: name=sysfsutils state=restarted

library/mongodb_replication.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
short_description: Adds or removes a node from a MongoDB Replica Set.
2424
description:
2525
- Adds or removes host from a MongoDB replica set. Initialize replica set if it needed.
26-
version_added: "2.1"
26+
version_added: "2.2"
2727
options:
2828
login_user:
2929
description:
@@ -56,7 +56,7 @@
5656
required: true
5757
host_port:
5858
description:
59-
- The port of the host
59+
- The port of the host, which should be added/deleted from RS
6060
required: true
6161
default: null
6262
host_type:
@@ -128,6 +128,23 @@
128128
- mongodb_replication: replica_set=replSet host_name=mongo4.dev host_port=27017 state=absent
129129
'''
130130

131+
RETURN = '''
132+
host_name:
133+
description: The name of the host to add/remove from replica set
134+
returned: success
135+
type: string
136+
sample: "mongo3.dev"
137+
host_port:
138+
description: The port of the host, which should be added/deleted from RS
139+
returned: success
140+
type: int
141+
sample: 27017
142+
host_type:
143+
description: The type of the host in replica set
144+
returned: success
145+
type: string
146+
sample: "replica"
147+
'''
131148
import ConfigParser
132149
import time
133150
from distutils.version import LooseVersion

tasks/auth_initialization.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
password: "{{ mongodb_user_admin_password }}",
3434
roles: "userAdminAnyDatabase"
3535
}
36+
no_log: true
3637

3738
- name: create administrative user siteRootAdmin
3839
mongodb_user:
@@ -48,6 +49,7 @@
4849
password: "{{ mongodb_root_admin_password }}",
4950
roles: "root"
5051
}
52+
no_log: true
5153

5254
- name: create backup user "backupuser"
5355
mongodb_user:
@@ -63,6 +65,7 @@
6365
password: "{{ mongodb_root_backup_password }}",
6466
roles: "backup,clusterMonitor"
6567
}
68+
no_log: true
6669

6770
- name: Move back mongod.conf
6871
template: src=mongod.conf.j2 dest=/etc/mongod.conf owner=root group=root mode=0644
@@ -71,8 +74,9 @@
7174
service: name={{ mongodb_daemon_name }} state=restarted
7275
when: mongodb_manage_service
7376

74-
- name: wait MongoDB port is listening
75-
wait_for: host="{{ mongodb_net_bindip }}" port="{{ mongodb_net_port }}" delay=5 state=started
77+
- name: Wait MongoDB port is listening
78+
wait_for: host="{{ item }}" port="{{ mongodb_net_port }}" delay=5 state=started
79+
with_items: "{{ mongodb_net_bindip.split(',') | map('replace', '0.0.0.0', '127.0.0.1') | list }}"
7680

7781
- name: stop mongodb if was not started
7882
shell: "kill {{ pidof_mongod.stdout }}"

tasks/configure.yml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,12 @@
4747
service: name={{ mongodb_daemon_name }} state=restarted
4848
when: config_result|changed and mongodb_manage_service
4949

50-
- name: Set fact about wait_for host address
51-
set_fact:
52-
wait_for_host: 127.0.0.1
53-
when: mongodb_net_bindip == "0.0.0.0"
54-
50+
- name: Ensure service is started
51+
service: name={{ mongodb_daemon_name }} state=started
52+
5553
- name: Wait when mongodb is started
5654
wait_for:
57-
host: "{{ wait_for_host | default(mongodb_net_bindip) }}"
55+
host: "{{ item }}"
5856
port: "{{ mongodb_net_port }}"
5957
timeout: 120
58+
with_items: "{{ mongodb_net_bindip.split(',') | map('replace', '0.0.0.0', '127.0.0.1') | list }}"

tasks/install.debian.yml

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,44 @@
11
---
22

33
- name: Check if running on systemd
4-
command: cat /proc/1/cmdline
5-
register: systemd
4+
stat: path=/sbin/init
5+
register: sbin_init
66
changed_when: false
7+
always_run: yes # side-effect free, so it can be run in check-mode as well
8+
9+
- name: Establish some role-related facts
10+
set_fact:
11+
mongodb_is_systemd: "{{ sbin_init.stat.islnk is defined and sbin_init.stat.islnk }}"
12+
mongodb_major_version: "{{ mongodb_version[0:3] }}"
713

814
- name: Add systemd configuration if present
915
copy: src=mongodb.service dest=/lib/systemd/system/mongodb.service owner=root group=root mode=0640
10-
when: "'systemd' in systemd.stdout"
16+
when: mongodb_is_systemd
1117

1218
- name: Add symlink for systemd
1319
file: src=/lib/systemd/system/mongodb.service dest=/etc/systemd/system/multi-user.target.wants/mongodb.service state=link
14-
when: "'systemd' in systemd.stdout"
20+
when: mongodb_is_systemd
1521
notify: reload systemd
1622

1723
- meta: flush_handlers
18-
when: "'systemd' in systemd.stdout"
24+
when: mongodb_is_systemd
1925

2026
- name: Add APT key
2127
apt_key:
22-
keyserver: "{{mongodb_apt_keyserver}}"
23-
id: "{{mongodb_apt_key_id}}"
28+
keyserver: "{{ mongodb_apt_keyserver }}"
29+
id: "{{ mongodb_apt_key_id[mongodb_major_version] }}"
2430
when: mongodb_package == 'mongodb-org'
25-
31+
2632
- name: Fail when used wrong mongodb_version variable
2733
fail:
2834
msg: "mongodb_version variable should be '2.6', '3.0' or '3.2'"
2935
when: (mongodb_package == 'mongodb-org' and
3036
(mongodb_version is not defined
31-
or mongodb_repository[item] is not defined))
32-
with_items: "{{ mongodb_version[0:3] }}"
33-
37+
or mongodb_repository[mongodb_major_version] is not defined))
38+
3439
- name: Add APT repository
3540
apt_repository: repo="{{ mongodb_repository[item] }}" update_cache=yes
36-
with_items: "{{ mongodb_version[0:3] }}"
41+
with_items: "{{ mongodb_major_version }}"
3742
when: mongodb_package == 'mongodb-org'
3843

3944
- name: Install MongoDB package
@@ -45,7 +50,7 @@
4550
- name: reload systemd
4651
shell: systemctl daemon-reload
4752
changed_when: false
48-
when: "'systemd' in systemd.stdout"
53+
when: mongodb_is_systemd
4954

5055
- name: Install PyMongo package
5156
apt: pkg=python-pymongo state=latest

tasks/main.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,16 @@
3030
- name: Check user admin is exists
3131
command: >
3232
mongo --quiet -u {{ mongodb_user_admin_name }} \
33-
-p {{ mongodb_user_admin_password }} --eval 'db.version()' admin
33+
-p {{ mongodb_user_admin_password }} --port {{ mongodb_net_port }} --eval 'db.version()' admin
34+
3435
register: mongodb_user_admin_check
3536
changed_when: false
37+
always_run: yes # side-effect free, so it can be run in check-mode as well
3638
ignore_errors: true
3739
when: ( mongodb_security_authorization == 'enabled'
3840
and (not mongodb_replication_replset
3941
or mongodb_replication_replset == '') )
42+
no_log: true
4043
tags: [mongodb]
4144

4245
- name: Include authorization configuration
@@ -64,6 +67,7 @@
6467
and mongodb_replication_replset != ''
6568
and mongodb_security_authorization == 'enabled'
6669
and mongodb_master is defined and mongodb_master )
70+
no_log: true
6771
tags: [mongodb]
6872

6973
- name: create normal users without replicaset
@@ -81,6 +85,7 @@
8185
when: ( mongodb_security_authorization == 'enabled'
8286
and (not mongodb_replication_replset
8387
or mongodb_replication_replset == '') )
88+
no_log: true
8489
tags: [mongodb]
8590

8691
- name: Include MMS Agent configuration

0 commit comments

Comments
 (0)