Skip to content

Commit b5257ff

Browse files
committed
Merge branch 'master' of github.com:UnderGreen/ansible-role-mongodb
2 parents bf8ff69 + 7a03b85 commit b5257ff

18 files changed

+129
-581
lines changed

.travis.yml

Lines changed: 8 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
# .travis.yml
22
---
33

4+
dist: trusty
45
sudo: required
6+
language: python
7+
python:
8+
- "2.7"
9+
- "3.6"
510
env:
611
- >
712
DISTRIBUTION=ubuntu-upstart
@@ -11,38 +16,6 @@ env:
1116
DISTRIBUTION=ubuntu-upstart
1217
DIST_VERSION=14.04
1318
MONGODB_VERSION=3.2
14-
- >
15-
DISTRIBUTION=ubuntu-upstart
16-
DIST_VERSION=14.04
17-
MONGODB_VERSION=3.0
18-
- >
19-
DISTRIBUTION=ubuntu-upstart
20-
DIST_VERSION=14.04
21-
MONGODB_VERSION=2.6
22-
- >
23-
DISTRIBUTION=ubuntu-upstart
24-
DIST_VERSION=12.04-builded
25-
MONGODB_VERSION=3.4
26-
- >
27-
DISTRIBUTION=ubuntu-upstart
28-
DIST_VERSION=12.04-builded
29-
MONGODB_VERSION=3.2
30-
- >
31-
DISTRIBUTION=ubuntu-upstart
32-
DIST_VERSION=12.04-builded
33-
MONGODB_VERSION=3.0
34-
- >
35-
DISTRIBUTION=ubuntu-upstart
36-
DIST_VERSION=12.04-builded
37-
MONGODB_VERSION=2.6
38-
- >
39-
DISTRIBUTION=centos
40-
DIST_VERSION=6-builded
41-
MONGODB_VERSION=2.6
42-
- >
43-
DISTRIBUTION=centos
44-
DIST_VERSION=6-builded
45-
MONGODB_VERSION=3.0
4619
- >
4720
DISTRIBUTION=centos
4821
DIST_VERSION=6-builded
@@ -51,14 +24,6 @@ env:
5124
DISTRIBUTION=centos
5225
DIST_VERSION=6-builded
5326
MONGODB_VERSION=3.4
54-
- >
55-
DISTRIBUTION=centos
56-
DIST_VERSION=7-builded
57-
MONGODB_VERSION=2.6
58-
- >
59-
DISTRIBUTION=centos
60-
DIST_VERSION=7-builded
61-
MONGODB_VERSION=3.0
6227
- >
6328
DISTRIBUTION=centos
6429
DIST_VERSION=7-builded
@@ -68,84 +33,14 @@ env:
6833
DIST_VERSION=7-builded
6934
MONGODB_VERSION=3.4
7035
# - >
71-
# distribution=ubuntu-upstart
72-
# version=12.04
73-
# - >
7436
# distribution=debian
7537
# version=7
7638

7739
services:
7840
- docker
7941

80-
before_install:
81-
- sudo apt-get update
82-
# Latest Ansible install
83-
- sudo apt-add-repository -y ppa:ansible/ansible
84-
- sudo apt-get update
85-
- sudo apt-get install ansible python-pip -y
86-
- sudo pip install docker-py==1.5.0
87-
# Pull docker image or build it
88-
- >
89-
if [ -f tests/Dockerfile.${DISTRIBUTION}_${DIST_VERSION} ]; then
90-
sudo docker build --rm=true --file=tests/Dockerfile.${DISTRIBUTION}_${DIST_VERSION}
91-
--tag ${DISTRIBUTION}:${DIST_VERSION} tests; else sudo docker pull ${DISTRIBUTION}:${DIST_VERSION}; fi
92-
- sudo ln -s ${PWD} /etc/ansible/roles/greendayonfire.mongodb
42+
install:
43+
- bash tests/scripts/before_install.sh
9344

9445
script:
95-
# Test 1
96-
- >
97-
sudo ansible-playbook -i tests/hosts tests/site.yml -e target=mongo1 -e mongodb_version=${MONGODB_VERSION} -e image_name=${DISTRIBUTION}:${DIST_VERSION}
98-
# Idempotence test
99-
- >
100-
sudo ansible-playbook -i tests/hosts tests/site.yml -e target=mongo1 -e mongodb_version=${MONGODB_VERSION} -e image_name=${DISTRIBUTION}:${DIST_VERSION}
101-
| grep -q 'changed=0.*failed=0'
102-
&& (echo 'Idempotence test: pass' && exit 0)
103-
|| (echo 'Idempotence test: fail' && exit 1)
104-
105-
# Delete all containers
106-
- sudo docker kill mongo{1,2,3} && docker rm mongo{1,2,3}
107-
108-
# Test 2
109-
- >
110-
sudo ansible-playbook -i tests/hosts tests/site.yml -e target=mongo1 -e image_name=${DISTRIBUTION}:${DIST_VERSION}
111-
-e mongodb_version=${MONGODB_VERSION} -e mongodb_security_authorization='enabled'
112-
# Idempotence test
113-
- >
114-
sudo ansible-playbook -i tests/hosts tests/site.yml -e target=mongo1 -e image_name=${DISTRIBUTION}:${DIST_VERSION}
115-
-e mongodb_version=${MONGODB_VERSION} -e mongodb_security_authorization='enabled'
116-
| grep -q 'changed=0.*failed=0'
117-
&& (echo 'Idempotence test: pass' && exit 0)
118-
|| (echo 'Idempotence test: fail' && exit 1)
119-
120-
# Delete all containers
121-
- sudo docker kill mongo{1,2,3} && docker rm mongo{1,2,3}
122-
123-
# Test 3
124-
- >
125-
sudo ansible-playbook -i tests/hosts tests/site.yml -e target=mongo -e image_name=${DISTRIBUTION}:${DIST_VERSION}
126-
-e mongodb_version=${MONGODB_VERSION} -e mongodb_replication_replset='testrs'
127-
# Idempotence test
128-
- >
129-
sudo ansible-playbook -i tests/hosts tests/site.yml -e target=mongo -e image_name=${DISTRIBUTION}:${DIST_VERSION}
130-
-e mongodb_version=${MONGODB_VERSION} -e mongodb_replication_replset='testrs'
131-
| grep -q 'changed=0.*failed=0'
132-
&& (echo 'Idempotence test: pass' && exit 0)
133-
|| (echo 'Idempotence test: fail' && exit 1)
134-
135-
# Delete all containers
136-
- sudo docker kill mongo{1,2,3} && docker rm mongo{1,2,3}
137-
138-
# Test 4
139-
- >
140-
sudo ansible-playbook -i tests/hosts tests/site.yml -e target=mongo -e image_name=${DISTRIBUTION}:${DIST_VERSION}
141-
-e mongodb_version=${MONGODB_VERSION} -e mongodb_replication_replset='testrs'
142-
-e mongodb_security_authorization='enabled'
143-
# Idempotence test
144-
- >
145-
sudo ansible-playbook -i tests/hosts tests/site.yml -e target=mongo -e image_name=${DISTRIBUTION}:${DIST_VERSION}
146-
-e mongodb_version=${MONGODB_VERSION} -e mongodb_replication_replset='testrs'
147-
-e mongodb_security_authorization='enabled'
148-
| grep -q 'changed=0.*failed=0'
149-
&& (echo 'Idempotence test: pass' && exit 0)
150-
|| (echo 'Idempotence test: fail' && exit 1)
151-
46+
- bash tests/scripts/test.sh

README.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,15 @@ MongoDB support matrix:
1313
| Distribution | MongoDB 2.4 | MongoDB 2.6 | MongoDB 3.0 | MongoDB 3.2 | MongoDB 3.4 |
1414
| ------------ |:-----------:|:-----------:|:-----------:|:-----------:|:-----------:|
1515
| 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:|
1716
| Ubuntu 16.04 | :no_entry: | :x: | :x: | :x:| :x:|
18-
| Debian 7.x | :no_entry: | :interrobang: | :interrobang: | :interrobang:| :x:|
1917
| Debian 8.x | :no_entry: | :x: | :x: | :x:| :x:|
18+
| Debian 9.x | :no_entry: | :x: | :x: | :x:| :x:|
2019
| RHEL 6.x | :no_entry: | :interrobang: | :interrobang: | :interrobang: | :interrobang: |
2120
| RHEL 7.x | :no_entry: | :interrobang: | :interrobang: | :interrobang: | :interrobang: |
2221

23-
:white_check_mark: - fully tested, should work fine
24-
:interrobang: - will be added testing suite soon
25-
:x: - don't have official support
22+
:white_check_mark: - fully tested, should work fine
23+
:interrobang: - will be added testing suite soon
24+
:x: - don't have official support
2625
:no_entry: - does't have support, because used old format of configuration files
2726

2827
#### Variables
@@ -89,7 +88,7 @@ mongodb_replication_oplogsize: 1024 # specifies a maximum size in
8988

9089
## setParameter options
9190
# Configure setParameter option.
92-
# Example :
91+
# Example :
9392
mongodb_set_parameters: { "enableLocalhostAuthBypass": "true", "authenticationMechanisms": "SCRAM-SHA-1,MONGODB-CR" }
9493

9594
# MMS Agent

defaults/main.yml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
---
22

33
mongodb_package: mongodb-org
4-
mongodb_version: "3.4"
4+
mongodb_version: "3.6"
55
mongodb_apt_keyserver: keyserver.ubuntu.com
66
mongodb_apt_key_id:
7-
"2.6": "7F0CEB10"
8-
"3.0": "7F0CEB10"
97
"3.2": "EA312927"
108
"3.4": "0C49F3730359A14518585931BC711F9BA15703C6"
9+
"3.6": "2930ADAE8CAF5059EE73BB4B58712A2291FA4AD5"
1110

1211
mongodb_pymongo_from_pip: true # Install latest PyMongo via PIP or package manager
1312

@@ -41,7 +40,7 @@ mongodb_security_keyfile: /etc/mongodb-keyfile # Specify path to keyfile with
4140
mongodb_storage_dbpath: /data/db # Directory for datafiles
4241
# The storage engine for the mongod database. Available values:
4342
# 'mmapv1', 'wiredTiger'
44-
mongodb_storage_engine: "{{ 'mmapv1' if mongodb_version[0:3] == '3.0' else 'wiredTiger' }}"
43+
mongodb_storage_engine: "wiredTiger"
4544
# mmapv1 specific options
4645
mongodb_storage_quota_enforced: false # Limits each database to a certain number of files
4746
mongodb_storage_quota_maxfiles: 8 # Number of quota files per DB
@@ -95,8 +94,8 @@ mongodb_user_admin_password: passw0rd
9594
mongodb_root_admin_name: siteRootAdmin
9695
mongodb_root_admin_password: passw0rd
9796

98-
mongodb_root_backup_name: "backupuser"
99-
mongodb_root_backup_password: "passw0rd"
97+
mongodb_root_backup_name: backupuser
98+
mongodb_root_backup_password: passw0rd
10099

101100
# setParameter config
102101
mongodb_set_parameters:

library/mongodb_replication.py

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/python
22

3-
# (c) 2015-2016, Sergei Antipov, 2GIS LLC
3+
# (c) 2015-2018, Sergei Antipov, 2GIS LLC
44
#
55
# This file is part of Ansible
66
#
@@ -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.2"
26+
version_added: "2.4"
2727
options:
2828
login_user:
2929
description:
@@ -105,7 +105,7 @@
105105
default: present
106106
choices: [ "present", "absent" ]
107107
notes:
108-
- Requires the pymongo Python package on the remote host, version 3.0+. It
108+
- Requires the pymongo Python package on the remote host, version 3.2+. It
109109
can be installed using pip or the OS package manager. @see http://api.mongodb.org/python/current/installation.html
110110
requirements: [ "pymongo" ]
111111
author: "Sergei Antipov @UnderGreen"
@@ -166,11 +166,14 @@
166166
# MongoDB module specific support methods.
167167
#
168168
def check_compatibility(module, client):
169-
if LooseVersion(PyMongoVersion) <= LooseVersion('3.0'):
170-
module.fail_json(msg='Note: you must use pymongo 3.0+')
171169
srv_info = client.server_info()
172-
if LooseVersion(srv_info['version']) >= LooseVersion('3.2') and LooseVersion(PyMongoVersion) <= LooseVersion('3.2'):
173-
module.fail_json(msg=' (Note: you must use pymongo 3.2+ with MongoDB >= 3.2)')
170+
if LooseVersion(PyMongoVersion) <= LooseVersion('3.2'):
171+
module.fail_json(msg='Note: you must use pymongo 3.2+')
172+
if LooseVersion(srv_info['version']) >= LooseVersion('3.4') and LooseVersion(PyMongoVersion) <= LooseVersion('3.4'):
173+
module.fail_json(msg='Note: you must use pymongo 3.4+ with MongoDB 3.4.x')
174+
if LooseVersion(srv_info['version']) >= LooseVersion('3.6') and LooseVersion(PyMongoVersion) <= LooseVersion('3.6'):
175+
module.fail_json(msg='Note: you must use pymongo 3.6+ with MongoDB 3.6.x')
176+
174177

175178
def check_members(state, module, client, host_name, host_port, host_type):
176179
admin_db = client['admin']
@@ -236,7 +239,7 @@ def add_host(module, client, host_name, host_port, host_type, timeout=180, **kwa
236239
cfg['members'].append(new_host)
237240
admin_db.command('replSetReconfig', cfg)
238241
return
239-
except (OperationFailure, AutoReconnect), e:
242+
except (OperationFailure, AutoReconnect) as e:
240243
timeout = timeout - 5
241244
if timeout <= 0:
242245
module.fail_json(msg='reached timeout while waiting for rs.reconfig(): %s' % str(e))
@@ -265,7 +268,7 @@ def remove_host(module, client, host_name, timeout=180):
265268
else:
266269
fail_msg = "couldn't find member with hostname: {0} in replica set members list".format(host_name)
267270
module.fail_json(msg=fail_msg)
268-
except (OperationFailure, AutoReconnect), e:
271+
except (OperationFailure, AutoReconnect) as e:
269272
timeout = timeout - 5
270273
if timeout <= 0:
271274
module.fail_json(msg='reached timeout while waiting for rs.reconfig(): %s' % str(e))
@@ -318,7 +321,7 @@ def main():
318321
module = AnsibleModule(
319322
argument_spec = dict(
320323
login_user=dict(default=None),
321-
login_password=dict(default=None),
324+
login_password=dict(default=None, no_log=True),
322325
login_host=dict(default='localhost'),
323326
login_port=dict(default='27017'),
324327
replica_set=dict(default=None),
@@ -374,9 +377,9 @@ def main():
374377
wait_for_ok_and_master(module, client)
375378
replica_set_created = True
376379
module.exit_json(changed=True, host_name=host_name, host_port=host_port, host_type=host_type)
377-
except OperationFailure, e:
380+
except OperationFailure as e:
378381
module.fail_json(msg='Unable to initiate replica set: %s' % str(e))
379-
except ConnectionFailure, e:
382+
except ConnectionFailure as e:
380383
module.fail_json(msg='unable to connect to database: %s' % str(e))
381384

382385
check_compatibility(module, client)
@@ -394,13 +397,13 @@ def main():
394397
priority = float(module.params['priority']),
395398
slave_delay = module.params['slave_delay'],
396399
votes = module.params['votes'])
397-
except OperationFailure, e:
400+
except OperationFailure as e:
398401
module.fail_json(msg='Unable to add new member to replica set: %s' % str(e))
399402

400403
elif state == 'absent':
401404
try:
402405
remove_host(module, client, host_name)
403-
except OperationFailure, e:
406+
except OperationFailure as e:
404407
module.fail_json(msg='Unable to remove member of replica set: %s' % str(e))
405408

406409
module.exit_json(changed=True, host_name=host_name, host_port=host_port, host_type=host_type)

0 commit comments

Comments
 (0)