Skip to content

Commit

Permalink
Merge pull request #685 from traylenator/hiera
Browse files Browse the repository at this point in the history
Set version defaults with hiera data
  • Loading branch information
zilchms authored Jan 29, 2024
2 parents 235212d + 6537f8b commit bc94e0d
Show file tree
Hide file tree
Showing 5 changed files with 134 additions and 135 deletions.
24 changes: 6 additions & 18 deletions REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -207,31 +207,19 @@ Default value: `undef`

##### <a name="-mongodb--globals--version"></a>`version`

Data type: `Any`


Data type: `Optional[String[1]]`

Default value:
Version of mongodb to install

```puppet
fact('os.distro.codename') ? { # Debian 10 doesn't provide mongodb 3.6.
'buster' => '4.4.8',
default => undef
```
Default value: `undef`

##### <a name="-mongodb--globals--manage_package_repo"></a>`manage_package_repo`

Data type: `Any`


Data type: `Optional[Boolean]`

Default value:
If `true` configure upstream mongodb repos

```puppet
fact('os.distro.codename') ? { # Debian 10 doesn't provide mongodb packages. So manage it!
'buster' => true,
default => undef
```
Default value: `undef`

##### <a name="-mongodb--globals--manage_package"></a>`manage_package`

Expand Down
3 changes: 3 additions & 0 deletions data/Debian-10.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
mongodb::globals::version: '4.4.8' # Debian 10 doesn't provide mongodb 3.6.
mongodb::globals::manage_package_repo: true # Debian 10 doesn't provide mongodb packages. So manage it!
14 changes: 14 additions & 0 deletions hiera.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
version: 5
defaults:
datadir: 'data'
data_hash: 'yaml_data'
hierarchy:
- name: 'Major Version'
path: '%{facts.os.name}-%{facts.os.release.major}.yaml'
- name: 'OS Family Major Version'
path: '%{facts.os.family}-family-%{facts.os.release.major}.yaml'
- name: 'OS Family'
path: '%{facts.os.family}-family.yaml'
- name: 'common'
path: 'common.yaml'
102 changes: 44 additions & 58 deletions manifests/globals.pp
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
# @param group
# @param ipv6
# @param bind_ip
# @param version
# @param manage_package_repo
# @param version Version of mongodb to install
# @param manage_package_repo If `true` configure upstream mongodb repos
# @param manage_package
# @param repo_proxy
# @param proxy_username
Expand All @@ -25,40 +25,33 @@
# @param manage_pidfile
#
class mongodb::globals (
$server_package_name = undef,
$client_package_name = undef,
$server_package_name = undef,
$client_package_name = undef,

$mongod_service_manage = undef,
$service_enable = undef,
$service_ensure = undef,
$service_name = undef,
$service_provider = undef,
$service_status = undef,
$mongod_service_manage = undef,
$service_enable = undef,
$service_ensure = undef,
$service_name = undef,
$service_provider = undef,
$service_status = undef,

$user = undef,
$group = undef,
$ipv6 = undef,
$bind_ip = undef,
$user = undef,
$group = undef,
$ipv6 = undef,
$bind_ip = undef,
Optional[String[1]] $version = undef,
Optional[Boolean] $manage_package_repo = undef,
$manage_package = undef,
$repo_proxy = undef,
$proxy_username = undef,
$proxy_password = undef,

$version = fact('os.distro.codename') ? { # Debian 10 doesn't provide mongodb 3.6.
'buster' => '4.4.8',
default => undef
},
$manage_package_repo = fact('os.distro.codename') ? { # Debian 10 doesn't provide mongodb packages. So manage it!
'buster' => true,
default => undef
},
$manage_package = undef,
$repo_proxy = undef,
$proxy_username = undef,
$proxy_password = undef,
$repo_location = undef,
$use_enterprise_repo = undef,

$repo_location = undef,
$use_enterprise_repo = undef,

$pidfilepath = undef,
$pidfilemode = undef,
$manage_pidfile = undef,
$pidfilepath = undef,
$pidfilemode = undef,
$manage_pidfile = undef,
) {
if $use_enterprise_repo {
$edition = 'enterprise'
Expand All @@ -67,34 +60,27 @@
}

# Setup of the repo only makes sense globally, so we are doing it here.
case $facts['os']['family'] {
'RedHat', 'Linux', 'Suse': {
# For RedHat, Linux and Suse family: if manage_package_repo is set at undef that include mongodb::repo
if $manage_package_repo != false {
class { 'mongodb::repo':
ensure => present,
version => pick($version, '3.6'),
use_enterprise_repo => $use_enterprise_repo,
repo_location => $repo_location,
proxy => $repo_proxy,
}
}
if $manage_package_repo or $manage_package_repo == undef and $facts['os']['family'] in ['RedHat','Linux','Suse'] {
if $use_enterprise_repo == true and $version == undef {
fail('You must set mongodb::globals::version when mongodb::globals::use_enterprise_repo is true')
}

# Set some default working repositories per OS if no version
# specified.
$_repo_version = $version ? {
Undef => $facts['os']['family'] in ['RedHat', 'Linux', 'Suse'] ? {
true => '3.6',
default => $version,
},
default => $version,
}
default: {
# For other (Debian) family: if manage_package_repo is set at undef that not include mongodb::repo
if $manage_package_repo {
if $use_enterprise_repo == true and $version == undef {
fail('You must set mongodb::globals::version when mongodb::globals::use_enterprise_repo is true')
}

class { 'mongodb::repo':
ensure => present,
version => $version,
use_enterprise_repo => $use_enterprise_repo,
repo_location => $repo_location,
proxy => $repo_proxy,
}
}
class { 'mongodb::repo':
ensure => present,
version => $_repo_version,
use_enterprise_repo => $use_enterprise_repo,
repo_location => $repo_location,
proxy => $repo_proxy,
}
}
}
126 changes: 67 additions & 59 deletions spec/defines/db_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,77 +6,85 @@
context 'default' do
let(:title) { 'testdb' }

let(:params) do
{ 'user' => 'testuser',
'password' => 'testpass' }
end
on_supported_os.each do |os, os_facts|
context "on #{os}" do
let(:facts) do
os_facts
end

it 'contains mongodb_database with mongodb::server requirement' do
is_expected.to contain_mongodb_database('testdb')
end
let(:params) do
{ 'user' => 'testuser',
'password' => 'testpass' }
end

it 'contains mongodb_user with mongodb_database requirement' do
is_expected.to contain_mongodb_user('User testuser on db testdb'). \
with_username('testuser'). \
with_database('testdb'). \
that_requires('Mongodb_database[testdb]')
end
it 'contains mongodb_database with mongodb::server requirement' do
is_expected.to contain_mongodb_database('testdb')
end

it 'contains mongodb_user with proper roles' do
params['roles'] = %w[testrole1 testrole2]
is_expected.to contain_mongodb_user('User testuser on db testdb'). \
with_roles(%w[testrole1 testrole2])
end
it 'contains mongodb_user with mongodb_database requirement' do
is_expected.to contain_mongodb_user('User testuser on db testdb'). \
with_username('testuser'). \
with_database('testdb'). \
that_requires('Mongodb_database[testdb]')
end

it 'prefers password_hash instead of password' do
params['password_hash'] = 'securehash'
is_expected.to contain_mongodb_user('User testuser on db testdb'). \
with_password_hash('securehash')
end
it 'contains mongodb_user with proper roles' do
params['roles'] = %w[testrole1 testrole2]
is_expected.to contain_mongodb_user('User testuser on db testdb'). \
with_roles(%w[testrole1 testrole2])
end

it 'contains mongodb_database with proper tries param' do
params['tries'] = 5
is_expected.to contain_mongodb_database('testdb').with_tries(5)
end
end
it 'prefers password_hash instead of password' do
params['password_hash'] = 'securehash'
is_expected.to contain_mongodb_user('User testuser on db testdb'). \
with_password_hash('securehash')
end

context 'with a db_name value' do
let(:title) { 'testdb-title' }
it 'contains mongodb_database with proper tries param' do
params['tries'] = 5
is_expected.to contain_mongodb_database('testdb').with_tries(5)
end
end

let(:params) do
{
'db_name' => 'testdb',
'user' => 'testuser',
'password' => 'testpass'
}
end
context 'with a db_name value' do
let(:title) { 'testdb-title' }

it 'contains mongodb_database with mongodb::server requirement' do
is_expected.to contain_mongodb_database('testdb')
end
let(:params) do
{
'db_name' => 'testdb',
'user' => 'testuser',
'password' => 'testpass'
}
end

it 'contains mongodb_user with mongodb_database requirement' do
is_expected.to contain_mongodb_user('User testuser on db testdb'). \
with_username('testuser'). \
with_database('testdb'). \
that_requires('Mongodb_database[testdb]')
end
it 'contains mongodb_database with mongodb::server requirement' do
is_expected.to contain_mongodb_database('testdb')
end

it 'contains mongodb_user with proper roles' do
params['roles'] = %w[testrole1 testrole2]
is_expected.to contain_mongodb_user('User testuser on db testdb'). \
with_roles(%w[testrole1 testrole2])
end
it 'contains mongodb_user with mongodb_database requirement' do
is_expected.to contain_mongodb_user('User testuser on db testdb'). \
with_username('testuser'). \
with_database('testdb'). \
that_requires('Mongodb_database[testdb]')
end

it 'prefers password_hash instead of password' do
params['password_hash'] = 'securehash'
is_expected.to contain_mongodb_user('User testuser on db testdb'). \
with_password_hash('securehash')
end
it 'contains mongodb_user with proper roles' do
params['roles'] = %w[testrole1 testrole2]
is_expected.to contain_mongodb_user('User testuser on db testdb'). \
with_roles(%w[testrole1 testrole2])
end

it 'prefers password_hash instead of password' do
params['password_hash'] = 'securehash'
is_expected.to contain_mongodb_user('User testuser on db testdb'). \
with_password_hash('securehash')
end

it 'contains mongodb_database with proper tries param' do
params['tries'] = 5
is_expected.to contain_mongodb_database('testdb').with_tries(5)
it 'contains mongodb_database with proper tries param' do
params['tries'] = 5
is_expected.to contain_mongodb_database('testdb').with_tries(5)
end
end
end
end
end

0 comments on commit bc94e0d

Please sign in to comment.