Skip to content

Commit 25c7cec

Browse files
author
Sergei Antipov
committed
Support of mongodb 3
1 parent b6e2ffe commit 25c7cec

23 files changed

+528
-205
lines changed

.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
.idea
21
*~
32
\#*\#
43
.\#*
5-
.ropeproject/
4+
/.python-version

.travis.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# .travis.yml
2+
---
3+
4+
sudo: required
5+
env:
6+
- >
7+
distribution=ubuntu-upstart
8+
version=14.04
9+
- >
10+
distribution=ubuntu-upstart
11+
version=12.04
12+
- >
13+
distribution=debian
14+
version=7
15+
16+
services:
17+
- docker
18+
19+
before_install:
20+
- sudo apt-get update
21+
# Latest Ansible install
22+
- sudo apt-add-repository -y ppa:ansible/ansible
23+
- sudo apt-get update -o Dir::Etc::sourcelist="sources.list.d/ansible-ansible-precise.list" \
24+
-o Dir::Etc::sourceparts="-" -o APT::Get::List-Cleanup="0"
25+
- sudo apt-get install ansible python-pip -y
26+
- sudo pip install docker-py
27+
# Pull docker image
28+
- docker pull ${distribution}:${version}
29+
30+
script:
31+
- ansible-playbook -i tests/hosts tests/site.yml -e target=mongo1
32+
# Idempotence test
33+
- >
34+
ansible-playbook -i tests/hosts tests/site.yml -e target=mongo1
35+
| grep -q 'changed=0.*failed=0'
36+
&& (echo 'Idempotence test: pass' && exit 0)
37+
|| (echo 'Idempotence test: fail' && exit 1)
38+
39+
# Delete all containers
40+
- docker kill mongo{1,2,3} && docker rm mongo{1,2,3}
41+

README.md

Lines changed: 65 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
Ansible role for MongoDB
22
============
3-
This repository forked from [Stouts.mongodb](https://github.com/Stouts/Stouts.mongodb).
4-
Ansible role which manage [MongoDB](http://www.mongodb.org/)
3+
Ansible role which manage [MongoDB](http://www.mongodb.org/).
54

65
* Install and configure the MongoDB;
76
* Provide handlers for restart and reload;
@@ -10,10 +9,20 @@ Ansible role which manage [MongoDB](http://www.mongodb.org/)
109
#### Variables
1110

1211
```yaml
12+
# You can use this variable to control installation source of MongoDB
13+
# 'mongodb' will be installed from Debian/Ubuntu repos
14+
# 'mongodb-org' will be installed from MongoDB official repos
1315
mongodb_package: mongodb-org
1416

17+
# You can control installed version via this param.
18+
# Should be '2.6', '3.0' or '3.2'. This role does't support MongoDB < 2.4.
19+
# I will recommend you to use latest version of MongoDB.
20+
mongodb_version: "3.2"
21+
1522
mongodb_force_wait_for_port: false # When not forced, the role will wait for mongod port to become available only with systemd
16-
mongodb_pymongo_from_pip: false # Install latest PyMongo via PIP or package manager
23+
mongodb_pymongo_from_pip: true # Install latest PyMongo via PIP or package manager
24+
mongodb_pymongo_pip_version: "3.2.2"
25+
1726
mongodb_disable_thp: true
1827

1928
mongodb_manage_service: true
@@ -22,32 +31,45 @@ mongodb_user: mongodb
2231
mongodb_uid:
2332
mongodb_gid:
2433
mongodb_daemon_name: "{{ 'mongod' if ('mongodb-org' in mongodb_package) else 'mongodb' }}"
25-
26-
mongodb_conf_auth: false # Run with security
27-
mongodb_conf_bind_ip: 127.0.0.1 # Comma separated list of ip addresses to listen on
28-
mongodb_conf_cpu: true # Periodically show cpu and iowait utilization
29-
mongodb_conf_dbpath: /data/db # Directory for datafiles
30-
mongodb_conf_fork: false # Fork server process
31-
mongodb_conf_httpinterface: false # Enable http interface
32-
mongodb_conf_ipv6: false # Enable IPv6 support (disabled by default)
33-
mongodb_conf_journal: true # Enable journaling
34-
mongodb_conf_logappend: true # Append to logpath instead of over-writing
35-
mongodb_conf_logpath: /var/log/mongodb/{{ mongodb_daemon_name }}.log # Log file to send write to instead of stdout
36-
mongodb_conf_maxConns: 1000000 # Max number of simultaneous connections
37-
mongodb_conf_noprealloc: false # Disable data file preallocation
38-
mongodb_conf_smallfiles: false # Disable smallfiles option
39-
mongodb_conf_noscripting: false # Disable scripting engine
40-
mongodb_conf_notablescan: false # Do not allow table scans
41-
mongodb_conf_port: 27017 # Specify port number
42-
mongodb_conf_quota: false # Limits each database to a certain number of files
43-
mongodb_conf_quotaFiles: 8 # Number of quota files
44-
mongodb_conf_syslog: false # Log to system's syslog facility instead of file
45-
46-
# Replica set options:
47-
mongodb_conf_replSet: # Enable replication <setname>[/<optionalseedhostlist>]
48-
mongodb_conf_replIndexPrefetch: "all" # specify index prefetching behavior (if secondary) [none|_id_only|all]
49-
mongodb_conf_oplogSize: 512 # specifies a maximum size in megabytes for the replication operation log
50-
mongodb_conf_keyFile: /etc/mongodb-keyfile # Specify path to keyfile with password for inter-process authentication
34+
## net Options
35+
mongodb_net_bindip: 127.0.0.1 # Comma separated list of ip addresses to listen on
36+
mongodb_net_http_enabled: false # Enable http interface
37+
mongodb_net_ipv6: false # Enable IPv6 support (disabled by default)
38+
mongodb_net_maxconns: 65536 # Max number of simultaneous connections
39+
mongodb_net_port: 27017 # Specify port number
40+
41+
## processManagement Options
42+
mongodb_processmanagement_fork: false # Fork server process
43+
44+
## security Options
45+
# Disable or enable security. Possible values: 'disabled', 'enabled'
46+
mongodb_security_authorization: "disabled"
47+
mongodb_security_keyfile: /etc/mongodb-keyfile # Specify path to keyfile with password for inter-process authentication
48+
49+
## storage Options
50+
mongodb_storage_dbpath: /data/db # Directory for datafiles
51+
# The storage engine for the mongod database. Available values:
52+
# 'mmapv1', 'wiredTiger'
53+
mongodb_storage_engine: "{{ 'mmapv1' if mongodb_version[0:3] == '3.0' else 'wiredTiger' }}"
54+
# mmapv1 specific options
55+
mongodb_storage_quota_enforced: false # Limits each database to a certain number of files
56+
mongodb_storage_quota_maxfiles: 8 # Number of quota files per DB
57+
mongodb_storage_smallfiles: false # Very useful for non-data nodes
58+
59+
mongodb_storage_journal_enabled: true # Enable journaling
60+
mongodb_storage_prealloc: true # Disable data file preallocation
61+
62+
## systemLog Options
63+
## The destination to which MongoDB sends all log output. Specify either 'file' or 'syslog'.
64+
## If you specify 'file', you must also specify mongodb_systemlog_path.
65+
mongodb_systemlog_destination: "file"
66+
mongodb_systemlog_logappend: true # Append to logpath instead of over-writing
67+
mongodb_systemlog_path: /var/log/mongodb/{{ mongodb_daemon_name }}.log # Log file to send write to instead of stdout
68+
69+
## replication Options
70+
mongodb_replication_replset: # Enable replication <setname>[/<optionalseedhostlist>]
71+
mongodb_replication_replindexprefetch: "all" # specify index prefetching behavior (if secondary) [none|_id_only|all]
72+
mongodb_replication_oplogsize: 1024 # specifies a maximum size in megabytes for the replication operation log
5173

5274
# MMS Agent
5375
mongodb_mms_agent_pkg: https://mms.mongodb.com/download/agent/automation/mongodb-mms-automation-agent-manager_1.4.2.783-1_amd64.deb
@@ -99,7 +121,7 @@ Add `greendayonfire.mongodb` to your roles and set vars in your playbook file.
99121

100122
Example vars for authorization:
101123
```yaml
102-
mongodb_conf_auth: true
124+
mongodb_security_authorization: true
103125
mongodb_users:
104126
- {
105127
name: testUser,
@@ -112,23 +134,34 @@ Required vars to change on production:
112134
```yaml
113135
mongodb_user_admin_password
114136
mongodb_root_admin_password
137+
138+
# if you use replication and authorization
139+
mongodb_security_keyfile
115140
```
116141
Example vars for replication:
117142
```yaml
143+
# It's a 'master' node
144+
mongodb_login_host: 192.168.56.2
145+
118146
# mongodb_replication_params should be configured on each replica set node
119147
mongodb_replication_params:
120-
- { host_name: 192.168.56.2, host_port: "{{ mongodb_conf_port }}", host_type: replica }
148+
- { host_name: 192.168.56.2, host_port: "{{ mongodb_net_port }}", host_type: replica }
121149
# host_type can be replica(default) and arbiter
122150
```
123151
And inventory file for replica set:
124152
```ini
125153
[mongo_master]
126-
192.158.56.2 mongodb_master=True # it'n not a really master of MongoDB replica set,
154+
192.158.56.2 mongodb_master=True # it is't a really master of MongoDB replica set,
127155
# use this variable for replica set init only
156+
# or when master is moved from initial master node
128157
129158
[mongo_replicas]
130159
192.168.56.3
131160
192.168.56.4
161+
162+
[mongo:children]
163+
mongo_master
164+
mongo_replicas
132165
```
133166

134167
Licensed under the GPLv2 License. See the [LICENSE.md](LICENSE.md) file for details.

defaults/main.yml

Lines changed: 44 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,60 @@
11
---
22

33
mongodb_package: mongodb-org
4-
mongodb_version: "2.6"
5-
mongodb_apt_key_url: http://docs.mongodb.org/10gen-gpg-key.asc
6-
mongodb_apt_key_id: 7F0CEB10
4+
mongodb_version: "3.2"
5+
mongodb_apt_keyserver: keyserver.ubuntu.com
6+
mongodb_apt_key_id: "{{ 'EA312927' if mongodb_version[0:3] == '3.2' else '7F0CEB10' }}"
7+
mongodb_pymongo_from_pip: true # Install latest PyMongo via PIP or package manager
8+
79
mongodb_force_wait_for_port: false
8-
mongodb_pymongo_from_pip: false # Install latest PyMongo via PIP or package manager
9-
mongodb_pymongo_pip_version: "2.9"
1010
mongodb_disable_thp: true
11-
11+
mongodb_user_update_password: "on_create" # MongoDB user password update default policy
1212
mongodb_manage_service: true
1313

1414
mongodb_user: mongodb
1515
mongodb_uid:
1616
mongodb_gid:
1717
mongodb_daemon_name: "{{ 'mongod' if ('mongodb-org' in mongodb_package) else 'mongodb' }}"
1818

19-
mongodb_conf_auth: false # Run with security
20-
mongodb_conf_bind_ip: 127.0.0.1 # Comma separated list of ip addresses to listen on
21-
mongodb_conf_cpu: true # Periodically show cpu and iowait utilization
22-
mongodb_conf_dbpath: /data/db # Directory for datafiles
23-
mongodb_conf_fork: false # Fork server process
24-
mongodb_conf_httpinterface: false # Enable http interface
25-
mongodb_conf_ipv6: false # Enable IPv6 support (disabled by default)
26-
mongodb_conf_journal: true # Enable journaling
27-
mongodb_conf_logappend: true # Append to logpath instead of over-writing
28-
mongodb_conf_logpath: /var/log/mongodb/{{ mongodb_daemon_name }}.log # Log file to send write to instead of stdout
29-
mongodb_conf_maxConns: 1000000 # Max number of simultaneous connections
30-
mongodb_conf_noprealloc: false # Disable data file preallocation
31-
mongodb_conf_smallfiles: false # Disable smallfiles option
32-
mongodb_conf_noscripting: false # Disable scripting engine
33-
mongodb_conf_notablescan: false # Do not allow table scans
34-
mongodb_conf_port: 27017 # Specify port number
35-
mongodb_conf_quota: false # Limits each database to a certain number of files
36-
mongodb_conf_quotaFiles: 8 # Number of quota files
37-
mongodb_conf_syslog: false # Log to system's syslog facility instead of file
19+
## net Options
20+
mongodb_net_bindip: 127.0.0.1 # Comma separated list of ip addresses to listen on
21+
mongodb_net_http_enabled: false # Enable http interface
22+
mongodb_net_ipv6: false # Enable IPv6 support (disabled by default)
23+
mongodb_net_maxconns: 65536 # Max number of simultaneous connections
24+
mongodb_net_port: 27017 # Specify port number
25+
26+
## processManagement Options
27+
mongodb_processmanagement_fork: false # Fork server process
28+
29+
## security Options
30+
# Disable or enable security. Possible values: 'disabled', 'enabled'
31+
mongodb_security_authorization: "disabled"
32+
mongodb_security_keyfile: /etc/mongodb-keyfile # Specify path to keyfile with password for inter-process authentication
33+
34+
## storage Options
35+
mongodb_storage_dbpath: /data/db # Directory for datafiles
36+
# The storage engine for the mongod database. Available values:
37+
# 'mmapv1', 'wiredTiger'
38+
mongodb_storage_engine: "{{ 'mmapv1' if mongodb_version[0:3] == '3.0' else 'wiredTiger' }}"
39+
# mmapv1 specific options
40+
mongodb_storage_quota_enforced: false # Limits each database to a certain number of files
41+
mongodb_storage_quota_maxfiles: 8 # Number of quota files per DB
42+
mongodb_storage_smallfiles: false # Very useful for non-data nodes
43+
44+
mongodb_storage_journal_enabled: true # Enable journaling
45+
mongodb_storage_prealloc: true # Enable data file preallocation
46+
47+
## systemLog Options
48+
## The destination to which MongoDB sends all log output. Specify either 'file' or 'syslog'.
49+
## If you specify 'file', you must also specify mongodb_systemlog_path.
50+
mongodb_systemlog_destination: "file"
51+
mongodb_systemlog_logappend: true # Append to logpath instead of over-writing
52+
mongodb_systemlog_path: /var/log/mongodb/{{ mongodb_daemon_name }}.log # Log file to send write to instead of stdout
3853

39-
# Replica set options:
40-
mongodb_conf_replSet: # Enable replication <setname>[/<optionalseedhostlist>]
41-
mongodb_conf_replIndexPrefetch: "all" # specify index prefetching behavior (if secondary) [none|_id_only|all]
42-
mongodb_conf_oplogSize: 512 # specifies a maximum size in megabytes for the replication operation log
43-
mongodb_conf_keyFile: /etc/mongodb-keyfile # Specify path to keyfile with password for inter-process authentication
54+
## replication Options
55+
mongodb_replication_replset: # Enable replication <setname>[/<optionalseedhostlist>]
56+
mongodb_replication_replindexprefetch: "all" # specify index prefetching behavior (if secondary) [none|_id_only|all]
57+
mongodb_replication_oplogsize: 1024 # specifies a maximum size in megabytes for the replication operation log
4458

4559
# MMS Agent
4660
mongodb_mms_agent_pkg: https://mms.mongodb.com/download/agent/automation/mongodb-mms-automation-agent-manager_1.4.2.783-1_amd64.deb

0 commit comments

Comments
 (0)