Add puppetlabs-mongodb
This is a verbatim copy of upstream https://github.com/puppetlabs/puppetlabs-mongodb v0.7.0 c5e672581664c326b9f0dc4071d9d79c764e40cc Partial (Stage 2) blueprint: ceilometer-fuel-integraition Change-Id: Icbd908ff855cd5320c961ec198ccc536baf204e5 Signed-off-by: Bogdan Dobrelya <bdobrelia@mirantis.com>
This commit is contained in:
parent
101f3645ea
commit
3aff1017bc
6
deployment/puppet/mongodb/.fixtures.yml
Normal file
6
deployment/puppet/mongodb/.fixtures.yml
Normal file
@ -0,0 +1,6 @@
|
||||
fixtures:
|
||||
repositories:
|
||||
"stdlib": "git://github.com/puppetlabs/puppetlabs-stdlib.git"
|
||||
"apt": "git://github.com/puppetlabs/puppetlabs-apt.git"
|
||||
symlinks:
|
||||
"mongodb": "#{source_dir}"
|
9
deployment/puppet/mongodb/.gitignore
vendored
Normal file
9
deployment/puppet/mongodb/.gitignore
vendored
Normal file
@ -0,0 +1,9 @@
|
||||
Gemfile.lock
|
||||
metadata.json
|
||||
*.idea
|
||||
*.swp
|
||||
*.tmp
|
||||
tmp/
|
||||
pkg/
|
||||
spec/fixtures/manifests
|
||||
.rspec_system/
|
31
deployment/puppet/mongodb/.nodeset.yml
Normal file
31
deployment/puppet/mongodb/.nodeset.yml
Normal file
@ -0,0 +1,31 @@
|
||||
---
|
||||
default_set: 'centos-64-x64'
|
||||
sets:
|
||||
'centos-59-x64':
|
||||
nodes:
|
||||
"main.foo.vm":
|
||||
prefab: 'centos-59-x64'
|
||||
'centos-64-x64':
|
||||
nodes:
|
||||
"main.foo.vm":
|
||||
prefab: 'centos-64-x64'
|
||||
'fedora-18-x64':
|
||||
nodes:
|
||||
"main.foo.vm":
|
||||
prefab: 'fedora-18-x64'
|
||||
'debian-607-x64':
|
||||
nodes:
|
||||
"main.foo.vm":
|
||||
prefab: 'debian-607-x64'
|
||||
'debian-70rc1-x64':
|
||||
nodes:
|
||||
"main.foo.vm":
|
||||
prefab: 'debian-70rc1-x64'
|
||||
'ubuntu-server-10044-x64':
|
||||
nodes:
|
||||
"main.foo.vm":
|
||||
prefab: 'ubuntu-server-10044-x64'
|
||||
'ubuntu-server-12042-x64':
|
||||
nodes:
|
||||
"main.foo.vm":
|
||||
prefab: 'ubuntu-server-12042-x64'
|
33
deployment/puppet/mongodb/.travis.yml
Normal file
33
deployment/puppet/mongodb/.travis.yml
Normal file
@ -0,0 +1,33 @@
|
||||
branches:
|
||||
only:
|
||||
- master
|
||||
language: ruby
|
||||
before_install:
|
||||
- gem update bundler
|
||||
- bundle --version
|
||||
- gem update --system 2.1.11
|
||||
- gem --version
|
||||
bundler_args: --without development
|
||||
script: "bundle exec rake spec SPEC_OPTS='--format documentation'"
|
||||
after_success:
|
||||
- git clone -q git://github.com/puppetlabs/ghpublisher.git .forge-release
|
||||
- .forge-release/publish
|
||||
rvm:
|
||||
- 1.8.7
|
||||
- 1.9.3
|
||||
- 2.0.0
|
||||
env:
|
||||
matrix:
|
||||
- PUPPET_GEM_VERSION="~> 2.7.0"
|
||||
- PUPPET_GEM_VERSION="~> 3.3.0"
|
||||
global:
|
||||
- PUBLISHER_LOGIN=puppetlabs
|
||||
- secure: "iUYpjvk33JffZB9lVRqjuwRWesvcvmTknh908xnf60rUOA0QbGEPXxQY+LsQJEIimVsMA22fV6vp9BcqMEjO7OfK2MvAWsEWU/lG+kisFqhWDRf96sADE7k/RvPWJeB2xe+lWXK7Eh26jgctNfk4NptX1X1MjGmdzEvH7Aq79/w="
|
||||
matrix:
|
||||
exclude:
|
||||
- rvm: 1.9.3
|
||||
env: PUPPET_GEM_VERSION="~> 2.7.0"
|
||||
- rvm: 2.0.0
|
||||
env: PUPPET_GEM_VERSION="~> 2.7.0"
|
||||
notifications:
|
||||
email: false
|
52
deployment/puppet/mongodb/CHANGELOG
Normal file
52
deployment/puppet/mongodb/CHANGELOG
Normal file
@ -0,0 +1,52 @@
|
||||
2014-1-29 - Version 0.7.0
|
||||
|
||||
Summary:
|
||||
|
||||
Added Replica Set Type and Provider
|
||||
|
||||
2014-1-17 - Version 0.6.0
|
||||
|
||||
Summary:
|
||||
|
||||
Added support for installing MongoDB client on
|
||||
RHEL family systems.
|
||||
|
||||
2014-01-10 Version 0.5.0
|
||||
|
||||
Summary:
|
||||
|
||||
Added types for providers for Mongo users and databases.
|
||||
|
||||
2013-12 Version 0.4.0
|
||||
|
||||
Major refactoring of the MongoDB module. Includes a new 'mongodb::globals'
|
||||
that consolidates many shared parameters into one location. This is an
|
||||
API-breaking release in anticipation of a 1.0 release.
|
||||
|
||||
2013-10-31 - Version 0.3.0
|
||||
|
||||
Summary:
|
||||
|
||||
Adds a number of parameters and fixes some platform
|
||||
specific bugs in module deployment.
|
||||
|
||||
2013-09-25 - Version 0.2.0
|
||||
|
||||
Summary:
|
||||
|
||||
This release fixes a duplicate parameter.
|
||||
|
||||
Fixes:
|
||||
- Fix a duplicated parameter.
|
||||
|
||||
2012-07-13 Puppet Labs <info@puppetlabs.com> - 0.1.0
|
||||
* Add support for RHEL/CentOS
|
||||
* Change default mongodb install location to OS repo
|
||||
|
||||
2012-05-29 Puppet Labs <info@puppetlabs.com> - 0.0.2
|
||||
* Fix Modulefile typo.
|
||||
* Remove repo pin.
|
||||
* Update spec tests and add travis support.
|
||||
|
||||
2012-05-03 Puppet Labs <info@puppetlabs.com> - 0.0.1
|
||||
* Initial Release.
|
17
deployment/puppet/mongodb/Gemfile
Normal file
17
deployment/puppet/mongodb/Gemfile
Normal file
@ -0,0 +1,17 @@
|
||||
source 'https://rubygems.org'
|
||||
|
||||
group :test, :development do
|
||||
gem 'rspec-puppet', :require => false
|
||||
gem 'rake', :require => false
|
||||
gem 'puppetlabs_spec_helper', :require => false
|
||||
gem 'rspec-system', :require => false
|
||||
gem 'rspec-system-puppet', :require => false
|
||||
gem 'rspec-system-serverspec', :require => false
|
||||
gem 'serverspec', :require => false
|
||||
end
|
||||
|
||||
if puppetversion = ENV['PUPPET_VERSION']
|
||||
gem 'puppet', puppetversion, :require => false
|
||||
else
|
||||
gem 'puppet', :require => false
|
||||
end
|
15
deployment/puppet/mongodb/LICENSE
Normal file
15
deployment/puppet/mongodb/LICENSE
Normal file
@ -0,0 +1,15 @@
|
||||
Copyright (C) 2012 Puppet Labs Inc
|
||||
|
||||
Puppet Labs can be contacted at: info@puppetlabs.com
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
12
deployment/puppet/mongodb/Modulefile
Normal file
12
deployment/puppet/mongodb/Modulefile
Normal file
@ -0,0 +1,12 @@
|
||||
name 'puppetlabs-mongodb'
|
||||
version '0.7.0'
|
||||
source 'git@github.com:puppetlabs/puppetlabs-mongodb.git'
|
||||
author 'puppetlabs'
|
||||
license 'Apache License Version 2.0'
|
||||
summary 'mongodb puppet module'
|
||||
description '10gen mongodb puppet module'
|
||||
project_page 'https://github.com/puppetlabs/puppetlabs-mongodb'
|
||||
|
||||
## Add dependencies, if any:
|
||||
dependency 'puppetlabs/apt', '>= 1.0.0'
|
||||
dependency 'puppetlabs/stdlib', '>= 2.2.0'
|
508
deployment/puppet/mongodb/README.md
Normal file
508
deployment/puppet/mongodb/README.md
Normal file
@ -0,0 +1,508 @@
|
||||
# mongodb puppet module
|
||||
|
||||
[![Build Status](https://travis-ci.org/puppetlabs/puppetlabs-mongodb.png?branch=master)](https://travis-ci.org/puppetlabs/puppetlabs-mongodb)
|
||||
|
||||
####Table of Contents
|
||||
|
||||
1. [Overview] (#overview)
|
||||
2. [Module Description - What does the module do?](#module-description)
|
||||
3. [Setup - The basics of getting started with mongodb](#setup)
|
||||
4. [Usage - Configuration options and additional functionality](#usage)
|
||||
5. [Reference - An under-the-hood peek at what the module is doing and how](#reference)
|
||||
6. [Limitations - OS compatibility, etc.] (#limitations)
|
||||
7. [Development - Guide for contributing to the module] (#development)
|
||||
|
||||
## Overview
|
||||
|
||||
Installs MongoDB on RHEL/Ubuntu/Debian from OS repo, or alternatively from
|
||||
10gen repository [installation documentation](http://www.mongodb.org/display/DOCS/Ubuntu+and+Debian+packages).
|
||||
|
||||
### Deprecation Warning ###
|
||||
|
||||
This release is a major refactoring of the module which means that the API may
|
||||
have changed in backwards incompatible ways. If your project depends on the old API,
|
||||
please pin your dependencies to 0.3 version to ensure your environments don't break.
|
||||
|
||||
The current module design is undergoing review for potential 1.0 release. We welcome
|
||||
any feedback with regard to the APIs and patterns used in this release.
|
||||
|
||||
##Module Description
|
||||
|
||||
The MongoDB module manages mongod server installation and configuration of the
|
||||
mongod daemon. For the time being it supports only a single MongoDB server
|
||||
instance, without sharding functionality.
|
||||
|
||||
For the 0.5 release, the MongoDB module now supports database and user types.
|
||||
|
||||
For the 0.6 release, the MongoDB module now supports basic replicaset features
|
||||
(initiating a replicaset and adding members, but without specific options).
|
||||
|
||||
## Setup
|
||||
|
||||
###What MongoDB affects
|
||||
|
||||
* MongoDB package.
|
||||
* MongoDB configuration files.
|
||||
* MongoDB service.
|
||||
* MongoDB client.
|
||||
* 10gen/mongodb apt/yum repository.
|
||||
|
||||
###Beginning with MongoDB
|
||||
|
||||
If you just want a server installation with the default options you can run
|
||||
`include '::mongodb::server'`. If you need to customize configuration
|
||||
options you need to do the following:
|
||||
|
||||
```puppet
|
||||
class {'::mongodb::server':
|
||||
port => 27018,
|
||||
verbose => true,
|
||||
}
|
||||
```
|
||||
|
||||
For Red Hat family systems, the client can be installed in a similar fashion:
|
||||
|
||||
```
|
||||
puppet class {'::mongodb::client':}
|
||||
```
|
||||
|
||||
Note that for Debian/Ubuntu family systems the client is installed with the
|
||||
server. Using the client class will by default install the server.
|
||||
|
||||
Although most distros come with a prepacked MongoDB server we recommend to
|
||||
use the 10gen/MongoDB software repository, because most of the current OS
|
||||
packages are outdated and not appropriate for a production environment.
|
||||
To install MongoDB from 10gen repository:
|
||||
|
||||
```puppet
|
||||
class {'::mongodb::globals':
|
||||
manage_package_repo => true,
|
||||
}->
|
||||
class {'::mongodb::server': }->
|
||||
class {'::mongodb::client': }
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
Most of the interaction for the server is done via `mongodb::server`. For
|
||||
more options please have a look at [mongodb::server](#class-mongodbserver).
|
||||
Also in this version we introduced `mongodb::globals`, which is meant more
|
||||
for future implementation, where you can configure the main settings for
|
||||
this module in a global way, to be used by other classes and defined resources.
|
||||
On its own it does nothing.
|
||||
|
||||
### Create MongoDB database
|
||||
|
||||
To install MongoDB server, create database "testdb" and user "user1" with password "pass1".
|
||||
|
||||
```puppet
|
||||
class {'::mongodb::server':
|
||||
auth => true,
|
||||
}
|
||||
|
||||
mongodb::db { 'testdb':
|
||||
user => 'user1',
|
||||
password_hash => 'a15fbfca5e3a758be80ceaf42458bcd8',
|
||||
}
|
||||
```
|
||||
Parameter 'password_hash' is hex encoded md5 hash of "user1:mongo:pass1".
|
||||
Unsafe plain text password could be used with 'password' parameter instead of 'password_hash'.
|
||||
|
||||
## Reference
|
||||
|
||||
### Classes
|
||||
|
||||
####Public classes
|
||||
* `mongodb::server`: Installs and configure MongoDB
|
||||
* `mongodb::client`: Installs the MongoDB client shell (for Red Hat family systems)
|
||||
* `mongodb::globals`: Configure main settings in a global way
|
||||
|
||||
####Private classes
|
||||
* `mongodb::repo`: Manage 10gen/MongoDB software repository
|
||||
* `mongodb::repo::apt`: Manage Debian/Ubuntu apt 10gen/MongoDB repository
|
||||
* `mongodb::repo::yum`: Manage Redhat/CentOS apt 10gen/MongoDB repository
|
||||
* `mongodb::server::config`: Configures MongoDB configuration files
|
||||
* `mongodb::server::install`: Install MongoDB software packages
|
||||
* `mongodb::server::service`: Manages service
|
||||
* `mongodb::client::install`: Installs the MongoDB client software package
|
||||
|
||||
####Class: mongodb::globals
|
||||
*Note:* most server specific defaults should be overridden in the `mongodb::server`
|
||||
class. This class should only be used if you are using a non-standard OS or
|
||||
if you are changing elements such as `version` or `manage_package_repo` that
|
||||
can only be changed here.
|
||||
|
||||
This class allows you to configure the main settings for this module in a
|
||||
global way, to be used by the other classes and defined resources. On its
|
||||
own it does nothing.
|
||||
|
||||
#####`server_package_name`
|
||||
This setting can be used to override the default MongoDB server package
|
||||
name. If not specified, the module will use whatever package name is the
|
||||
default for your OS distro.
|
||||
|
||||
#####`service_name`
|
||||
This setting can be used to override the default MongoDB service name. If not
|
||||
specified, the module will use whatever service name is the default for your OS distro.
|
||||
|
||||
#####`service_provider`
|
||||
This setting can be used to override the default MongoDB service provider. If
|
||||
not specified, the module will use whatever service provider is the default for
|
||||
your OS distro.
|
||||
|
||||
#####`service_status`
|
||||
This setting can be used to override the default status check command for
|
||||
your MongoDB service. If not specified, the module will use whatever service
|
||||
name is the default for your OS distro.
|
||||
|
||||
#####`user`
|
||||
This setting can be used to override the default MongoDB user and owner of the
|
||||
service and related files in the file system. If not specified, the module will
|
||||
use the default for your OS distro.
|
||||
|
||||
#####`group`
|
||||
This setting can be used to override the default MongoDB user group to be used
|
||||
for related files in the file system. If not specified, the module will use
|
||||
the default for your OS distro.
|
||||
|
||||
#####`bind_ip`
|
||||
This setting can be used to configure MonogDB process to bind to and listen
|
||||
for connections from applications on this address. If not specified, the
|
||||
module will use the default for your OS distro.
|
||||
*Note:* This value should be passed as an array.
|
||||
|
||||
#####`version`
|
||||
The version of MonogDB to install/manage. This is a simple way of providing
|
||||
a specific version such as '2.2' or '2.4' for example. If not specified,
|
||||
the module will use the default for your OS distro.
|
||||
|
||||
####Class: mongodb::server
|
||||
|
||||
Most of the parameters manipulate the mongod.conf file.
|
||||
|
||||
For more details about configuration parameters consult the
|
||||
[MongoDB Configuration File Options](http://docs.mongodb.org/manual/reference/configuration-options/).
|
||||
|
||||
#####`ensure`
|
||||
enable or disable the service
|
||||
|
||||
#####`config`
|
||||
Path of the config file. If not specified, the module will use the default
|
||||
for your OS distro.
|
||||
|
||||
#####`dbpath`
|
||||
Set this value to designate a directory for the mongod instance to store
|
||||
it's data. If not specified, the module will use the default for your OS distro.
|
||||
|
||||
#####`pidfilepath`
|
||||
Specify a file location to hold the PID or process ID of the mongod process.
|
||||
If not specified, the module will use the default for your OS distro.
|
||||
|
||||
#####`logpath`
|
||||
Specify the path to a file name for the log file that will hold all diagnostic
|
||||
logging information. Unless specified, mongod will output all log information
|
||||
to the standard output.
|
||||
|
||||
#####`bind_ip`
|
||||
Set this option to configure the mongod or mongos process to bind to and listen
|
||||
for connections from applications on this address. If not specified, the module
|
||||
will use the default for your OS distro. Example: bind_ip=['127.0.0.1', '192.168.0.3']
|
||||
*Note*: bind_ip accepts an array as a value.
|
||||
|
||||
#####`logappend`
|
||||
Set to true to add new entries to the end of the logfile rather than overwriting
|
||||
the content of the log when the process restarts. Default: True
|
||||
|
||||
#####`fork`
|
||||
Set to true to fork server process at launch time. The default setting depends on
|
||||
the operating system.
|
||||
|
||||
#####`port`
|
||||
Specifies a TCP port for the server instance to listen for client connections.
|
||||
Default: 27017
|
||||
|
||||
#####`journal`
|
||||
Set to true to enable operation journaling to ensure write durability and
|
||||
data consistency. Default: on 64-bit systems true and on 32-bit systems false
|
||||
|
||||
#####`nojournal`
|
||||
Set nojournal = true to disable durability journaling. By default, mongod
|
||||
enables journaling in 64-bit versions after v2.0.
|
||||
Default: on 64-bit systems false and on 32-bit systems true
|
||||
|
||||
*Note*: You must use journal to enable journaling on 32-bit systems.
|
||||
|
||||
#####`smallfiles`
|
||||
Set to true to modify MongoDB to use a smaller default data file size.
|
||||
Specifically, smallfiles reduces the initial size for data files and
|
||||
limits them to 512 megabytes. Default: false
|
||||
|
||||
#####`cpu`
|
||||
Set to true to force mongod to report every four seconds CPU utilization
|
||||
and the amount of time that the processor waits for I/O operations to
|
||||
complete (i.e. I/O wait.) Default: false
|
||||
|
||||
#####`auth`
|
||||
Set to true to enable database authentication for users connecting from
|
||||
remote hosts. If no users exist, the localhost interface will continue
|
||||
to have access to the database until you create the first user.
|
||||
Default: false
|
||||
|
||||
#####`noauth`
|
||||
Disable authentication. Currently the default. Exists for future compatibility
|
||||
and clarity.
|
||||
|
||||
#####`verbose`
|
||||
Increases the amount of internal reporting returned on standard output or in
|
||||
the log file generated by `logpath`. Default: false
|
||||
|
||||
#####`verbositylevel`
|
||||
MongoDB has the following levels of verbosity: v, vv, vvv, vvvv and vvvvv.
|
||||
Default: None
|
||||
|
||||
#####`objcheck`
|
||||
Forces the mongod to validate all requests from clients upon receipt to ensure
|
||||
that clients never insert invalid documents into the database.
|
||||
Default: on v2.4 default to true and on earlier version to false
|
||||
|
||||
#####`quota`
|
||||
Set to true to enable a maximum limit for the number of data files each database
|
||||
can have. The default quota is 8 data files, when quota is true. Default: false
|
||||
|
||||
#####`quotafiles`
|
||||
Modify limit on the number of data files per database. This option requires the
|
||||
`quota` setting. Default: 8
|
||||
|
||||
#####`diaglog`
|
||||
Creates a very verbose diagnostic log for troubleshooting and recording various
|
||||
errors. Valid values: 0, 1, 2, 3 and 7.
|
||||
For more information please refer to [MongoDB Configuration File Options](http://docs.mongodb.org/manual/reference/configuration-options/).
|
||||
|
||||
#####`directoryperdb`
|
||||
Set to true to modify the storage pattern of the data directory to store each
|
||||
database’s files in a distinct folder. Default: false
|
||||
|
||||
#####`profile`
|
||||
Modify this value to changes the level of database profiling, which inserts
|
||||
information about operation performance into output of mongod or the
|
||||
log file if specified by `logpath`.
|
||||
|
||||
#####`maxconns`
|
||||
Specifies a value to set the maximum number of simultaneous connections
|
||||
that MongoDB will accept. Default: depends on system (i.e. ulimit and file descriptor)
|
||||
limits. Unless set, MongoDB will not limit its own connections.
|
||||
|
||||
#####`oplog_size`
|
||||
Specifies a maximum size in megabytes for the replication operation log
|
||||
(e.g. oplog.) mongod creates an oplog based on the maximum amount of space
|
||||
available. For 64-bit systems, the oplog is typically 5% of available disk space.
|
||||
|
||||
#####`nohints`
|
||||
Ignore query hints. Default: None
|
||||
|
||||
#####`nohttpinterface`
|
||||
Set to true to disable the HTTP interface. This command will override the rest
|
||||
and disable the HTTP interface if you specify both. Default: false
|
||||
|
||||
#####`noscripting`
|
||||
Set noscripting = true to disable the scripting engine. Default: false
|
||||
|
||||
#####`notablescan`
|
||||
Set notablescan = true to forbid operations that require a table scan. Default: false
|
||||
|
||||
#####`noprealloc`
|
||||
Set noprealloc = true to disable the preallocation of data files. This will shorten
|
||||
the start up time in some cases, but can cause significant performance penalties
|
||||
during normal operations. Default: false
|
||||
|
||||
#####`nssize`
|
||||
Use this setting to control the default size for all newly created namespace
|
||||
files (i.e .ns). Default: 16
|
||||
|
||||
#####`mms_token`
|
||||
MMS token for mms monitoring. Default: None
|
||||
|
||||
#####`mms_name`
|
||||
MMS identifier for mms monitoring. Default: None
|
||||
|
||||
#####`mms_interval`
|
||||
MMS interval for mms monitoring. Default: None
|
||||
|
||||
#####`replset`
|
||||
Use this setting to configure replication with replica sets. Specify a replica
|
||||
set name as an argument to this set. All hosts must have the same set name.
|
||||
|
||||
#####`rest`
|
||||
Set to true to enable a simple REST interface. Default: false
|
||||
|
||||
#####`slowms`
|
||||
Sets the threshold for mongod to consider a query “slow” for the database profiler.
|
||||
Default: 100 ms
|
||||
|
||||
#####`keyfile`
|
||||
Specify the path to a key file to store authentication information. This option
|
||||
is only useful for the connection between replica set members. Default: None
|
||||
|
||||
#####`master`
|
||||
Set to true to configure the current instance to act as master instance in a
|
||||
replication configuration. Default: False *Note*: deprecated – use replica sets
|
||||
|
||||
#####`set_parameter`
|
||||
Specify extra configuration file parameters (i.e.
|
||||
textSearchEnabled=true). Default: None
|
||||
|
||||
#####`slave`
|
||||
Set to true to configure the current instance to act as slave instance in a
|
||||
replication configuration. Default: false
|
||||
*Note*: deprecated – use replica sets
|
||||
|
||||
#####`only`
|
||||
Used with the slave option, only specifies only a single database to
|
||||
replicate. Default: <>
|
||||
*Note*: deprecated – use replica sets
|
||||
|
||||
#####`source`
|
||||
Used with the slave setting to specify the master instance from which
|
||||
this slave instance will replicate. Default: <>
|
||||
*Note*: deprecated – use replica sets
|
||||
|
||||
### Definitions
|
||||
|
||||
#### Definition: mongodb:db
|
||||
|
||||
Creates database with user. Resource title used as database name.
|
||||
|
||||
#####`user`
|
||||
Name of the user for database
|
||||
|
||||
#####`password_hash`
|
||||
Hex encoded md5 hash of "$username:mongo:$password".
|
||||
For more information please refer to [MongoDB Authentication Process](http://docs.mongodb.org/meta-driver/latest/legacy/implement-authentication-in-driver/#authentication-process).
|
||||
|
||||
#####`password`
|
||||
Plain-text user password (will be hashed)
|
||||
|
||||
#####`roles`
|
||||
Array with user roles. Default: ['dbAdmin']
|
||||
|
||||
### Providers
|
||||
|
||||
#### Provider: mongodb_database
|
||||
'mongodb_database' can be used to create and manage databases within MongoDB.
|
||||
|
||||
```puppet
|
||||
mongodb_database { testdb:
|
||||
ensure => present,
|
||||
tries => 10,
|
||||
require => Class['mongodb::server'],
|
||||
}
|
||||
```
|
||||
#####`tries`
|
||||
The maximum amount of two second tries to wait MongoDB startup. Default: 10
|
||||
|
||||
|
||||
#### Provider: mongodb_user
|
||||
'mongodb_user' can be used to create and manage users within MongoDB database.
|
||||
|
||||
```puppet
|
||||
mongodb_user { testuser:
|
||||
ensure => present,
|
||||
password_hash => mongodb_password('testuser', 'p@ssw0rd'),
|
||||
database => testdb,
|
||||
roles => ['readWrite', 'dbAdmin'],
|
||||
tries => 10,
|
||||
require => Class['mongodb::server'],
|
||||
}
|
||||
```
|
||||
#####`password_hash`
|
||||
Hex encoded md5 hash of "$username:mongo:$password".
|
||||
|
||||
#####`database`
|
||||
Name of database. It will be created, if not exists.
|
||||
|
||||
#####`roles`
|
||||
Array with user roles. Default: ['dbAdmin']
|
||||
|
||||
#####`tries`
|
||||
The maximum amount of two second tries to wait MongoDB startup. Default: 10
|
||||
|
||||
#### Provider: mongodb_replset
|
||||
'mongodb_replset' can be used to create and manage MongoDB replicasets.
|
||||
|
||||
```puppet
|
||||
mongodb_replicaset { rsmain:
|
||||
ensure => present,
|
||||
members => ['host1:27017', 'host2:27017', 'host3:27017']
|
||||
}
|
||||
```
|
||||
|
||||
Ideally the ```mongodb_replicaset``` resource will be declared on the initial
|
||||
desired primary node (arbitrarily the first of the list) and this node will be
|
||||
processed once the secondary nodes are up. This will ensure all the nodes are
|
||||
in the first configuration of the replicaset, else it will require running
|
||||
puppet again to add them.
|
||||
|
||||
#####`members`
|
||||
Array of 'host:port' of the replicaset members.
|
||||
|
||||
It currently only adds members without options.
|
||||
|
||||
## Limitation
|
||||
|
||||
This module has been tested on:
|
||||
|
||||
* Debian 7.* (Wheezy)
|
||||
* Debian 6.* (squeeze)
|
||||
* Ubuntu 12.04.2 (precise)
|
||||
* Ubuntu 10.04.4 LTS (lucid)
|
||||
* RHEL 5/6
|
||||
* CentOS 5/6
|
||||
|
||||
For a full list of tested operating systems please have a look at the [.nodeset.xml](https://github.com/puppetlabs/puppetlabs-mongodb/blob/master/.nodeset.yml) definition.
|
||||
|
||||
## Development
|
||||
|
||||
Puppet Labs modules on the Puppet Forge are open projects, and community
|
||||
contributions are essential for keeping them great. We can’t access the
|
||||
huge number of platforms and myriad of hardware, software, and deployment
|
||||
configurations that Puppet is intended to serve.
|
||||
|
||||
We want to keep it as easy as possible to contribute changes so that our
|
||||
modules work in your environment. There are a few guidelines that we need
|
||||
contributors to follow so that we can have a chance of keeping on top of things.
|
||||
|
||||
You can read the complete module contribution guide [on the Puppet Labs wiki.](http://projects.puppetlabs.com/projects/module-site/wiki/Module_contributing)
|
||||
|
||||
### Testing
|
||||
|
||||
There are two types of tests distributed with this module. Unit tests with
|
||||
rspec-puppet and system tests using rspec-system.
|
||||
|
||||
|
||||
unit tests should be run under Bundler with the gem versions as specified
|
||||
in the Gemfile. To install the necessary gems:
|
||||
|
||||
bundle install --path=vendor
|
||||
|
||||
Test setup and teardown is handled with rake tasks, so the
|
||||
supported way of running tests is with
|
||||
|
||||
bundle exec rake spec
|
||||
|
||||
|
||||
For system test you will also need to install vagrant > 1.3.x and virtualbox > 4.2.10.
|
||||
To run the system tests
|
||||
|
||||
bundle exec rake spec:system
|
||||
|
||||
To run the tests on different operating systems, see the sets available in [.nodeset.xml](https://github.com/puppetlabs/puppetlabs-mongodb/blob/master/.nodeset.yml)
|
||||
and run the specific set with the following syntax:
|
||||
|
||||
RSPEC_SET=ubuntu-server-12042-x64 bundle exec rake spec:system
|
||||
|
||||
### Authors
|
||||
|
||||
We would like to thank everyone who has contributed issues and pull requests to this module.
|
||||
A complete list of contributors can be found on the
|
||||
[GitHub Contributor Graph](https://github.com/puppetlabs/puppetlabs-mongodb/graphs/contributors)
|
||||
for the [puppetlabs-mongodb module](https://github.com/puppetlabs/puppetlabs-mongodb).
|
2
deployment/puppet/mongodb/Rakefile
Normal file
2
deployment/puppet/mongodb/Rakefile
Normal file
@ -0,0 +1,2 @@
|
||||
require 'puppetlabs_spec_helper/rake_tasks'
|
||||
require 'rspec-system/rake_task'
|
@ -0,0 +1,14 @@
|
||||
require 'digest/md5'
|
||||
|
||||
module Puppet::Parser::Functions
|
||||
newfunction(:mongodb_password, :type => :rvalue, :doc => <<-EOS
|
||||
Returns the mongodb password hash from the clear text password.
|
||||
EOS
|
||||
) do |args|
|
||||
|
||||
raise(Puppet::ParseError, 'mongodb_password(): Wrong number of arguments ' +
|
||||
"given (#{args.size} for 2)") if args.size != 2
|
||||
|
||||
Digest::MD5.hexdigest("#{args[0]}:mongo:#{args[1]}")
|
||||
end
|
||||
end
|
@ -0,0 +1,32 @@
|
||||
Puppet::Type.type(:mongodb_database).provide(:mongodb) do
|
||||
|
||||
desc "Manages MongoDB database."
|
||||
|
||||
defaultfor :kernel => 'Linux'
|
||||
|
||||
commands :mongo => 'mongo'
|
||||
|
||||
def block_until_mongodb(tries = 10)
|
||||
begin
|
||||
mongo('--quiet', '--eval', 'db.getMongo()')
|
||||
rescue
|
||||
debug('MongoDB server not ready, retrying')
|
||||
sleep 2
|
||||
retry unless (tries -= 1) <= 0
|
||||
end
|
||||
end
|
||||
|
||||
def create
|
||||
mongo(@resource[:name], '--quiet', '--eval', "db.dummyData.insert({\"created_by_puppet\": 1})")
|
||||
end
|
||||
|
||||
def destroy
|
||||
mongo(@resource[:name], '--quiet', '--eval', 'db.dropDatabase()')
|
||||
end
|
||||
|
||||
def exists?
|
||||
block_until_mongodb(@resource[:tries])
|
||||
mongo("--quiet", "--eval", 'db.getMongo().getDBNames()').split(",").include?(@resource[:name])
|
||||
end
|
||||
|
||||
end
|
@ -0,0 +1,138 @@
|
||||
#
|
||||
# Author: François Charlier <francois.charlier@enovance.com>
|
||||
#
|
||||
|
||||
require 'json'
|
||||
|
||||
Puppet::Type.type(:mongodb_replset).provide(:mongo) do
|
||||
|
||||
desc "Manage hosts members for a replicaset."
|
||||
|
||||
commands :mongo => 'mongo'
|
||||
|
||||
def create
|
||||
alive_members = members_present
|
||||
hostsconf = alive_members.collect.each_with_index do |host, id|
|
||||
"{ _id: #{id}, host: \"#{host}\" }"
|
||||
end.join(',')
|
||||
conf = "{ _id: \"#{@resource[:name]}\", members: [ #{hostsconf} ] }"
|
||||
output = self.rs_initiate(conf, alive_members[0])
|
||||
if output['ok'] == 0
|
||||
raise Puppet::Error, "rs.initiate() failed for replicaset #{@resource[:name]}: #{output['errmsg']}"
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
end
|
||||
|
||||
def exists?
|
||||
failcount = 0
|
||||
is_configured = false
|
||||
@resource[:members].each do |host|
|
||||
begin
|
||||
debug "Checking replicaset member #{host} ..."
|
||||
status = self.rs_status(host)
|
||||
if status.has_key?('errmsg') and status['errmsg'] == 'not running with --replSet'
|
||||
raise Puppet::Error, "Can't configure replicaset #{@resource[:name]}, host #{host} is not supposed to be part of a replicaset."
|
||||
end
|
||||
if status.has_key?('set')
|
||||
if status['set'] != @resource[:name]
|
||||
raise Puppet::Error, "Can't configure replicaset #{@resource[:name]}, host #{host} is already part of another replicaset."
|
||||
end
|
||||
is_configured = true
|
||||
end
|
||||
rescue Puppet::ExecutionFailure
|
||||
debug "Can't connect to replicaset member #{host}."
|
||||
failcount += 1
|
||||
end
|
||||
end
|
||||
|
||||
if failcount == @resource[:members].length
|
||||
raise Puppet::Error, "Can't connect to any member of replicaset #{@resource[:name]}."
|
||||
end
|
||||
return is_configured
|
||||
end
|
||||
|
||||
def members
|
||||
if master = self.master_host()
|
||||
self.db_ismaster(master)['hosts']
|
||||
else
|
||||
raise Puppet::Error, "Can't find master host for replicaset #{@resource[:name]}."
|
||||
end
|
||||
end
|
||||
|
||||
def members=(hosts)
|
||||
if master = master_host()
|
||||
current = self.db_ismaster(master)['hosts']
|
||||
newhosts = hosts - current
|
||||
newhosts.each do |host|
|
||||
#TODO: check output (['ok'] == 0 should be sufficient)
|
||||
self.rs_add(host, master)
|
||||
end
|
||||
else
|
||||
raise Puppet::Error, "Can't find master host for replicaset #{@resource[:name]}."
|
||||
end
|
||||
end
|
||||
|
||||
def members_present
|
||||
@resource[:members].select do |host|
|
||||
begin
|
||||
self.mongo('--host', host, '--quiet', '--eval', 'db.version()')
|
||||
true
|
||||
rescue Puppet::ExecutionFailure
|
||||
false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def mongo_command(command, host, retries=4)
|
||||
# Allow waiting for mongod to become ready
|
||||
# Wait for 2 seconds initially and double the delay at each retry
|
||||
wait = 2
|
||||
begin
|
||||
output = self.mongo('--quiet', '--host', host, '--eval', "printjson(#{command})")
|
||||
rescue Puppet::ExecutionFailure => e
|
||||
if e =~ /Error: couldn't connect to server/ and wait <= 2**max_wait
|
||||
info("Waiting #{wait} seconds for mongod to become available")
|
||||
sleep wait
|
||||
wait *= 2
|
||||
retry
|
||||
else
|
||||
raise
|
||||
end
|
||||
end
|
||||
|
||||
# Dirty hack to remove JavaScript objects
|
||||
output.gsub!(/ISODate\((.+?)\)/, '\1 ')
|
||||
output.gsub!(/Timestamp\((.+?)\)/, '[\1]')
|
||||
JSON.parse(output)
|
||||
end
|
||||
|
||||
def master_host
|
||||
@resource[:members].each do |host|
|
||||
status = self.db_ismaster(host)
|
||||
if status.has_key?('primary')
|
||||
return status['primary']
|
||||
end
|
||||
end
|
||||
false
|
||||
end
|
||||
|
||||
def db_ismaster(host)
|
||||
self.mongo_command("db.isMaster()", host)
|
||||
end
|
||||
|
||||
def rs_initiate(conf, host)
|
||||
return self.mongo_command("rs.initiate(#{conf})", @resource[:members][0])
|
||||
|
||||
end
|
||||
|
||||
def rs_status(host)
|
||||
self.mongo_command("rs.status()", host)
|
||||
end
|
||||
|
||||
def rs_add(host, master)
|
||||
self.mongo_command("rs.add(\"#{host}\")", master)
|
||||
end
|
||||
|
||||
end
|
@ -0,0 +1,48 @@
|
||||
Puppet::Type.type(:mongodb_user).provide(:mongodb) do
|
||||
|
||||
desc "Manage users for a MongoDB database."
|
||||
|
||||
defaultfor :kernel => 'Linux'
|
||||
|
||||
commands :mongo => 'mongo'
|
||||
|
||||
def block_until_mongodb(tries = 10)
|
||||
begin
|
||||
mongo('--quiet', '--eval', 'db.getMongo()')
|
||||
rescue
|
||||
debug('MongoDB server not ready, retrying')
|
||||
sleep 2
|
||||
retry unless (tries -= 1) <= 0
|
||||
end
|
||||
end
|
||||
|
||||
def create
|
||||
mongo(@resource[:database], '--eval', "db.system.users.insert({user:\"#{@resource[:name]}\", pwd:\"#{@resource[:password_hash]}\", roles: #{@resource[:roles].inspect}})")
|
||||
end
|
||||
|
||||
def destroy
|
||||
mongo(@resource[:database], '--quiet', '--eval', "db.removeUser(\"#{@resource[:name]}\")")
|
||||
end
|
||||
|
||||
def exists?
|
||||
block_until_mongodb(@resource[:tries])
|
||||
mongo(@resource[:database], '--quiet', '--eval', "db.system.users.find({user:\"#{@resource[:name]}\"}).count()").strip.eql?('1')
|
||||
end
|
||||
|
||||
def password_hash
|
||||
mongo(@resource[:database], '--quiet', '--eval', "db.system.users.findOne({user:\"#{@resource[:name]}\"})[\"pwd\"]").strip
|
||||
end
|
||||
|
||||
def password_hash=(value)
|
||||
mongo(@resource[:database], '--quiet', '--eval', "db.system.users.update({user:\"#{@resource[:name]}\"}, { $set: {pwd:\"#{value}\"}})")
|
||||
end
|
||||
|
||||
def roles
|
||||
mongo(@resource[:database], '--quiet', '--eval', "db.system.users.findOne({user:\"#{@resource[:name]}\"})[\"roles\"]").strip.split(",").sort
|
||||
end
|
||||
|
||||
def roles=(value)
|
||||
mongo(@resource[:database], '--quiet', '--eval', "db.system.users.update({user:\"#{@resource[:name]}\"}, { $set: {roles: #{@resource[:roles].inspect}}})")
|
||||
end
|
||||
|
||||
end
|
@ -0,0 +1,20 @@
|
||||
Puppet::Type.newtype(:mongodb_database) do
|
||||
@doc = "Manage MongoDB databases."
|
||||
|
||||
ensurable
|
||||
|
||||
newparam(:name, :namevar=>true) do
|
||||
desc "The name of the database."
|
||||
newvalues(/^\w+$/)
|
||||
end
|
||||
|
||||
newparam(:tries) do
|
||||
desc "The maximum amount of two second tries to wait MongoDB startup."
|
||||
defaultto 10
|
||||
newvalues(/^\d+$/)
|
||||
munge do |value|
|
||||
Integer(value)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
35
deployment/puppet/mongodb/lib/puppet/type/mongodb_replset.rb
Normal file
35
deployment/puppet/mongodb/lib/puppet/type/mongodb_replset.rb
Normal file
@ -0,0 +1,35 @@
|
||||
#
|
||||
# Author: François Charlier <francois.charlier@enovance.com>
|
||||
#
|
||||
|
||||
Puppet::Type.newtype(:mongodb_replset) do
|
||||
@doc = "Manage a MongoDB replicaSet"
|
||||
|
||||
ensurable do
|
||||
defaultto :present
|
||||
|
||||
newvalue(:present) do
|
||||
provider.create
|
||||
end
|
||||
end
|
||||
|
||||
newparam(:name) do
|
||||
desc "The name of the replicaSet"
|
||||
end
|
||||
|
||||
newproperty(:members, :array_matching => :all) do
|
||||
desc "The replicaSet members"
|
||||
|
||||
def insync?(is)
|
||||
is.sort == should.sort
|
||||
end
|
||||
end
|
||||
|
||||
autorequire(:package) do
|
||||
'mongodb'
|
||||
end
|
||||
|
||||
autorequire(:service) do
|
||||
'mongodb'
|
||||
end
|
||||
end
|
56
deployment/puppet/mongodb/lib/puppet/type/mongodb_user.rb
Normal file
56
deployment/puppet/mongodb/lib/puppet/type/mongodb_user.rb
Normal file
@ -0,0 +1,56 @@
|
||||
Puppet::Type.newtype(:mongodb_user) do
|
||||
@doc = 'Manage a MongoDB user. This includes management of users password as well as privileges.'
|
||||
|
||||
ensurable
|
||||
|
||||
def initialize(*args)
|
||||
super
|
||||
# Sort roles array before comparison.
|
||||
self[:roles] = Array(self[:roles]).sort!
|
||||
end
|
||||
|
||||
newparam(:name, :namevar=>true) do
|
||||
desc "The name of the user."
|
||||
end
|
||||
|
||||
newparam(:database) do
|
||||
desc "The user's target database."
|
||||
defaultto do
|
||||
fail("Parameter 'database' must be set")
|
||||
end
|
||||
newvalues(/^\w+$/)
|
||||
end
|
||||
|
||||
newparam(:tries) do
|
||||
desc "The maximum amount of two second tries to wait MongoDB startup."
|
||||
defaultto 10
|
||||
newvalues(/^\d+$/)
|
||||
munge do |value|
|
||||
Integer(value)
|
||||
end
|
||||
end
|
||||
|
||||
newproperty(:roles, :array_matching => :all) do
|
||||
desc "The user's roles."
|
||||
defaultto ['dbAdmin']
|
||||
newvalue(/^\w+$/)
|
||||
|
||||
# Pretty output for arrays.
|
||||
def should_to_s(value)
|
||||
value.inspect
|
||||
end
|
||||
|
||||
def is_to_s(value)
|
||||
value.inspect
|
||||
end
|
||||
end
|
||||
|
||||
newproperty(:password_hash) do
|
||||
desc "The password hash of the user. Use mongodb_password() for creating hash."
|
||||
defaultto do
|
||||
fail("Property 'password_hash' must be set. Use mongodb_password() for creating hash.")
|
||||
end
|
||||
newvalue(/^\w+$/)
|
||||
end
|
||||
|
||||
end
|
26
deployment/puppet/mongodb/manifests/client.pp
Normal file
26
deployment/puppet/mongodb/manifests/client.pp
Normal file
@ -0,0 +1,26 @@
|
||||
# Class for installing a MongoDB client shell (CLI).
|
||||
#
|
||||
# == Parameters
|
||||
#
|
||||
# [ensure] Desired ensure state of the package. Optional.
|
||||
# Defaults to 'true'
|
||||
#
|
||||
# [package_name] Name of the package to install the client from. Default
|
||||
# is repository dependent.
|
||||
#
|
||||
class mongodb::client (
|
||||
$ensure = $mongodb::params::ensure_client,
|
||||
$package_name = $mongodb::params::client_package_name,
|
||||
) inherits mongodb::params {
|
||||
case $::osfamily {
|
||||
'RedHat', 'Linux': {
|
||||
class { 'mongodb::client::install': }
|
||||
}
|
||||
'Debian': {
|
||||
warning ('Debian client is included by default with server. Please use ::mongodb::server to install the mongo client for Debian family systems.')
|
||||
}
|
||||
default: {
|
||||
# no action taken, failure happens in params.pp
|
||||
}
|
||||
}
|
||||
}
|
26
deployment/puppet/mongodb/manifests/client/install.pp
Normal file
26
deployment/puppet/mongodb/manifests/client/install.pp
Normal file
@ -0,0 +1,26 @@
|
||||
# PRIVATE CLASS: do not call directly
|
||||
class mongodb::client::install {
|
||||
$package_ensure = $mongodb::client::ensure
|
||||
$package_name = $mongodb::client::package_name
|
||||
|
||||
case $package_ensure {
|
||||
true: {
|
||||
$my_package_ensure = 'present'
|
||||
}
|
||||
false: {
|
||||
$my_package_ensure = 'purged'
|
||||
}
|
||||
'absent': {
|
||||
$my_package_ensure = 'purged'
|
||||
}
|
||||
default: {
|
||||
$my_package_ensure = $package_ensure
|
||||
}
|
||||
}
|
||||
|
||||
package { 'mongodb_client':
|
||||
ensure => $my_package_ensure,
|
||||
name => $package_name,
|
||||
tag => 'mongodb',
|
||||
}
|
||||
}
|
43
deployment/puppet/mongodb/manifests/db.pp
Normal file
43
deployment/puppet/mongodb/manifests/db.pp
Normal file
@ -0,0 +1,43 @@
|
||||
# == Class: mongodb::db
|
||||
#
|
||||
# Class for creating mongodb databases and users.
|
||||
#
|
||||
# == Parameters
|
||||
#
|
||||
# user - Database username.
|
||||
# password_hash - Hashed password. Hex encoded md5 hash of "$username:mongo:$password".
|
||||
# password - Plain text user password. This is UNSAFE, use 'password_hash' unstead.
|
||||
# roles (default: ['dbAdmin']) - array with user roles.
|
||||
# tries (default: 10) - The maximum amount of two second tries to wait MongoDB startup.
|
||||
#
|
||||
define mongodb::db (
|
||||
$user,
|
||||
$password_hash = false,
|
||||
$password = false,
|
||||
$roles = ['dbAdmin'],
|
||||
$tries = 10,
|
||||
) {
|
||||
|
||||
mongodb_database { $name:
|
||||
ensure => present,
|
||||
tries => $tries,
|
||||
require => Class['mongodb::server'],
|
||||
}
|
||||
|
||||
if $password_hash {
|
||||
$hash = $password_hash
|
||||
} elsif $password {
|
||||
$hash = mongodb_password($user, $password)
|
||||
} else {
|
||||
fail("Parameter 'password_hash' or 'password' should be provided to mongodb::db.")
|
||||
}
|
||||
|
||||
mongodb_user { $user:
|
||||
ensure => present,
|
||||
password_hash => $hash,
|
||||
database => $name,
|
||||
roles => $roles,
|
||||
require => Mongodb_database[$name],
|
||||
}
|
||||
|
||||
}
|
27
deployment/puppet/mongodb/manifests/globals.pp
Normal file
27
deployment/puppet/mongodb/manifests/globals.pp
Normal file
@ -0,0 +1,27 @@
|
||||
# Class for setting cross-class global overrides. See README.md for more
|
||||
# details.
|
||||
|
||||
class mongodb::globals (
|
||||
$server_package_name = undef,
|
||||
$client_package_name = undef,
|
||||
|
||||
$service_name = undef,
|
||||
$service_provider = undef,
|
||||
$service_status = undef,
|
||||
|
||||
$user = undef,
|
||||
$group = undef,
|
||||
$bind_ip = undef,
|
||||
|
||||
$version = undef,
|
||||
|
||||
$manage_package_repo = undef,
|
||||
) {
|
||||
|
||||
# Setup of the repo only makes sense globally, so we are doing it here.
|
||||
if($manage_package_repo) {
|
||||
class { '::mongodb::repo':
|
||||
ensure => present,
|
||||
}
|
||||
}
|
||||
}
|
136
deployment/puppet/mongodb/manifests/init.pp
Normal file
136
deployment/puppet/mongodb/manifests/init.pp
Normal file
@ -0,0 +1,136 @@
|
||||
# == Class: mongodb
|
||||
#
|
||||
# Direct use of this class is deprecated. Please use mongodb::server
|
||||
#
|
||||
# Manage mongodb installations on RHEL, CentOS, Debian and Ubuntu - either
|
||||
# installing from the 10Gen repo or from EPEL in the case of EL systems.
|
||||
#
|
||||
# === Parameters
|
||||
#
|
||||
# enable_10gen (default: false) - Whether or not to set up 10gen software repositories
|
||||
# init (auto discovered) - override init (sysv or upstart) for Debian derivatives
|
||||
# location - override apt location configuration for Debian derivatives
|
||||
# packagename (auto discovered) - override the package name
|
||||
# servicename (auto discovered) - override the service name
|
||||
# service-enable (default: true) - Enable the service and ensure it is running
|
||||
#
|
||||
# === Examples
|
||||
#
|
||||
# To install with defaults from the distribution packages on any system:
|
||||
# include mongodb
|
||||
#
|
||||
# To install from 10gen on a EL server
|
||||
# class { 'mongodb':
|
||||
# enable_10gen => true,
|
||||
# }
|
||||
#
|
||||
# === Authors
|
||||
#
|
||||
# Craig Dunn <craig@craigdunn.org>
|
||||
#
|
||||
# === Copyright
|
||||
#
|
||||
# Copyright 2013 PuppetLabs
|
||||
#
|
||||
|
||||
class mongodb (
|
||||
# Deprecated parameters
|
||||
$enable_10gen = undef,
|
||||
|
||||
$init = $mongodb::params::service_provider,
|
||||
$location = '',
|
||||
$packagename = undef,
|
||||
$version = undef,
|
||||
$servicename = $mongodb::params::service_name,
|
||||
$service_enable = true, #deprecated
|
||||
$logpath = $mongodb::params::logpath,
|
||||
$logappend = true,
|
||||
$fork = $mongodb::params::fork,
|
||||
$port = 27017,
|
||||
$dbpath = $mongodb::params::dbpath,
|
||||
$journal = undef,
|
||||
$nojournal = undef,
|
||||
$smallfiles = undef,
|
||||
$cpu = undef,
|
||||
$noauth = undef,
|
||||
$auth = undef,
|
||||
$verbose = undef,
|
||||
$objcheck = undef,
|
||||
$quota = undef,
|
||||
$oplog = undef, #deprecated it's on if replica set
|
||||
$oplog_size = undef,
|
||||
$nohints = undef,
|
||||
$nohttpinterface = undef,
|
||||
$noscripting = undef,
|
||||
$notablescan = undef,
|
||||
$noprealloc = undef,
|
||||
$nssize = undef,
|
||||
$mms_token = undef,
|
||||
$mms_name = undef,
|
||||
$mms_interval = undef,
|
||||
$slave = undef,
|
||||
$only = undef,
|
||||
$master = undef,
|
||||
$source = undef,
|
||||
$replset = undef,
|
||||
$rest = undef,
|
||||
$slowms = undef,
|
||||
$keyfile = undef,
|
||||
$bind_ip = undef,
|
||||
$pidfilepath = undef
|
||||
) inherits mongodb::params {
|
||||
|
||||
if $enable_10gen {
|
||||
fail("Parameter enable_10gen is no longer supported. Please use class { 'mongodb::globals': manage_package_repo => true }")
|
||||
}
|
||||
|
||||
if $version {
|
||||
fail("Parameter version is no longer supported. Please use class { 'mongodb::globals': version => VERSION }")
|
||||
}
|
||||
|
||||
if $oplog {
|
||||
fail('Parameter is no longer supported. On replica set Oplog is enabled by default.')
|
||||
}
|
||||
|
||||
notify { 'An attempt has been made below to automatically apply your custom
|
||||
settings to mongodb::server. Please verify this works in a safe test
|
||||
environment.': }
|
||||
|
||||
class { 'mongodb::server':
|
||||
package_name => $packagename,
|
||||
logpath => $logpath,
|
||||
logappend => $logappend,
|
||||
fork => $fork,
|
||||
port => $port,
|
||||
dbpath => $dbpath,
|
||||
journal => $journal,
|
||||
nojournal => $nojournal,
|
||||
smallfiles => $smallfiles,
|
||||
cpu => $cpu,
|
||||
noauth => $noauth,
|
||||
verbose => $verbose,
|
||||
objcheck => $objcheck,
|
||||
quota => $quota,
|
||||
oplog_size => $oplog_size,
|
||||
nohints => $nohints,
|
||||
nohttpinterface => $nohttpinterface,
|
||||
noscripting => $noscripting,
|
||||
notablescan => $notablescan,
|
||||
noprealloc => $noprealloc,
|
||||
nssize => $nssize,
|
||||
mms_token => $mms_token,
|
||||
mms_name => $mms_name,
|
||||
mms_interval => $mms_interval,
|
||||
slave => $slave,
|
||||
only => $only,
|
||||
master => $master,
|
||||
source => $source,
|
||||
replset => $replset,
|
||||
rest => $rest,
|
||||
slowms => $slowms,
|
||||
keyfile => $keyfile,
|
||||
bind_ip => $bind_ip,
|
||||
pidfilepath => $pidfilepath,
|
||||
}
|
||||
|
||||
}
|
93
deployment/puppet/mongodb/manifests/params.pp
Normal file
93
deployment/puppet/mongodb/manifests/params.pp
Normal file
@ -0,0 +1,93 @@
|
||||
# PRIVATE CLASS: do not use directly
|
||||
class mongodb::params inherits mongodb::globals {
|
||||
$ensure = true
|
||||
$service_status = $service_status
|
||||
$ensure_client = true
|
||||
|
||||
# Amazon Linux's OS Family is 'Linux', operating system 'Amazon'.
|
||||
case $::osfamily {
|
||||
'RedHat', 'Linux': {
|
||||
|
||||
if $mongodb::globals::manage_package_repo {
|
||||
$user = pick($user, 'mongod')
|
||||
$group = pick($group, 'mongod')
|
||||
if $::mongodb::globals::version {
|
||||
$server_package_name = "mongo-10gen-server-${::mongodb::globals::version}"
|
||||
$client_package_name = "mongo-10gen-${::mongodb::globals::version}"
|
||||
} else {
|
||||
$server_package_name = 'mongo-10gen-server'
|
||||
$client_package_name = 'mongo-10gen'
|
||||
}
|
||||
$service_name = pick($service_name, 'mongod')
|
||||
$config = '/etc/mongod.conf'
|
||||
$dbpath = '/var/lib/mongo'
|
||||
$logpath = '/var/log/mongo/mongod.log'
|
||||
$pidfilepath = '/var/run/mongodb/mongod.pid'
|
||||
$bind_ip = pick($bind_ip, ['127.0.0.1'])
|
||||
$fork = true
|
||||
} else {
|
||||
# RedHat/CentOS doesn't come with a prepacked mongodb
|
||||
# so we assume that you are using EPEL repository.
|
||||
$user = pick($user, 'mongodb')
|
||||
$group = pick($group, 'mongodb')
|
||||
$server_package_name = pick($server_package_name, 'mongodb-server')
|
||||
$client_package_name = pick($client_package_name, 'mongodb')
|
||||
|
||||
$service_name = pick($service_name, 'mongod')
|
||||
$config = '/etc/mongodb.conf'
|
||||
$dbpath = '/var/lib/mongodb'
|
||||
$logpath = '/var/log/mongodb/mongodb.log'
|
||||
$bind_ip = pick($bind_ip, ['127.0.0.1'])
|
||||
$pidfilepath = '/var/run/mongodb/mongodb.pid'
|
||||
$fork = true
|
||||
$journal = true
|
||||
}
|
||||
}
|
||||
'Debian': {
|
||||
if $mongodb::globals::manage_package_repo {
|
||||
$user = pick($user, 'mongodb')
|
||||
$group = pick($group, 'mongodb')
|
||||
if $::mongodb::globals::version {
|
||||
$server_package_name = "mongodb-10gen-${::mongodb::globals::version}"
|
||||
} else {
|
||||
$server_package_name = 'mongodb-10gen'
|
||||
}
|
||||
$service_name = 'mongodb'
|
||||
$config = '/etc/mongodb.conf'
|
||||
$dbpath = '/var/lib/mongodb'
|
||||
$logpath = '/var/log/mongodb/mongodb.log'
|
||||
$bind_ip = ['127.0.0.1']
|
||||
} else {
|
||||
# although we are living in a free world,
|
||||
# I would not recommend to use the prepacked
|
||||
# mongodb server on Ubuntu 12.04 or Debian 6/7,
|
||||
# because its really outdated
|
||||
$user = pick($user, 'mongodb')
|
||||
$group = pick($group, 'mongodb')
|
||||
$server_package_name = pick($server_package_name, 'mongodb-server')
|
||||
$client_package_name = pick($client_package_name, 'mongodb')
|
||||
$service_name = pick($service_name, 'mongodb')
|
||||
$config = '/etc/mongodb.conf'
|
||||
$dbpath = '/var/lib/mongodb'
|
||||
$logpath = '/var/log/mongodb/mongodb.log'
|
||||
$bind_ip = pick($bind_ip, ['127.0.0.1'])
|
||||
$pidfilepath = undef
|
||||
}
|
||||
# avoid using fork because of the init scripts design
|
||||
$fork = undef
|
||||
}
|
||||
default: {
|
||||
fail("Osfamily ${::osfamily} and ${::operatingsystem} is not supported")
|
||||
}
|
||||
}
|
||||
|
||||
case $::operatingsystem {
|
||||
'Ubuntu': {
|
||||
$service_provider = pick($service_provider, 'upstart')
|
||||
}
|
||||
default: {
|
||||
$service_provider = undef
|
||||
}
|
||||
}
|
||||
|
||||
}
|
31
deployment/puppet/mongodb/manifests/repo.pp
Normal file
31
deployment/puppet/mongodb/manifests/repo.pp
Normal file
@ -0,0 +1,31 @@
|
||||
# PRIVATE CLASS: do not use directly
|
||||
class mongodb::repo (
|
||||
$ensure = $mongodb::params::ensure,
|
||||
) inherits mongodb::params {
|
||||
case $::osfamily {
|
||||
'RedHat', 'Linux': {
|
||||
$location = $::architecture ? {
|
||||
'x86_64' => 'http://downloads-distro.mongodb.org/repo/redhat/os/x86_64/',
|
||||
'i686' => 'http://downloads-distro.mongodb.org/repo/redhat/os/i686/',
|
||||
'i386' => 'http://downloads-distro.mongodb.org/repo/redhat/os/i686/',
|
||||
default => undef
|
||||
}
|
||||
class { 'mongodb::repo::yum': }
|
||||
}
|
||||
|
||||
'Debian': {
|
||||
$location = $::operatingsystem ? {
|
||||
'Debian' => 'http://downloads-distro.mongodb.org/repo/debian-sysvinit',
|
||||
'Ubuntu' => 'http://downloads-distro.mongodb.org/repo/ubuntu-upstart',
|
||||
default => undef
|
||||
}
|
||||
class { 'mongodb::repo::apt': }
|
||||
}
|
||||
|
||||
default: {
|
||||
if($ensure == 'present' or $ensure == true) {
|
||||
fail("Unsupported managed repository for osfamily: ${::osfamily}, operatingsystem: ${::operatingsystem}, module ${module_name} currently only supports managing repos for osfamily RedHat, Debian and Ubuntu")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
25
deployment/puppet/mongodb/manifests/repo/apt.pp
Normal file
25
deployment/puppet/mongodb/manifests/repo/apt.pp
Normal file
@ -0,0 +1,25 @@
|
||||
# PRIVATE CLASS: do not use directly
|
||||
class mongodb::repo::apt inherits mongodb::repo {
|
||||
# we try to follow/reproduce the instruction
|
||||
# from http://docs.mongodb.org/manual/tutorial/install-mongodb-on-ubuntu/
|
||||
|
||||
include ::apt
|
||||
|
||||
if($::mongodb::repo::ensure == 'present' or $::mongodb::repo::ensure == true) {
|
||||
apt::source { 'downloads-distro.mongodb.org':
|
||||
location => $::mongodb::repo::location,
|
||||
release => 'dist',
|
||||
repos => '10gen',
|
||||
key => '9ECBEC467F0CEB10',
|
||||
key_server => 'keyserver.ubuntu.com',
|
||||
include_src => false,
|
||||
}
|
||||
|
||||
Apt::Source['downloads-distro.mongodb.org']->Package<|tag == 'mongodb'|>
|
||||
}
|
||||
else {
|
||||
apt::source { 'downloads-distro.mongodb.org':
|
||||
ensure => absent,
|
||||
}
|
||||
}
|
||||
}
|
20
deployment/puppet/mongodb/manifests/repo/yum.pp
Normal file
20
deployment/puppet/mongodb/manifests/repo/yum.pp
Normal file
@ -0,0 +1,20 @@
|
||||
# PRIVATE CLASS: do not use directly
|
||||
class mongodb::repo::yum inherits mongodb::repo {
|
||||
# We try to follow/reproduce the instruction
|
||||
# http://docs.mongodb.org/manual/tutorial/install-mongodb-on-red-hat-centos-or-fedora-linux/
|
||||
|
||||
if($::mongodb::repo::ensure == 'present' or $::mongodb::repo::ensure == true) {
|
||||
yumrepo { 'mongodb':
|
||||
descr => 'MongoDB/10gen Repository',
|
||||
baseurl => $::mongodb::repo::location,
|
||||
gpgcheck => '0',
|
||||
enabled => '1',
|
||||
}
|
||||
Yumrepo['mongodb'] -> Package<|tag == 'mongodb'|>
|
||||
}
|
||||
else {
|
||||
yumrepo { 'mongodb':
|
||||
enabled => absent,
|
||||
}
|
||||
}
|
||||
}
|
76
deployment/puppet/mongodb/manifests/server.pp
Normal file
76
deployment/puppet/mongodb/manifests/server.pp
Normal file
@ -0,0 +1,76 @@
|
||||
# This installs a MongoDB server. See README.md for more details.
|
||||
class mongodb::server (
|
||||
$ensure = $mongodb::params::ensure,
|
||||
|
||||
$user = $mongodb::params::user,
|
||||
$group = $mongodb::params::group,
|
||||
|
||||
$config = $mongodb::params::config,
|
||||
$dbpath = $mongodb::params::dbpath,
|
||||
$pidfilepath = $mongodb::params::pidfilepath,
|
||||
|
||||
$service_provider = $mongodb::params::service_provider,
|
||||
$service_name = $mongodb::params::service_name,
|
||||
$service_status = $mongodb::params::service_status,
|
||||
|
||||
$package_ensure = $ensure,
|
||||
$package_name = $mongodb::params::server_package_name,
|
||||
|
||||
$logpath = $mongodb::params::logpath,
|
||||
$bind_ip = $mongodb::params::bind_ip,
|
||||
$logappend = true,
|
||||
$fork = $mongodb::params::fork,
|
||||
$port = 27017,
|
||||
$journal = $mongodb::params::journal,
|
||||
$nojournal = undef,
|
||||
$smallfiles = undef,
|
||||
$cpu = undef,
|
||||
$auth = false,
|
||||
$noauth = undef,
|
||||
$verbose = undef,
|
||||
$verbositylevel = undef,
|
||||
$objcheck = undef,
|
||||
$quota = undef,
|
||||
$quotafiles = undef,
|
||||
$diaglog = undef,
|
||||
$directoryperdb = undef,
|
||||
$profile = undef,
|
||||
$maxconns = undef,
|
||||
$oplog_size = undef,
|
||||
$nohints = undef,
|
||||
$nohttpinterface = undef,
|
||||
$noscripting = undef,
|
||||
$notablescan = undef,
|
||||
$noprealloc = undef,
|
||||
$nssize = undef,
|
||||
$mms_token = undef,
|
||||
$mms_name = undef,
|
||||
$mms_interval = undef,
|
||||
$replset = undef,
|
||||
$rest = undef,
|
||||
$slowms = undef,
|
||||
$keyfile = undef,
|
||||
$set_parameter = undef,
|
||||
|
||||
# Deprecated parameters
|
||||
$master = undef,
|
||||
$slave = undef,
|
||||
$only = undef,
|
||||
$source = undef,
|
||||
) inherits mongodb::params {
|
||||
|
||||
|
||||
if ($ensure == 'present' or $ensure == true) {
|
||||
anchor { 'mongodb::server::start': }->
|
||||
class { 'mongodb::server::install': }->
|
||||
class { 'mongodb::server::config': }->
|
||||
class { 'mongodb::server::service': }->
|
||||
anchor { 'mongodb::server::end': }
|
||||
} else {
|
||||
anchor { 'mongodb::server::start': }->
|
||||
class { 'mongodb::server::service': }->
|
||||
class { 'mongodb::server::config': }->
|
||||
class { 'mongodb::server::install': }->
|
||||
anchor { 'mongodb::server::end': }
|
||||
}
|
||||
}
|
89
deployment/puppet/mongodb/manifests/server/config.pp
Normal file
89
deployment/puppet/mongodb/manifests/server/config.pp
Normal file
@ -0,0 +1,89 @@
|
||||
# PRIVATE CLASS: do not call directly
|
||||
class mongodb::server::config {
|
||||
$ensure = $mongodb::server::ensure
|
||||
$user = $mongodb::server::user
|
||||
$group = $mongodb::server::group
|
||||
$config = $mongodb::server::config
|
||||
|
||||
$dbpath = $mongodb::server::dbpath
|
||||
$pidfilepath = $mongodb::server::pidfilepath
|
||||
$logpath = $mongodb::server::logpath
|
||||
$logappend = $mongodb::server::logappend
|
||||
$fork = $mongodb::server::fork
|
||||
$port = $mongodb::server::port
|
||||
$journal = $mongodb::server::journal
|
||||
$nojournal = $mongodb::server::nojournal
|
||||
$smallfiles = $mongodb::server::smallfiles
|
||||
$cpu = $mongodb::server::cpu
|
||||
$auth = $mongodb::server::auth
|
||||
$noath = $mongodb::server::noauth
|
||||
$verbose = $mongodb::server::verbose
|
||||
$verbositylevel = $mongodb::server::verbositylevel
|
||||
$objcheck = $mongodb::server::objcheck
|
||||
$quota = $mongodb::server::quota
|
||||
$quotafiles = $mongodb::server::quotafiles
|
||||
$diaglog = $mongodb::server::diaglog
|
||||
$oplog_size = $mongodb::server::oplog_size
|
||||
$nohints = $mongodb::server::nohints
|
||||
$nohttpinterface = $mongodb::server::nohttpinterface
|
||||
$noscripting = $mongodb::server::noscripting
|
||||
$notablescan = $mongodb::server::notablescan
|
||||
$noprealloc = $mongodb::server::noprealloc
|
||||
$nssize = $mongodb::server::nssize
|
||||
$mms_token = $mongodb::server::mms_token
|
||||
$mms_name = $mongodb::server::mms_name
|
||||
$mms_interval = $mongodb::server::mms_interval
|
||||
$master = $mongodb::server::master
|
||||
$slave = $mongodb::server::slave
|
||||
$only = $mongodb::server::only
|
||||
$source = $mongodb::server::source
|
||||
$replset = $mongodb::server::replset
|
||||
$rest = $mongodb::server::rest
|
||||
$slowms = $mongodb::server::slowms
|
||||
$keyfile = $mongodb::server::keyfile
|
||||
$bind_ip = $mongodb::server::bind_ip
|
||||
$directoryperdb = $mongodb::server::directoryperdb
|
||||
$profile = $mongodb::server::profile
|
||||
$set_parameter = $mongodb::server::set_parameter
|
||||
|
||||
File {
|
||||
owner => $user,
|
||||
group => $group,
|
||||
}
|
||||
|
||||
if ($ensure == 'present' or $ensure == true) {
|
||||
|
||||
# Exists for future compatibility and clarity.
|
||||
if $auth {
|
||||
$noauth = false
|
||||
}
|
||||
else {
|
||||
$noauth = true
|
||||
}
|
||||
|
||||
file { $config:
|
||||
content => template('mongodb/mongodb.conf.erb'),
|
||||
owner => 'root',
|
||||
group => 'root',
|
||||
mode => '0644',
|
||||
notify => Class['mongodb::server::service']
|
||||
}
|
||||
|
||||
file { $dbpath:
|
||||
ensure => directory,
|
||||
mode => '0755',
|
||||
owner => $user,
|
||||
group => $group,
|
||||
require => File[$config]
|
||||
}
|
||||
} else {
|
||||
file { $dbpath:
|
||||
ensure => absent,
|
||||
force => true,
|
||||
backup => false,
|
||||
}
|
||||
file { $config:
|
||||
ensure => absent
|
||||
}
|
||||
}
|
||||
}
|
30
deployment/puppet/mongodb/manifests/server/install.pp
Normal file
30
deployment/puppet/mongodb/manifests/server/install.pp
Normal file
@ -0,0 +1,30 @@
|
||||
# PRIVATE CLASS: do not call directly
|
||||
class mongodb::server::install {
|
||||
$package_ensure = $mongodb::server::package_ensure
|
||||
$package_name = $mongodb::server::package_name
|
||||
|
||||
case $package_ensure {
|
||||
true: {
|
||||
$my_package_ensure = 'present'
|
||||
$file_ensure = 'directory'
|
||||
}
|
||||
false: {
|
||||
$my_package_ensure = 'purged'
|
||||
$file_ensure = 'absent'
|
||||
}
|
||||
'absent': {
|
||||
$my_package_ensure = 'purged'
|
||||
$file_ensure = 'absent'
|
||||
}
|
||||
default: {
|
||||
$my_package_ensure = $package_ensure
|
||||
$file_ensure = 'present'
|
||||
}
|
||||
}
|
||||
|
||||
package { 'mongodb_server':
|
||||
ensure => $my_package_ensure,
|
||||
name => $package_name,
|
||||
tag => 'mongodb',
|
||||
}
|
||||
}
|
22
deployment/puppet/mongodb/manifests/server/service.pp
Normal file
22
deployment/puppet/mongodb/manifests/server/service.pp
Normal file
@ -0,0 +1,22 @@
|
||||
# PRIVATE CLASS: do not call directly
|
||||
class mongodb::server::service {
|
||||
$ensure = $mongodb::server::ensure
|
||||
$service_name = $mongodb::server::service_name
|
||||
$service_provider = $mongodb::server::service_provider
|
||||
$service_status = $mongodb::server::service_status
|
||||
|
||||
$service_ensure = $ensure ? {
|
||||
present => true,
|
||||
absent => false,
|
||||
default => $ensure
|
||||
}
|
||||
|
||||
service { 'mongodb':
|
||||
ensure => $service_ensure,
|
||||
name => $service_name,
|
||||
enable => $service_ensure,
|
||||
provider => $service_provider,
|
||||
hasstatus => true,
|
||||
status => $service_status,
|
||||
}
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe 'mongodb::client::install', :type => :class do
|
||||
describe 'it should create package' do
|
||||
let(:pre_condition) { ["class mongodb::client { $ensure = true $package_name = 'mongodb' }", "include mongodb::client"]}
|
||||
it {
|
||||
should contain_package('mongodb_client').with({
|
||||
:ensure => 'present',
|
||||
:name => 'mongodb',
|
||||
})
|
||||
}
|
||||
end
|
||||
end
|
31
deployment/puppet/mongodb/spec/classes/repo_spec.rb
Normal file
31
deployment/puppet/mongodb/spec/classes/repo_spec.rb
Normal file
@ -0,0 +1,31 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe 'mongodb::repo', :type => :class do
|
||||
|
||||
context 'when deploying on Debian' do
|
||||
let :facts do
|
||||
{
|
||||
:osfamily => 'Debian',
|
||||
:operatingsystem => 'Debian',
|
||||
}
|
||||
end
|
||||
|
||||
it {
|
||||
should contain_class('mongodb::repo::apt')
|
||||
}
|
||||
end
|
||||
|
||||
context 'when deploying on CentOS' do
|
||||
let :facts do
|
||||
{
|
||||
:osfamily => 'RedHat',
|
||||
:operatingsystem => 'CentOS',
|
||||
}
|
||||
end
|
||||
|
||||
it {
|
||||
should contain_class('mongodb::repo::yum')
|
||||
}
|
||||
end
|
||||
|
||||
end
|
97
deployment/puppet/mongodb/spec/classes/server_config_spec.rb
Normal file
97
deployment/puppet/mongodb/spec/classes/server_config_spec.rb
Normal file
@ -0,0 +1,97 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe 'mongodb::server::config', :type => :class do
|
||||
|
||||
describe 'with preseted variables' do
|
||||
let(:pre_condition) { ["class mongodb::server { $config = '/etc/mongod.conf' $dbpath = '/var/lib/mongo' }", "include mongodb::server"]}
|
||||
|
||||
it {
|
||||
should contain_file('/etc/mongod.conf')
|
||||
}
|
||||
|
||||
end
|
||||
|
||||
describe 'with default values' do
|
||||
let(:pre_condition) {[ "class mongodb::server { $config = '/etc/mongod.conf' $dbpath = '/var/lib/mongo' $ensure = present $user = 'mongod' $group = 'mongod' $port = 29017 $bind_ip = ['0.0.0.0'] $fork = true $logpath ='/var/log/mongo/mongod.log' $logappend = true }", "include mongodb::server" ]}
|
||||
|
||||
it {
|
||||
should contain_file('/etc/mongod.conf').with({
|
||||
:mode => '0644',
|
||||
:owner => 'root',
|
||||
:group => 'root'
|
||||
})
|
||||
|
||||
should contain_file('/etc/mongod.conf').with_content(/^dbpath=\/var\/lib\/mongo/)
|
||||
should contain_file('/etc/mongod.conf').with_content(/bind_ip\s=\s0\.0\.0\.0/)
|
||||
should contain_file('/etc/mongod.conf').with_content(/^port = 29017$/)
|
||||
should contain_file('/etc/mongod.conf').with_content(/^logappend=true/)
|
||||
should contain_file('/etc/mongod.conf').with_content(/^logpath=\/var\/log\/mongo\/mongod\.log/)
|
||||
should contain_file('/etc/mongod.conf').with_content(/^fork=true/)
|
||||
}
|
||||
end
|
||||
|
||||
describe 'with absent ensure' do
|
||||
let(:pre_condition) { ["class mongodb::server { $config = '/etc/mongod.conf' $dbpath = '/var/lib/mongo' $ensure = absent }", "include mongodb::server"]}
|
||||
|
||||
it {
|
||||
should contain_file('/etc/mongod.conf').with({ :ensure => 'absent' })
|
||||
}
|
||||
|
||||
end
|
||||
|
||||
describe 'with specific bind_ip values' do
|
||||
let(:pre_condition) { ["class mongodb::server { $config = '/etc/mongod.conf' $dbpath = '/var/lib/mongo' $ensure = present $bind_ip = ['127.0.0.1', '10.1.1.13']}", "include mongodb::server"]}
|
||||
|
||||
it {
|
||||
should contain_file('/etc/mongod.conf').with_content(/bind_ip\s=\s127\.0\.0\.1\,10\.1\.1\.13/)
|
||||
}
|
||||
end
|
||||
|
||||
describe 'when specifying auth to true' do
|
||||
let(:pre_condition) { ["class mongodb::server { $config = '/etc/mongod.conf' $auth = true $dbpath = '/var/lib/mongo' $ensure = present }", "include mongodb::server"]}
|
||||
|
||||
it {
|
||||
should contain_file('/etc/mongod.conf').with_content(/^auth=true/)
|
||||
}
|
||||
end
|
||||
|
||||
describe 'when specifying set_parameter value' do
|
||||
let(:pre_condition) { ["class mongodb::server { $config = '/etc/mongod.conf' $set_parameter = 'textSearchEnable=true' $dbpath = '/var/lib/mongo' $ensure = present }", "include mongodb::server"]}
|
||||
|
||||
it {
|
||||
should contain_file('/etc/mongod.conf').with_content(/^setParameter = textSearchEnable=true/)
|
||||
}
|
||||
end
|
||||
|
||||
describe 'with journal:' do
|
||||
context 'on true with i686 architecture' do
|
||||
let(:pre_condition) { ["class mongodb::server { $config = '/etc/mongod.conf' $dbpath = '/var/lib/mongo' $ensure = present $journal = true }", "include mongodb::server"]}
|
||||
let (:facts) { { :architecture => 'i686' } }
|
||||
|
||||
it {
|
||||
should contain_file('/etc/mongod.conf').with_content(/^journal = true/)
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
# check nested quota and quotafiles
|
||||
describe 'with quota to' do
|
||||
|
||||
context 'true and without quotafiles' do
|
||||
let(:pre_condition) { ["class mongodb::server { $config = '/etc/mongod.conf' $dbpath = '/var/lib/mongo' $ensure = present $quota = true }", "include mongodb::server"]}
|
||||
it {
|
||||
should contain_file('/etc/mongod.conf').with_content(/^quota = true/)
|
||||
}
|
||||
end
|
||||
|
||||
context 'true and with quotafiles' do
|
||||
let(:pre_condition) { ["class mongodb::server { $config = '/etc/mongod.conf' $dbpath = '/var/lib/mongo' $ensure = present $quota = true $quotafiles = 1 }", "include mongodb::server"]}
|
||||
|
||||
it {
|
||||
should contain_file('/etc/mongod.conf').with_content(/quota = true/)
|
||||
should contain_file('/etc/mongod.conf').with_content(/quotaFiles = 1/)
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
end
|
@ -0,0 +1,16 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe 'mongodb::server::install', :type => :class do
|
||||
|
||||
describe 'it should create package and dbpath file' do
|
||||
let(:pre_condition) { ["class mongodb::server { $package_ensure = true $dbpath = '/var/lib/mongo' $user = 'mongodb' $package_name = 'mongodb-server' }", "include mongodb::server"]}
|
||||
|
||||
it {
|
||||
should contain_package('mongodb_server').with({
|
||||
:ensure => 'present',
|
||||
:name => 'mongodb-server',
|
||||
})
|
||||
}
|
||||
end
|
||||
|
||||
end
|
23
deployment/puppet/mongodb/spec/classes/server_spec.rb
Normal file
23
deployment/puppet/mongodb/spec/classes/server_spec.rb
Normal file
@ -0,0 +1,23 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe 'mongodb::server' do
|
||||
let :facts do
|
||||
{
|
||||
:osfamily => 'Debian',
|
||||
:operatingsystem => 'Debian',
|
||||
}
|
||||
end
|
||||
|
||||
context 'with defaults' do
|
||||
it { should contain_class('mongodb::server::install') }
|
||||
it { should contain_class('mongodb::server::config') }
|
||||
end
|
||||
|
||||
context 'when deploying on Solaris' do
|
||||
let :facts do
|
||||
{ :osfamily => 'Solaris' }
|
||||
end
|
||||
it { expect { should raise_error(Puppet::Error) } }
|
||||
end
|
||||
|
||||
end
|
43
deployment/puppet/mongodb/spec/defines/db_spec.rb
Normal file
43
deployment/puppet/mongodb/spec/defines/db_spec.rb
Normal file
@ -0,0 +1,43 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe 'mongodb::db', :type => :define do
|
||||
let(:title) { 'testdb' }
|
||||
|
||||
let(:params) {
|
||||
{ 'user' => 'testuser',
|
||||
'password' => 'testpass',
|
||||
}
|
||||
}
|
||||
|
||||
it 'should contain mongodb_database with mongodb::server requirement' do
|
||||
should contain_mongodb_database('testdb')\
|
||||
.with_require('Class[Mongodb::Server]')
|
||||
end
|
||||
|
||||
it 'should contain mongodb_user with mongodb_database requirement' do
|
||||
should contain_mongodb_user('testuser')\
|
||||
.with_require('Mongodb_database[testdb]')
|
||||
end
|
||||
|
||||
it 'should contain mongodb_user with proper database name' do
|
||||
should contain_mongodb_user('testuser')\
|
||||
.with_database('testdb')
|
||||
end
|
||||
|
||||
it 'should contain mongodb_user with proper roles' do
|
||||
params.merge!({'roles' => ['testrole1', 'testrole2']})
|
||||
should contain_mongodb_user('testuser')\
|
||||
.with_roles(["testrole1", "testrole2"])
|
||||
end
|
||||
|
||||
it 'should prefer password_hash instead of password' do
|
||||
params.merge!({'password_hash' => 'securehash'})
|
||||
should contain_mongodb_user('testuser')\
|
||||
.with_password_hash('securehash')
|
||||
end
|
||||
|
||||
it 'should contain mongodb_database with proper tries param' do
|
||||
params.merge!({'tries' => 5})
|
||||
should contain_mongodb_database('testdb').with_tries(5)
|
||||
end
|
||||
end
|
1
deployment/puppet/mongodb/spec/spec_helper.rb
Normal file
1
deployment/puppet/mongodb/spec/spec_helper.rb
Normal file
@ -0,0 +1 @@
|
||||
require 'puppetlabs_spec_helper/module_spec_helper'
|
34
deployment/puppet/mongodb/spec/spec_helper_system.rb
Normal file
34
deployment/puppet/mongodb/spec/spec_helper_system.rb
Normal file
@ -0,0 +1,34 @@
|
||||
require 'rspec-system/spec_helper'
|
||||
require 'rspec-system-puppet/helpers'
|
||||
require 'rspec-system-serverspec/helpers'
|
||||
|
||||
include RSpecSystemPuppet::Helpers
|
||||
include Serverspec::Helper::RSpecSystem
|
||||
include Serverspec::Helper::DetectOS
|
||||
|
||||
RSpec.configure do |c|
|
||||
# Project root
|
||||
proj_root = File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
||||
|
||||
# Enable colour
|
||||
c.tty = true
|
||||
|
||||
c.include RSpecSystemPuppet::Helpers
|
||||
|
||||
# This is where we 'setup' the nodes before running our tests
|
||||
c.before :suite do
|
||||
# Install puppet
|
||||
puppet_install
|
||||
|
||||
# Install modules and dependencies
|
||||
puppet_module_install(:source => proj_root, :module_name => 'mongodb')
|
||||
shell('puppet module install puppetlabs-stdlib')
|
||||
shell('puppet module install puppetlabs-apt')
|
||||
|
||||
case node.facts['osfamily']
|
||||
when 'RedHat'
|
||||
shell('puppet module install stahnma-epel')
|
||||
puppet_apply('include epel')
|
||||
end
|
||||
end
|
||||
end
|
10
deployment/puppet/mongodb/spec/system/basic_spec.rb
Normal file
10
deployment/puppet/mongodb/spec/system/basic_spec.rb
Normal file
@ -0,0 +1,10 @@
|
||||
require 'spec_helper_system'
|
||||
|
||||
describe 'basic tests:' do
|
||||
# Using puppet_apply as a subject
|
||||
context puppet_apply 'notice("foo")' do
|
||||
its(:stdout) { should =~ /foo/ }
|
||||
its(:stderr) { should be_empty }
|
||||
its(:exit_code) { should be_zero }
|
||||
end
|
||||
end
|
111
deployment/puppet/mongodb/spec/system/server_10gen_spec.rb
Normal file
111
deployment/puppet/mongodb/spec/system/server_10gen_spec.rb
Normal file
@ -0,0 +1,111 @@
|
||||
require 'spec_helper_system'
|
||||
|
||||
describe 'mongodb::server: with 10gen repo' do
|
||||
|
||||
case node.facts['osfamily']
|
||||
when 'RedHat'
|
||||
package_name = 'mongo-10gen-server'
|
||||
service_name = 'mongod'
|
||||
config_file = '/etc/mongod.conf'
|
||||
when 'Debian'
|
||||
package_name = 'mongodb-10gen'
|
||||
service_name = 'mongodb'
|
||||
config_file = '/etc/mongodb.conf'
|
||||
end
|
||||
|
||||
client_name = 'mongo --version'
|
||||
|
||||
context 'default parameters' do
|
||||
it 'should work with no errors' do
|
||||
case node.facts['osfamily']
|
||||
when 'RedHat'
|
||||
pp = <<-EOS
|
||||
class { 'mongodb::globals': manage_package_repo => true }->
|
||||
class { 'mongodb::server': }->
|
||||
class { 'mongodb::client': }
|
||||
EOS
|
||||
when 'Debian'
|
||||
pp = <<-EOS
|
||||
class { 'mongodb::globals': manage_package_repo => true }->
|
||||
class { 'mongodb::server': }
|
||||
EOS
|
||||
end
|
||||
|
||||
puppet_apply(pp) do |r|
|
||||
r.exit_code.should == 2
|
||||
r.refresh
|
||||
r.exit_code.should == 0
|
||||
end
|
||||
end
|
||||
|
||||
describe package(package_name) do
|
||||
it { should be_installed }
|
||||
end
|
||||
|
||||
describe file(config_file) do
|
||||
it { should be_file }
|
||||
end
|
||||
|
||||
describe service(service_name) do
|
||||
it { should be_enabled }
|
||||
it { should be_running }
|
||||
end
|
||||
|
||||
describe port(27017) do
|
||||
it do
|
||||
sleep(20)
|
||||
should be_listening
|
||||
end
|
||||
end
|
||||
|
||||
describe command(client_name) do
|
||||
it do
|
||||
should return_exit_status 0
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'test using custom port' do
|
||||
it 'change port to 27018' do
|
||||
pp = <<-EOS
|
||||
class { 'mongodb::globals': manage_package_repo => true }->
|
||||
class { 'mongodb::server': port => 27018 }
|
||||
EOS
|
||||
|
||||
puppet_apply(pp) do |r|
|
||||
r.exit_code.should == 2
|
||||
end
|
||||
end
|
||||
|
||||
describe port(27018) do
|
||||
sleep(20)
|
||||
it { should be_listening }
|
||||
end
|
||||
end
|
||||
|
||||
context 'test shutdown of custom port' do
|
||||
it 'shut down service on port 27018' do
|
||||
pp = <<-EOS
|
||||
class {'mongodb::globals': manage_package_repo => true}->
|
||||
class {'mongodb::server': port => 27018, ensure => false}
|
||||
EOS
|
||||
|
||||
puppet_apply(pp) do |r|
|
||||
r.exit_code.should == 2
|
||||
end
|
||||
end
|
||||
|
||||
describe port(27018) do
|
||||
it { should_not be_listening}
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe 'cleanup' do
|
||||
it 'uninstalls mongodb' do
|
||||
puppet_apply("class {'mongodb::globals': manage_package_repo => true }-> class { 'mongodb::server': ensure => false }-> class { 'mongodb::client': ensure => false}") do |r|
|
||||
r.exit_code.should_not == 1
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
108
deployment/puppet/mongodb/spec/system/server_distro_spec.rb
Normal file
108
deployment/puppet/mongodb/spec/system/server_distro_spec.rb
Normal file
@ -0,0 +1,108 @@
|
||||
require 'spec_helper_system'
|
||||
|
||||
describe 'mongodb::server:' do
|
||||
|
||||
case node.facts['osfamily']
|
||||
when 'RedHat'
|
||||
package_name = 'mongodb-server'
|
||||
service_name = 'mongod'
|
||||
config_file = '/etc/mongodb.conf'
|
||||
when 'Debian'
|
||||
package_name = 'mongodb-server'
|
||||
service_name = 'mongodb'
|
||||
config_file = '/etc/mongodb.conf'
|
||||
end
|
||||
|
||||
client_name = 'mongo --version'
|
||||
|
||||
context 'default parameters' do
|
||||
it 'should work with no errors' do
|
||||
case node.facts['osfamily']
|
||||
when 'RedHat'
|
||||
pp = <<-EOS
|
||||
class { 'mongodb::server': }
|
||||
class { 'mongodb::client': }
|
||||
EOS
|
||||
when 'Debian'
|
||||
pp = <<-EOS
|
||||
class { 'mongodb::server': }
|
||||
EOS
|
||||
end
|
||||
|
||||
puppet_apply(pp) do |r|
|
||||
r.exit_code.should == 2
|
||||
r.refresh
|
||||
r.exit_code.should == 0
|
||||
end
|
||||
end
|
||||
|
||||
describe package(package_name) do
|
||||
it { should be_installed }
|
||||
end
|
||||
|
||||
describe file(config_file) do
|
||||
it { should be_file }
|
||||
end
|
||||
|
||||
describe service(service_name) do
|
||||
it { should be_enabled }
|
||||
it { should be_running }
|
||||
end
|
||||
|
||||
describe port(27017) do
|
||||
it do
|
||||
sleep(20)
|
||||
should be_listening
|
||||
end
|
||||
end
|
||||
|
||||
describe command(client_name) do
|
||||
it do
|
||||
should return_exit_status 0
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'test using custom port' do
|
||||
it 'change port to 27018' do
|
||||
pp = <<-EOS
|
||||
class { 'mongodb::server': port => 27018 }
|
||||
EOS
|
||||
|
||||
puppet_apply(pp) do |r|
|
||||
r.exit_code.should == 2
|
||||
end
|
||||
end
|
||||
|
||||
describe port(27018) do
|
||||
sleep(20)
|
||||
it { should be_listening }
|
||||
end
|
||||
end
|
||||
|
||||
context 'test shutdown of custom port' do
|
||||
it 'shut down service on port 27018' do
|
||||
pp = <<-EOS
|
||||
class {'mongodb::globals': manage_package_repo => true}->
|
||||
class {'mongodb::server': port => 27018, ensure => false}
|
||||
EOS
|
||||
|
||||
puppet_apply(pp) do |r|
|
||||
r.exit_code.should == 2
|
||||
end
|
||||
end
|
||||
|
||||
describe port(27018) do
|
||||
it { should_not be_listening}
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe 'cleanup' do
|
||||
it 'uninstalls mongodb' do
|
||||
puppet_apply("class {'mongodb::globals': manage_package_repo => true }-> class { 'mongodb::server': ensure => false }-> class { 'mongodb::client': ensure => false}") do |r|
|
||||
r.exit_code.should_not == 1
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
27
deployment/puppet/mongodb/spec/unit/mongodb_password_spec.rb
Normal file
27
deployment/puppet/mongodb/spec/unit/mongodb_password_spec.rb
Normal file
@ -0,0 +1,27 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe 'the mongodb_password function' do
|
||||
before :all do
|
||||
Puppet::Parser::Functions.autoloader.loadall
|
||||
end
|
||||
|
||||
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
|
||||
|
||||
it 'should exist' do
|
||||
Puppet::Parser::Functions.function('mongodb_password').should == 'function_mongodb_password'
|
||||
end
|
||||
|
||||
it 'should raise a ParseError if there no arguments' do
|
||||
lambda { scope.function_mongodb_password([]) }.should( raise_error(Puppet::ParseError))
|
||||
end
|
||||
|
||||
it 'should raise a ParseError if there is more than 2 arguments' do
|
||||
lambda { scope.function_mongodb_password(%w(foo bar baz)) }.should( raise_error(Puppet::ParseError))
|
||||
end
|
||||
|
||||
it 'should convert password into a hash' do
|
||||
result = scope.function_mongodb_password(%w(user pass))
|
||||
result.should(eq('e0c4a7b97d4db31f5014e9694e567d6b'))
|
||||
end
|
||||
|
||||
end
|
@ -0,0 +1,35 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe Puppet::Type.type(:mongodb_database).provider(:mongodb) do
|
||||
|
||||
let(:resource) { Puppet::Type.type(:mongodb_database).new(
|
||||
{ :ensure => :present,
|
||||
:name => 'new_database',
|
||||
:provider => described_class.name
|
||||
}
|
||||
)}
|
||||
|
||||
let(:provider) { resource.provider }
|
||||
|
||||
describe 'create' do
|
||||
it 'makes a database' do
|
||||
provider.expects(:mongo)
|
||||
provider.create
|
||||
end
|
||||
end
|
||||
|
||||
describe 'destroy' do
|
||||
it 'removes a database' do
|
||||
provider.expects(:mongo)
|
||||
provider.destroy
|
||||
end
|
||||
end
|
||||
|
||||
describe 'exists?' do
|
||||
it 'checks if database exists' do
|
||||
provider.expects(:mongo).at_least(2).returns("db1,new_database,db2")
|
||||
provider.exists?.should be_true
|
||||
end
|
||||
end
|
||||
|
||||
end
|
@ -0,0 +1,153 @@
|
||||
#
|
||||
# Authors: Emilien Macchi <emilien.macchi@enovance.com>
|
||||
# Francois Charlier <francois.charlier@enovance.com>
|
||||
#
|
||||
|
||||
require 'spec_helper'
|
||||
|
||||
describe Puppet::Type.type(:mongodb_replset).provider(:mongo) do
|
||||
|
||||
valid_members = ['mongo1:27017', 'mongo2:27017', 'mongo3:27017']
|
||||
|
||||
let(:resource) { Puppet::Type.type(:mongodb_replset).new(
|
||||
{ :ensure => :present,
|
||||
:name => 'rs_test',
|
||||
:members => valid_members,
|
||||
:provider => :mongo
|
||||
}
|
||||
)}
|
||||
|
||||
let(:provider) { resource.provider }
|
||||
|
||||
describe 'create' do
|
||||
it 'should create a replicaset' do
|
||||
provider.stubs(:mongo_command).returns(
|
||||
{ "info" => "Config now saved locally. Should come online in about a minute.",
|
||||
"ok" => 1 } )
|
||||
provider.create
|
||||
end
|
||||
end
|
||||
|
||||
describe 'exists?' do
|
||||
describe 'when the replicaset is not created' do
|
||||
it 'returns false' do
|
||||
provider.stubs(:mongo).returns(<<EOT)
|
||||
{
|
||||
"startupStatus" : 3,
|
||||
"info" : "run rs.initiate(...) if not yet done for the set",
|
||||
"ok" : 0,
|
||||
"errmsg" : "can't get local.system.replset config from self or any seed (EMPTYCONFIG)"
|
||||
}
|
||||
EOT
|
||||
provider.exists?.should be_false
|
||||
end
|
||||
end
|
||||
|
||||
describe 'when the replicaset is created' do
|
||||
it 'returns true' do
|
||||
provider.stubs(:mongo).returns(<<EOT)
|
||||
{
|
||||
"set" : "rs_test",
|
||||
"date" : ISODate("2014-01-10T18:39:54Z"),
|
||||
"myState" : 1,
|
||||
"members" : [ ],
|
||||
"ok" : 1
|
||||
}
|
||||
EOT
|
||||
provider.exists?.should be_true
|
||||
end
|
||||
end
|
||||
|
||||
describe 'when at least one member is configured with another replicaset name' do
|
||||
it 'raises an error' do
|
||||
provider.stubs(:mongo).returns(<<EOT)
|
||||
{
|
||||
"set" : "rs_another",
|
||||
"date" : ISODate("2014-01-10T18:39:54Z"),
|
||||
"myState" : 1,
|
||||
"members" : [ ],
|
||||
"ok" : 1
|
||||
}
|
||||
EOT
|
||||
expect { provider.exists? }.to raise_error(Puppet::Error, /is already part of another replicaset\.$/)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'when at least one member is not running with --replSet' do
|
||||
it 'raises an error' do
|
||||
provider.stubs(:mongo).returns('{ "ok" : 0, "errmsg" : "not running with --replSet" }')
|
||||
expect { provider.exists? }.to raise_error(Puppet::Error, /is not supposed to be part of a replicaset\.$/)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'when no member is available' do
|
||||
it 'raises an error' do
|
||||
provider.stubs(:mongo_command).raises(Puppet::ExecutionFailure, <<EOT)
|
||||
Fri Jan 10 20:20:33.995 Error: couldn't connect to server localhost:9999 at src/mongo/shell/mongo.js:147
|
||||
exception: connect failed
|
||||
EOT
|
||||
expect { provider.exists? }.to raise_error(Puppet::Error, "Can't connect to any member of replicaset #{resource[:name]}.")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'members' do
|
||||
it 'returns the members of a configured replicaset ' do
|
||||
provider.stubs(:mongo).returns(<<EOT)
|
||||
{
|
||||
"setName" : "rs_test",
|
||||
"ismaster" : true,
|
||||
"secondary" : false,
|
||||
"hosts" : [
|
||||
"mongo1:27017",
|
||||
"mongo2:27017",
|
||||
"mongo3:27017"
|
||||
],
|
||||
"primary" : "mongo1:27017",
|
||||
"me" : "mongo1:27017",
|
||||
"maxBsonObjectSize" : 16777216,
|
||||
"maxMessageSizeBytes" : 48000000,
|
||||
"localTime" : ISODate("2014-01-10T19:31:51.281Z"),
|
||||
"ok" : 1
|
||||
}
|
||||
EOT
|
||||
provider.members.should =~ valid_members
|
||||
end
|
||||
|
||||
it 'raises an error when the master host is not available' do
|
||||
provider.stubs(:master_host).returns(nil)
|
||||
expect { provider.members }.to raise_error(Puppet::Error, "Can't find master host for replicaset #{resource[:name]}.")
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe 'members=' do
|
||||
it 'adds missing members to an existing replicaset' do
|
||||
provider.stubs(:mongo).returns(<<EOT)
|
||||
{
|
||||
"setName" : "rs_test",
|
||||
"ismaster" : true,
|
||||
"secondary" : false,
|
||||
"hosts" : [
|
||||
"mongo1:27017"
|
||||
],
|
||||
"primary" : "mongo1:27017",
|
||||
"me" : "mongo1:27017",
|
||||
"maxBsonObjectSize" : 16777216,
|
||||
"maxMessageSizeBytes" : 48000000,
|
||||
"localTime" : ISODate("2014-01-10T19:31:51.281Z"),
|
||||
"ok" : 1
|
||||
}
|
||||
EOT
|
||||
provider.expects('rs_add').times(2)
|
||||
provider.members=(valid_members)
|
||||
end
|
||||
|
||||
it 'raises an error when the master host is not available' do
|
||||
provider.stubs(:master_host).returns(nil)
|
||||
expect { provider.members=(valid_members) }.to raise_error(Puppet::Error, "Can't find master host for replicaset #{resource[:name]}.")
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
@ -0,0 +1,66 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe Puppet::Type.type(:mongodb_user).provider(:mongodb) do
|
||||
|
||||
let(:resource) { Puppet::Type.type(:mongodb_user).new(
|
||||
{ :ensure => :present,
|
||||
:name => 'new_user',
|
||||
:database => 'new_database',
|
||||
:password_hash => 'pass',
|
||||
:roles => ['role1', 'role2'],
|
||||
:provider => described_class.name
|
||||
}
|
||||
)}
|
||||
|
||||
let(:provider) { resource.provider }
|
||||
|
||||
describe 'create' do
|
||||
it 'creates a user' do
|
||||
provider.expects(:mongo)
|
||||
provider.create
|
||||
end
|
||||
end
|
||||
|
||||
describe 'destroy' do
|
||||
it 'removes a user' do
|
||||
provider.expects(:mongo)
|
||||
provider.destroy
|
||||
end
|
||||
end
|
||||
|
||||
describe 'exists?' do
|
||||
it 'checks if user exists' do
|
||||
provider.expects(:mongo).at_least(2).returns("1")
|
||||
provider.exists?.should be_true
|
||||
end
|
||||
end
|
||||
|
||||
describe 'password_hash' do
|
||||
it 'returns a password_hash' do
|
||||
provider.expects(:mongo).returns("pass\n")
|
||||
provider.password_hash.should == "pass"
|
||||
end
|
||||
end
|
||||
|
||||
describe 'password_hash=' do
|
||||
it 'changes a password_hash' do
|
||||
provider.expects(:mongo)
|
||||
provider.password_hash=("newpass")
|
||||
end
|
||||
end
|
||||
|
||||
describe 'roles' do
|
||||
it 'returns a sorted roles' do
|
||||
provider.expects(:mongo).returns("role2,role1\n")
|
||||
provider.roles.should == ['role1','role2']
|
||||
end
|
||||
end
|
||||
|
||||
describe 'roles=' do
|
||||
it 'changes a roles' do
|
||||
provider.expects(:mongo)
|
||||
provider.roles=(['role3','role4'])
|
||||
end
|
||||
end
|
||||
|
||||
end
|
@ -0,0 +1,24 @@
|
||||
require 'puppet'
|
||||
require 'puppet/type/mongodb_database'
|
||||
describe Puppet::Type.type(:mongodb_database) do
|
||||
|
||||
before :each do
|
||||
@db = Puppet::Type.type(:mongodb_database).new(:name => 'test')
|
||||
end
|
||||
|
||||
it 'should accept a database name' do
|
||||
@db[:name].should == 'test'
|
||||
end
|
||||
|
||||
it 'should accept a tries parameter' do
|
||||
@db[:tries] = 5
|
||||
@db[:tries].should == 5
|
||||
end
|
||||
|
||||
it 'should require a name' do
|
||||
expect {
|
||||
Puppet::Type.type(:mongodb_database).new({})
|
||||
}.to raise_error(Puppet::Error, 'Title or name must be provided')
|
||||
end
|
||||
|
||||
end
|
@ -0,0 +1,28 @@
|
||||
#
|
||||
# Author: Emilien Macchi <emilien.macchi@enovance.com>
|
||||
#
|
||||
|
||||
require 'puppet'
|
||||
require 'puppet/type/mongodb_replset'
|
||||
describe Puppet::Type.type(:mongodb_replset) do
|
||||
|
||||
before :each do
|
||||
@replset = Puppet::Type.type(:mongodb_replset).new(:name => 'test')
|
||||
end
|
||||
|
||||
it 'should accept a replica set name' do
|
||||
@replset[:name].should == 'test'
|
||||
end
|
||||
|
||||
it 'should accept a members array' do
|
||||
@replset[:members] = ['mongo1:27017', 'mongo2:27017']
|
||||
@replset[:members].should == ['mongo1:27017', 'mongo2:27017']
|
||||
end
|
||||
|
||||
it 'should require a name' do
|
||||
expect {
|
||||
Puppet::Type.type(:mongodb_replset).new({})
|
||||
}.to raise_error(Puppet::Error, 'Title or name must be provided')
|
||||
end
|
||||
|
||||
end
|
@ -0,0 +1,67 @@
|
||||
require 'puppet'
|
||||
require 'puppet/type/mongodb_user'
|
||||
describe Puppet::Type.type(:mongodb_user) do
|
||||
|
||||
before :each do
|
||||
@user = Puppet::Type.type(:mongodb_user).new(
|
||||
:name => 'test',
|
||||
:database => 'testdb',
|
||||
:password_hash => 'pass')
|
||||
end
|
||||
|
||||
it 'should accept a user name' do
|
||||
@user[:name].should == 'test'
|
||||
end
|
||||
|
||||
it 'should accept a database name' do
|
||||
@user[:database].should == 'testdb'
|
||||
end
|
||||
|
||||
it 'should accept a tries parameter' do
|
||||
@user[:tries] = 5
|
||||
@user[:tries].should == 5
|
||||
end
|
||||
|
||||
it 'should accept a password' do
|
||||
@user[:password_hash] = 'foo'
|
||||
@user[:password_hash].should == 'foo'
|
||||
end
|
||||
|
||||
it 'should use default role' do
|
||||
@user[:roles].should == ['dbAdmin']
|
||||
end
|
||||
|
||||
it 'should accept a roles array' do
|
||||
@user[:roles] = ['role1', 'role2']
|
||||
@user[:roles].should == ['role1', 'role2']
|
||||
end
|
||||
|
||||
it 'should require a name' do
|
||||
expect {
|
||||
Puppet::Type.type(:mongodb_user).new({})
|
||||
}.to raise_error(Puppet::Error, 'Title or name must be provided')
|
||||
end
|
||||
|
||||
it 'should require a database' do
|
||||
expect {
|
||||
Puppet::Type.type(:mongodb_user).new({:name => 'test', :password_hash => 'pass'})
|
||||
}.to raise_error(Puppet::Error, 'Parameter \'database\' must be set')
|
||||
end
|
||||
|
||||
it 'should require a password_hash' do
|
||||
expect {
|
||||
Puppet::Type.type(:mongodb_user).new({:name => 'test', :database => 'testdb'})
|
||||
}.to raise_error(Puppet::Error, 'Property \'password_hash\' must be set. Use mongodb_password() for creating hash.')
|
||||
end
|
||||
|
||||
it 'should sort roles' do
|
||||
# Reinitialize type with explicit unsorted roles.
|
||||
@user = Puppet::Type.type(:mongodb_user).new(
|
||||
:name => 'test',
|
||||
:database => 'testdb',
|
||||
:password_hash => 'pass',
|
||||
:roles => ['b', 'a'])
|
||||
@user[:roles].should == ['a', 'b']
|
||||
end
|
||||
|
||||
end
|
164
deployment/puppet/mongodb/templates/mongodb.conf.erb
Normal file
164
deployment/puppet/mongodb/templates/mongodb.conf.erb
Normal file
@ -0,0 +1,164 @@
|
||||
# mongo.conf - generated from Puppet
|
||||
|
||||
#where to log
|
||||
logpath=<%= @logpath %>
|
||||
logappend=<%= @logappend %>
|
||||
<% if @bind_ip -%>
|
||||
# Set this option to configure the mongod or mongos process to bind to and
|
||||
# listen for connections from applications on this address.
|
||||
# You may concatenate a list of comma separated values to bind mongod to multiple IP addresses.
|
||||
bind_ip = <%= @bind_ip.join(',') %>
|
||||
<% end -%>
|
||||
<% if @fork -%>
|
||||
# fork and run in background
|
||||
fork=<%= @fork %>
|
||||
<% end -%>
|
||||
port = <%= @port %>
|
||||
dbpath=<%= @dbpath %>
|
||||
<% if @pidfilepath -%>
|
||||
# location of pidfile
|
||||
pidfilepath = <%= @pidfilepath %>
|
||||
<% end -%>
|
||||
<% if @nojournal -%>
|
||||
# Disables write-ahead journaling
|
||||
nojournal = <%= @nojournal %>
|
||||
<% end -%>
|
||||
<% if @journal -%>
|
||||
# Enables journaling
|
||||
journal = <%= @journal %>
|
||||
<% end -%>
|
||||
<% if @cpu -%>
|
||||
# Enables periodic logging of CPU utilization and I/O wait
|
||||
cpu = <%= @cpu %>
|
||||
<% end -%>
|
||||
# Turn on/off security. Off is currently the default
|
||||
<% if @noauth -%>
|
||||
noauth=<%= @noauth %>
|
||||
<% end -%>
|
||||
<% if @auth -%>
|
||||
auth=<%= @auth %>
|
||||
<% end -%>
|
||||
<% if @verbose -%>
|
||||
# Verbose logging output.
|
||||
verbose = <%= @verbose %>
|
||||
<% end -%>
|
||||
<% if @verbositylevel -%>
|
||||
<%= @verbositylevel -%> = true
|
||||
<% end -%>
|
||||
<% if @objcheck -%>
|
||||
# Inspect all client data for validity on receipt (useful for
|
||||
# developing drivers)
|
||||
objcheck = <%= @objcheck %>
|
||||
<% end -%>
|
||||
<% if @maxconns -%>
|
||||
maxConns = <%= @maxconns %>
|
||||
<% end -%>
|
||||
<% if @quota -%>
|
||||
# Enable db quota management
|
||||
quota = <%= @quota %>
|
||||
<% if @quotafiles -%>
|
||||
quotaFiles = <%= @quotafiles %>
|
||||
<% end -%>
|
||||
<% end -%>
|
||||
<% if @diaglog -%>
|
||||
# Set oplogging level where n is
|
||||
# 0=off (default)
|
||||
# 1=W
|
||||
# 2=R
|
||||
# 3=both
|
||||
# 7=W+some reads
|
||||
diaglog = <%= @diaglog %>
|
||||
<% end -%>
|
||||
<% if @oplog_size -%>
|
||||
# Specifies a maximum size in megabytes for the replication operation log
|
||||
oplogSize = <%= @oplog_size %>
|
||||
<% end -%>
|
||||
<% if @nohints -%>
|
||||
# Ignore query hints
|
||||
nohints = <%= @nohints %>
|
||||
<% end -%>
|
||||
<% if @nohttpinterface -%>
|
||||
# Disable the HTTP interface (Defaults to localhost:27018).
|
||||
nohttpinterface = <%= @nohttpinterface %>
|
||||
<% end -%>
|
||||
<% if @noscripting -%>
|
||||
# Turns off server-side scripting. This will result in greatly limited
|
||||
# functionality
|
||||
noscripting = <%= @noscripting %>
|
||||
<% end -%>
|
||||
<% if @notablescan -%>
|
||||
# Turns off table scans. Any query that would do a table scan fails.
|
||||
notablescan = <%= @notablescan %>
|
||||
<% end -%>
|
||||
<% if @noprealloc -%>
|
||||
# Disable data file preallocation.
|
||||
noprealloc = <%= @noprealloc %>
|
||||
<% end -%>
|
||||
<% if @nssize -%>
|
||||
# Specify .ns file size for new databases in megabytes.
|
||||
nssize = <%= @nssize %>
|
||||
<% end -%>
|
||||
<% if @mms_token -%>
|
||||
# Accout token for Mongo monitoring server.
|
||||
mms-token = <%= @mms_token %>
|
||||
<% end -%>
|
||||
<% if @mms_name -%>
|
||||
# Server name for Mongo monitoring server.
|
||||
mms-name = <%= @mms_name %>
|
||||
<% end -%>
|
||||
<% if @mms_interval -%>
|
||||
# Ping interval for Mongo monitoring server.
|
||||
mms-interval = <%= @mms_interval %>
|
||||
<% end -%>
|
||||
<% if @slave -%>
|
||||
slave = <%= @slave %>
|
||||
<% end -%>
|
||||
<% if @source -%>
|
||||
source = <%= @source %>
|
||||
<% end -%>
|
||||
<% if @only -%>
|
||||
# Slave only: specify a single database to replicate
|
||||
only = <%= @only %>
|
||||
<% end -%>
|
||||
<% if @master -%>
|
||||
master = <%= @master %>
|
||||
<% end -%>
|
||||
<% if @directoryperdb -%>
|
||||
# Alters the storage pattern of the data directory to store each database
|
||||
# files in a distinct folder.
|
||||
directoryperdb = <%= @directoryperdb %>
|
||||
<% end -%>
|
||||
<% if @replset -%>
|
||||
# Configure ReplicaSet membership
|
||||
replSet = <%= @replset %>
|
||||
<% end -%>
|
||||
<% if @smallfiles -%>
|
||||
# Use a smaller default data file size.
|
||||
smallfiles = <%= @smallfiles %>
|
||||
<% end -%>
|
||||
<% if @rest -%>
|
||||
# Enable rest API (disabled by default)
|
||||
rest = <%= @rest %>
|
||||
<% end -%>
|
||||
<% if @profile -%>
|
||||
# Modify this value to changes the level of database profiling, which inserts
|
||||
# information about operation performance into output of mongod or the log file.
|
||||
#0 = Off. No profiling. default
|
||||
#1 = On. Only includes slow operations.
|
||||
#2 = On. Includes all operations.
|
||||
profile = <%= @profile %>
|
||||
<% end -%>
|
||||
<% if @slowms -%>
|
||||
# Sets the threshold in milliseconds for mongod to consider a query slow for the profiler.
|
||||
slowms = <%= @slowms %>
|
||||
<% end -%>
|
||||
<% if @keyfile -%>
|
||||
# Specify the path to a key file to store authentication information.
|
||||
keyFile = <%= @keyfile %>
|
||||
<% end -%>
|
||||
<% if @directoryperdb -%>
|
||||
directoryperdb = <%= @directoryperdb %>
|
||||
<% end -%>
|
||||
<% if @set_parameter -%>
|
||||
setParameter = <%= @set_parameter %>
|
||||
<% end -%>
|
3
deployment/puppet/mongodb/tests/globals.pp
Normal file
3
deployment/puppet/mongodb/tests/globals.pp
Normal file
@ -0,0 +1,3 @@
|
||||
class { 'mongodb::globals':
|
||||
manage_package_repo => true
|
||||
}
|
1
deployment/puppet/mongodb/tests/init.pp
Normal file
1
deployment/puppet/mongodb/tests/init.pp
Normal file
@ -0,0 +1 @@
|
||||
class { '::mongodb': }
|
16
deployment/puppet/mongodb/tests/replicaset.pp
Normal file
16
deployment/puppet/mongodb/tests/replicaset.pp
Normal file
@ -0,0 +1,16 @@
|
||||
node default {
|
||||
class { '::mongodb::globals':
|
||||
manage_package_repo => true
|
||||
} ->
|
||||
class { '::mongodb::server':
|
||||
smallfiles => true,
|
||||
bind_ip => ['0.0.0.0'],
|
||||
replset => 'rsmain'
|
||||
}
|
||||
}
|
||||
|
||||
node /mongo1/ inherits default {
|
||||
mongodb_replset{'rsmain':
|
||||
members => ['mongo1:27017', 'mongo2:27017', 'mongo3:27017']
|
||||
}
|
||||
}
|
2
deployment/puppet/mongodb/tests/server.pp
Normal file
2
deployment/puppet/mongodb/tests/server.pp
Normal file
@ -0,0 +1,2 @@
|
||||
class { 'mongodb::globals': manage_package_repo => true }->
|
||||
class { 'mongodb::server': }
|
Loading…
Reference in New Issue
Block a user