Skip to content

Commit

Permalink
server: support arbiter node config introduced by PR#182
Browse files Browse the repository at this point in the history
  • Loading branch information
pecharmin committed Nov 1, 2018
1 parent 2aef855 commit 02d32f4
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 3 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -418,14 +418,19 @@ set name as an argument to this set. All hosts must have the same set name.
An array of member hosts for the replica set.
Mutually exclusive with `replset_config` param.

##### `replset_arbiter`
A string to identify an arbiter instance for the replica set.
The arbiter node must also appear in `replset_members`.
Mutually exclusive with `replset_config` param.

##### `replset_config`
A hash that is used to configure the replica set.
Mutually exclusive with `replset_members` param.

```puppet
class mongodb::server {
replset => 'rsmain',
replset_config => { 'rsmain' => { ensure => present, settings => { heartbeatTimeoutSecs => 15, getLastErrorModes => { ttmode => { dc => 1 } } }, members => [{'host'=>'host1:27017', 'tags':{ 'dc' : 'east'}}, { 'host' => 'host2:27017'}, 'host3:27017'] } }
replset_config => { 'rsmain' => { ensure => present, settings => { heartbeatTimeoutSecs => 15, getLastErrorModes => { ttmode => { dc => 1 } } }, members => [{'host'=>'host1:27017', 'tags':{ 'dc' : 'east'}}, { 'host' => 'host2:27017'}, 'host3:27017'] }, arbiter => ['host3:27017'] }
}
```
Expand Down
6 changes: 4 additions & 2 deletions manifests/server.pp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
Optional[String] $replset = undef,
Optional[Hash] $replset_config = undef,
Optional[Array] $replset_members = undef,
Optional[String] $replset_arbiter = undef,
Optional[Boolean] $configsvr = undef,
Optional[Boolean] $shardsvr = undef,
Optional[Boolean] $rest = undef,
Expand Down Expand Up @@ -113,8 +114,8 @@
# Set-up replicasets
if $replset {
# Check that we've got either a members array or a replset_config hash
if $replset_members and $replset_config {
fail('You can provide either replset_members or replset_config, not both.')
if ( $replset_members or $replset_arbiter ) and $replset_config {
fail('You can provide either replset_members incl. replset_arbiter or replset_config, not both.')
} elsif !$replset_members and !$replset_config {
# No members or config provided. Warn about it.
warning('Replset specified, but no replset_members or replset_config provided.')
Expand All @@ -129,6 +130,7 @@
"${replset}" => {
'ensure' => 'present',
'members' => $replset_members,
'arbiter' => $replset_arbiter,
},
}
}
Expand Down
30 changes: 30 additions & 0 deletions spec/classes/server_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,36 @@

it { is_expected.to contain_class('mongodb::replset').with_sets(rsConf) }
end

describe 'should setup using replset_members with replset_arbiter' do
let(:rsConf) do
{
'rsTest' => {
'ensure' => 'present',
'members' => [
'mongo1:27017',
'mongo2:27017',
'mongo3:27017'
],
'arbiter' => 'mongo3:27017'
}
}
end

let(:params) do
{
replset: 'rsTest',
replset_members: [
'mongo1:27017',
'mongo2:27017',
'mongo3:27017'
],
'arbiter' => 'mongo3:27017'
}
end

it { is_expected.to contain_class('mongodb::replset').with_sets(rsConf) }
end
end
end
end
Expand Down

0 comments on commit 02d32f4

Please sign in to comment.