From 625aa83737978a4d86aad971605b1129afd9b792 Mon Sep 17 00:00:00 2001 From: Hugo Haakseth Date: Thu, 21 Mar 2024 13:19:05 +0100 Subject: [PATCH] Move params to classes and hiera; Align defaults with supported versions --- REFERENCE.md | 361 +++++++++++------------------------- data/Debian-family.yaml | 2 + data/Linux-family.yaml | 7 + data/RedHat-family.yaml | 3 + data/Suse-family.yaml | 6 + manifests/client.pp | 6 +- manifests/client/params.pp | 18 -- manifests/globals.pp | 122 +++--------- manifests/mongos.pp | 48 ++--- manifests/mongos/params.pp | 40 ---- manifests/params.pp | 81 -------- manifests/server.pp | 67 +++---- manifests/server/config.pp | 2 - spec/classes/server_spec.rb | 31 +--- templates/mongodb.conf.erb | 6 +- 15 files changed, 224 insertions(+), 576 deletions(-) create mode 100644 data/Linux-family.yaml create mode 100644 data/Suse-family.yaml delete mode 100644 manifests/client/params.pp delete mode 100644 manifests/mongos/params.pp delete mode 100644 manifests/params.pp diff --git a/REFERENCE.md b/REFERENCE.md index 1169a603d..a8eb993bf 100644 --- a/REFERENCE.md +++ b/REFERENCE.md @@ -18,12 +18,9 @@ #### Private Classes -* `mongodb::client::params`: mongodb client params * `mongodb::mongos::config`: Manages mongos config * `mongodb::mongos::install`: Installs mongos -* `mongodb::mongos::params`: mongos params * `mongodb::mongos::service`: Manages the mongos service -* `mongodb::params`: mongodb params * `mongodb::repo`: Manages the mongodb repository * `mongodb::repo::apt`: This is a repo class for apt * `mongodb::repo::yum`: This is a repo class for yum @@ -67,7 +64,7 @@ Data type: `String[1]` Used to ensure that the package is installed, or that the package is absent/purged -Default value: `$mongodb::client::params::package_ensure` +Default value: `pick($mongodb::globals::version, 'present')` ##### `package_name` @@ -76,7 +73,7 @@ Data type: `String[1]` This setting can be used to specify the name of the package that should be installed. If not specified, the module will use whatever service name is the default for your OS distro. -Default value: `$mongodb::client::params::package_name` +Default value: `"mongodb-${mongodb::globals::edition}-shell"` ### `mongodb::globals` @@ -125,146 +122,32 @@ class {'mongodb::globals': The following parameters are available in the `mongodb::globals` class: -* [`server_package_name`](#-mongodb--globals--server_package_name) -* [`client_package_name`](#-mongodb--globals--client_package_name) -* [`mongod_service_manage`](#-mongodb--globals--mongod_service_manage) -* [`service_enable`](#-mongodb--globals--service_enable) -* [`service_ensure`](#-mongodb--globals--service_ensure) -* [`service_name`](#-mongodb--globals--service_name) -* [`service_provider`](#-mongodb--globals--service_provider) -* [`service_status`](#-mongodb--globals--service_status) -* [`user`](#-mongodb--globals--user) -* [`group`](#-mongodb--globals--group) -* [`ipv6`](#-mongodb--globals--ipv6) -* [`bind_ip`](#-mongodb--globals--bind_ip) * [`version`](#-mongodb--globals--version) -* [`repo_version`](#-mongodb--globals--repo_version) * [`manage_package_repo`](#-mongodb--globals--manage_package_repo) -* [`manage_package`](#-mongodb--globals--manage_package) +* [`repo_version`](#-mongodb--globals--repo_version) +* [`use_enterprise_repo`](#-mongodb--globals--use_enterprise_repo) +* [`repo_location`](#-mongodb--globals--repo_location) * [`repo_proxy`](#-mongodb--globals--repo_proxy) * [`proxy_username`](#-mongodb--globals--proxy_username) * [`proxy_password`](#-mongodb--globals--proxy_password) -* [`repo_location`](#-mongodb--globals--repo_location) -* [`use_enterprise_repo`](#-mongodb--globals--use_enterprise_repo) -* [`pidfilepath`](#-mongodb--globals--pidfilepath) -* [`pidfilemode`](#-mongodb--globals--pidfilemode) -* [`manage_pidfile`](#-mongodb--globals--manage_pidfile) - -##### `server_package_name` - -Data type: `Any` - -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. - -Default value: `undef` - -##### `client_package_name` - -Data type: `Any` - -This setting can be used to specify the name of the client package that should be installed. -If not specified, the module will use whatever service name is the default for your OS distro. - -Default value: `undef` - -##### `mongod_service_manage` - -Data type: `Any` - -This setting can be used to override the default management of the mongod service. -By default the module will manage the mongod process. - -Default value: `undef` - -##### `service_enable` - -Data type: `Any` - -This setting can be used to specify if the service should be enable at boot - -Default value: `undef` - -##### `service_ensure` - -Data type: `Any` - -This setting can be used to specify if the service should be running - -Default value: `undef` - -##### `service_name` - -Data type: `Any` - -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. - -Default value: `undef` - -##### `service_provider` - -Data type: `Any` - -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. - -Default value: `undef` +* [`aptkey_options`](#-mongodb--globals--aptkey_options) -##### `service_status` - -Data type: `Any` - -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. - -Default value: `undef` - -##### `user` - -Data type: `Any` - -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. - -Default value: `undef` - -##### `group` - -Data type: `Any` - -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. - -Default value: `undef` - -##### `ipv6` - -Data type: `Any` - -This setting is used to configure MongoDB to turn on ipv6 support. -If not specified and ipv6 address is passed to MongoDB bind_ip it will just fail. - -Default value: `undef` +##### `version` -##### `bind_ip` +Data type: `Optional[String[1]]` -Data type: `Any` - -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. +The version of MonogDB to install/manage. +If not specified, the module will ensure packages with `present`. Default value: `undef` -##### `version` +##### `manage_package_repo` -Data type: `Optional[String[1]]` +Data type: `Boolean` -The version of MonogDB to install/manage. This is needed when managing repositories. -If not specified, the module will use the default for your OS distro. +Whether to manage MongoDB software repository. -Default value: `undef` +Default value: `true` ##### `repo_version` @@ -274,25 +157,27 @@ The version of the package repo. Default value: `'5.0'` -##### `manage_package_repo` +##### `use_enterprise_repo` Data type: `Boolean` -Whether to use the MongoDB software repository or the OS packages (True) or a Custom repo (False) +When manage_package_repo is set to true, this setting indicates if it will use the Community Edition +(false, the default) or the Enterprise one (true). -Default value: `true` +Default value: `false` -##### `manage_package` +##### `repo_location` -Data type: `Any` +Data type: `Optional[String]` -wgether this module willm manage the mongoDB server package +This setting can be used to override the default MongoDB repository location. +If not specified, the module will use the default repository for your OS distro. Default value: `undef` ##### `repo_proxy` -Data type: `Any` +Data type: `Optional[String]` This will allow you to set a proxy for your repository in case you are behind a corporate firewall. Currently this is only supported with yum repositories @@ -301,7 +186,7 @@ Default value: `undef` ##### `proxy_username` -Data type: `Any` +Data type: `Optional[String]` This sets the username for the proxyserver, should authentication be required. @@ -309,52 +194,17 @@ Default value: `undef` ##### `proxy_password` -Data type: `Any` +Data type: `Optional[String]` This sets the password for the proxyserver, should authentication be required Default value: `undef` -##### `repo_location` - -Data type: `Any` - -This setting can be used to override the default MongoDB repository location. -If not specified, the module will use the default repository for your OS distro. - -Default value: `undef` - -##### `use_enterprise_repo` +##### `aptkey_options` -Data type: `Any` - -When manage_package_repo is set to true, this setting indicates if it will use the Community Edition -(false, the default) or the Enterprise one (true). - -Default value: `undef` - -##### `pidfilepath` - -Data type: `Any` - -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. - -Default value: `undef` - -##### `pidfilemode` - -Data type: `Any` - -The file mode of the pid file - -Default value: `undef` - -##### `manage_pidfile` - -Data type: `Any` +Data type: `Optional[String[1]]` -If true, the pidfile will be managed by puppet +Options for debian aptkey Default value: `undef` @@ -408,7 +258,7 @@ Data type: `Stdlib::Absolutepath` Path of the config file. If not specified, the module will use the default for your OS distro. -Default value: `$mongodb::mongos::params::config` +Default value: `'/etc/mongos.conf'` ##### `config_content` @@ -416,7 +266,7 @@ Data type: `Optional[String[1]]` Config content if the default doesn't match one needs. -Default value: `$mongodb::mongos::params::config_content` +Default value: `undef` ##### `config_template` @@ -424,7 +274,7 @@ Data type: `Optional[String[1]]` Path to the config template if the default doesn't match one needs. -Default value: `$mongodb::mongos::params::config_template` +Default value: `undef` ##### `configdb` @@ -432,7 +282,7 @@ Data type: `Variant[String[1], Array[String[1]]]` Array of the config servers IP addresses the mongos should connect to. -Default value: `$mongodb::mongos::params::configdb` +Default value: `'127.0.0.1:27019'` ##### `config_data` @@ -440,7 +290,7 @@ Data type: `Optional[Hash]` Hash containing key-value pairs to allow for additional configuration options to be set in user-provided template. -Default value: `$mongodb::mongos::params::config_data` +Default value: `undef` ##### `service_manage` @@ -448,7 +298,7 @@ Data type: `Boolean` Whether or not the MongoDB sharding service resource should be part of the catalog. -Default value: `$mongodb::mongos::params::service_manage` +Default value: `true` ##### `service_provider` @@ -457,20 +307,20 @@ Data type: `Optional[String]` This setting can be used to override the default Mongos service provider. If not specified, the module will use whatever service provider is the default for your OS distro. -Default value: `$mongodb::mongos::params::service_provider` +Default value: `undef` ##### `service_name` -Data type: `Optional[String]` +Data type: `String[1]` This setting can be used to override the default Mongos service name. If not specified, the module will use whatever service name is the default for your OS distro. -Default value: `$mongodb::mongos::params::service_name` +Default value: `'mongos'` ##### `service_user` -Data type: `String` +Data type: `String[1]` The user used by Systemd for running the service. @@ -478,7 +328,7 @@ Default value: `'mongodb'` ##### `service_group` -Data type: `String` +Data type: `String[1]` The group used by Systemd for running the service @@ -486,11 +336,11 @@ Default value: `'mongodb'` ##### `service_template` -Data type: `Optional[String[1]]` +Data type: `String[1]` Path to the service template if the default doesn't match one needs. -Default value: `$mongodb::mongos::params::service_template` +Default value: `'mongodb/mongos/mongos.service-dropin.epp'` ##### `service_enable` @@ -498,7 +348,7 @@ Data type: `Boolean` This setting can be used to specify if the service should be enable at boot -Default value: `$mongodb::mongos::params::service_enable` +Default value: `true` ##### `service_ensure` @@ -506,7 +356,7 @@ Data type: `Stdlib::Ensure::Service` This setting can be used to specify if the service should be running -Default value: `$mongodb::mongos::params::service_ensure` +Default value: `'running'` ##### `service_status` @@ -515,15 +365,15 @@ Data type: `Optional[String]` This setting can be used to override the default status check command for your Mongos service. If not specified, the module will use whatever service name is the default for your OS distro. -Default value: `$mongodb::mongos::params::service_status` +Default value: `undef` ##### `package_ensure` -Data type: `Variant[Boolean, String]` +Data type: `String[1]` This setting can be used to specify if puppet should install the package or not -Default value: `$mongodb::mongos::params::package_ensure` +Default value: `pick($mongodb::globals::version, 'present')` ##### `package_name` @@ -532,41 +382,41 @@ Data type: `String` This setting can be used to specify the name of the package that should be installed. If not specified, the module will use whatever service name is the default for your OS distro. -Default value: `$mongodb::mongos::params::package_name` +Default value: `"mongodb-${mongodb::globals::edition}-mongos"` ##### `unixsocketprefix` -Data type: `Optional[Stdlib::Absolutepath]` +Data type: `Stdlib::Absolutepath` The path for the UNIX socket. If this option has no value, the mongos process creates a socket with /tmp as a prefix. -Default value: `$mongodb::mongos::params::unixsocketprefix` +Default value: `'/var/run/mongodb'` ##### `pidfilepath` -Data type: `Optional[Stdlib::Absolutepath]` +Data type: `Stdlib::Absolutepath` 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. -Default value: `$mongodb::mongos::params::pidfilepath` +Default value: `'/var/run/mongodb/mongos.pid'` ##### `logpath` -Data type: `Optional[Variant[Boolean, Stdlib::Absolutepath]]` +Data type: `Variant[Boolean, Stdlib::Absolutepath]` 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. -Default value: `$mongodb::mongos::params::logpath` +Default value: `'/var/log/mongodb/mongos.log'` ##### `fork` -Data type: `Optional[Boolean]` +Data type: `Boolean` Set to true to fork server process at launch time. The default setting depends on the operating system. -Default value: `$mongodb::mongos::params::fork` +Default value: `true` ##### `bind_ip` @@ -575,7 +425,7 @@ Data type: `Optional[Array[Stdlib::IP::Address]]` 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. -Default value: `$mongodb::mongos::params::bind_ip` +Default value: `undef` ##### `port` @@ -583,7 +433,7 @@ Data type: `Optional[Stdlib::Port]` Specifies a TCP port for the server instance to listen for client connections. -Default value: `$mongodb::mongos::params::port` +Default value: `undef` ##### `restart` @@ -591,7 +441,7 @@ Data type: `Boolean` Specifies whether the service should be restarted on config changes. -Default value: `$mongodb::mongos::params::restart` +Default value: `true` ### `mongodb::opsmanager` @@ -1021,30 +871,30 @@ The following parameters are available in the `mongodb::server` class: ##### `ensure` -Data type: `Variant[Boolean, String]` +Data type: `String[1]` Used to ensure that the package is installed and the service is running, or that the package is absent/purged and the service is stopped. -Default value: `$mongodb::params::ensure` +Default value: `'present'` ##### `user` -Data type: `String` +Data type: `String[1]` 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. -Default value: `$mongodb::params::user` +Default value: `'mongod'` ##### `group` -Data type: `String` +Data type: `String[1]` 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. -Default value: `$mongodb::params::group` +Default value: `'mongod'` ##### `config` @@ -1052,7 +902,7 @@ Data type: `Stdlib::Absolutepath` Path of the config file. If not specified, the module will use the default for your OS distro. -Default value: `$mongodb::params::config` +Default value: `'/etc/mongod.conf'` ##### `dbpath` @@ -1061,7 +911,7 @@ Data type: `Stdlib::Absolutepath` 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. -Default value: `$mongodb::params::dbpath` +Default value: `'/var/lib/mongodb'` ##### `dbpath_fix` @@ -1071,15 +921,15 @@ Set this value to true if you want puppet to recursively manage the permissions directory. If you are using the default dbpath, this should probably be false. Set this to true if you are using a custom dbpath. -Default value: `$mongodb::params::dbpath_fix` +Default value: `false` ##### `pidfilemode` -Data type: `String` +Data type: `String[4,4]` The file mode of the pidfilepath -Default value: `$mongodb::params::pidfilemode` +Default value: `'0644'` ##### `pidfilepath` @@ -1088,7 +938,7 @@ Data type: `Optional[Stdlib::Absolutepath]` 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. -Default value: `$mongodb::params::pidfilepath` +Default value: `undef` ##### `manage_pidfile` @@ -1096,7 +946,7 @@ Data type: `Boolean` Should puppet create the pidfile. Mongod 6.2.10 will not start if pidfile exists -Default value: `$mongodb::params::manage_pidfile` +Default value: `false` ##### `rcfile` @@ -1104,7 +954,7 @@ Data type: `String` The path to the custom mongosh rc file. -Default value: `$mongodb::params::rcfile` +Default value: `"${facts['root_home']}/.mongorc.js"` ##### `service_manage` @@ -1112,31 +962,31 @@ Data type: `Boolean` Whether or not the MongoDB service resource should be part of the catalog. -Default value: `$mongodb::params::service_manage` +Default value: `true` ##### `service_manage` Whether or not the MongoDB sharding service resource should be part of the catalog. -Default value: `$mongodb::params::service_manage` +Default value: `true` ##### `service_name` -Data type: `Optional[String]` +Data type: `String[1]` This setting can be used to override the default Mongos service name. If not specified, the module will use whatever service name is the default for your OS distro. -Default value: `$mongodb::params::service_name` +Default value: `'mongod'` ##### `service_provider` -Data type: `Optional[String]` +Data type: `Optional[String[1]]` This setting can be used to override the default Mongos service provider. If not specified, the module will use whatever service provider is the default for your OS distro. -Default value: `$mongodb::params::service_provider` +Default value: `undef` ##### `service_status` @@ -1145,7 +995,7 @@ Data type: `Optional[Enum['stopped', 'running']]` This setting can be used to override the default status check command for your Mongos service. If not specified, the module will use whatever service name is the default for your OS distro. -Default value: `$mongodb::params::service_status` +Default value: `undef` ##### `service_enable` @@ -1153,7 +1003,7 @@ Data type: `Boolean` This setting can be used to specify if the service should be enable at boot. -Default value: `$mongodb::params::service_enable` +Default value: `true` ##### `service_ensure` @@ -1161,33 +1011,33 @@ Data type: `Enum['stopped', 'running']` -Default value: `$mongodb::params::service_ensure` +Default value: `'running'` ##### `package_ensure` -Data type: `Variant[Boolean, String]` +Data type: `String[1]` This setting can be used to specify if puppet should install the package or not. -Default value: `$mongodb::params::package_ensure` +Default value: `pick($mongodb::globals::version, 'present')` ##### `package_name` -Data type: `String` +Data type: `String[1]` This setting can be used to specify the name of the package that should be installed. If not specified, the module will use whatever service name is the default for your OS distro. -Default value: `$mongodb::params::server_package_name` +Default value: `"mongodb-${mongodb::globals::edition}-server"` ##### `logpath` -Data type: `Variant[Boolean, Stdlib::Absolutepath]` +Data type: `Stdlib::Absolutepath` 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. -Default value: `$mongodb::params::logpath` +Default value: `'/var/log/mongodb/mongod.log'` ##### `bind_ip` @@ -1196,7 +1046,7 @@ Data type: `Array[Stdlib::IP::Address]` 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. -Default value: `$mongodb::params::bind_ip` +Default value: `['127.0.0.1']` ##### `ipv6` @@ -1227,11 +1077,11 @@ Default value: `undef` ##### `fork` -Data type: `Optional[Boolean]` +Data type: `Boolean` Set to true to fork server process at launch time. The default setting depends on the operating system. -Default value: `$mongodb::params::fork` +Default value: `false` ##### `port` @@ -1247,7 +1097,7 @@ Data type: `Optional[Boolean]` Set to true to enable operation journaling to ensure write durability and data consistency. -Default value: `$mongodb::params::journal` +Default value: `undef` ##### `nojournal` @@ -1559,12 +1409,11 @@ Default value: `undef` ##### `syslog` -Data type: `Optional[Boolean]` +Data type: `Boolean` Sends all logging output to the host’s syslog system rather than to standard output or a log file. -Important: You cannot use syslog with logpath. Set logpath to false to disable it. -Default value: `undef` +Default value: `false` ##### `config_content` @@ -1702,7 +1551,7 @@ Data type: `Boolean` Specifies whether the service should be restarted on config changes. -Default value: `$mongodb::params::restart` +Default value: `true` ##### `storage_engine` @@ -1719,7 +1568,7 @@ Data type: `Boolean` Allows to create admin user for admin database. -Default value: `$mongodb::params::create_admin` +Default value: `false` ##### `admin_username` @@ -1727,7 +1576,7 @@ Data type: `String` Administrator user name -Default value: `$mongodb::params::admin_username` +Default value: `'admin'` ##### `admin_password` @@ -1743,7 +1592,7 @@ Data type: `Enum['scram_sha_1', 'scram_sha_256']` Administrator authentication mechanism. scram_sha_256 password synchronization verification is not supported. -Default value: `$mongodb::params::admin_auth_mechanism` +Default value: `'scram_sha_1'` ##### `admin_update_password` @@ -1755,11 +1604,19 @@ Default value: `false` ##### `admin_roles` -Data type: `Array` +Data type: `Array[String[1]]` Administrator user roles -Default value: `$mongodb::params::admin_roles` +Default value: + +```puppet +[ + 'userAdmin', 'readWrite', 'dbAdmin', 'dbAdminAnyDatabase', 'readAnyDatabase', + 'readWriteAnyDatabase', 'userAdminAnyDatabase', 'clusterAdmin', + 'clusterManager', 'clusterMonitor', 'hostManager', 'root', 'restore', + ] +``` ##### `handle_creds` @@ -1768,7 +1625,7 @@ Data type: `Boolean` Set this to false to avoid having puppet handle .mongoshrc.js in case you wish to deliver it by other means. This is needed for facts and providers to work if you have auth set to true. -Default value: `$mongodb::params::handle_creds` +Default value: `true` ##### `store_creds` @@ -1776,7 +1633,7 @@ Data type: `Boolean` Store admin credentials in mongoshrc.js file. Uses with create_admin parameter -Default value: `$mongodb::params::store_creds` +Default value: `false` ### `mongodb::shardsvr` diff --git a/data/Debian-family.yaml b/data/Debian-family.yaml index 193d155ea..6893e342d 100644 --- a/data/Debian-family.yaml +++ b/data/Debian-family.yaml @@ -1,3 +1,5 @@ --- +mongodb::server::user: 'mongodb' +mongodb::server::group: 'mongodb' mongodb::mongos::service_user: 'mongodb' mongodb::mongos::service_group: 'mongodb' diff --git a/data/Linux-family.yaml b/data/Linux-family.yaml new file mode 100644 index 000000000..85ba439e8 --- /dev/null +++ b/data/Linux-family.yaml @@ -0,0 +1,7 @@ +--- +# Amazon uses os family Linux +mongodb::server::user: 'mongod' +mongodb::server::group: 'mongod' +mongodb::server::journal: true +mongodb::mongos::service_user: 'mongod' +mongodb::mongos::service_group: 'mongod' diff --git a/data/RedHat-family.yaml b/data/RedHat-family.yaml index 22614910a..3bf234f18 100644 --- a/data/RedHat-family.yaml +++ b/data/RedHat-family.yaml @@ -1,3 +1,6 @@ --- +mongodb::server::user: 'mongod' +mongodb::server::group: 'mongod' +mongodb::server::journal: true mongodb::mongos::service_user: 'mongod' mongodb::mongos::service_group: 'mongod' diff --git a/data/Suse-family.yaml b/data/Suse-family.yaml new file mode 100644 index 000000000..3bf234f18 --- /dev/null +++ b/data/Suse-family.yaml @@ -0,0 +1,6 @@ +--- +mongodb::server::user: 'mongod' +mongodb::server::group: 'mongod' +mongodb::server::journal: true +mongodb::mongos::service_user: 'mongod' +mongodb::mongos::service_group: 'mongod' diff --git a/manifests/client.pp b/manifests/client.pp index 29b7d0a16..a1160769c 100644 --- a/manifests/client.pp +++ b/manifests/client.pp @@ -11,9 +11,9 @@ # If not specified, the module will use whatever service name is the default for your OS distro. # class mongodb::client ( - String[1] $ensure = $mongodb::client::params::package_ensure, - String[1] $package_name = $mongodb::client::params::package_name, -) inherits mongodb::client::params { + String[1] $ensure = pick($mongodb::globals::version, 'present'), + String[1] $package_name = "mongodb-${mongodb::globals::edition}-shell", +) inherits mongodb::globals { package { 'mongodb_client': ensure => $ensure, name => $package_name, diff --git a/manifests/client/params.pp b/manifests/client/params.pp deleted file mode 100644 index 554345997..000000000 --- a/manifests/client/params.pp +++ /dev/null @@ -1,18 +0,0 @@ -# @summary mongodb client params -# -# @api private -# -class mongodb::client::params inherits mongodb::globals { - $package_ensure = pick($mongodb::globals::version, 'present') - $manage_package = pick($mongodb::globals::manage_package, $mongodb::globals::manage_package_repo, false) - - if $manage_package { - $package_name = "mongodb-${mongodb::globals::edition}-shell" - } else { - $package_name = $facts['os']['family'] ? { - 'Debian' => 'mongodb-clients', - 'Redhat' => "mongodb-${mongodb::globals::edition}-shell", - default => 'mongodb', - } - } -} diff --git a/manifests/globals.pp b/manifests/globals.pp index 6e32eb432..c482ddf3d 100644 --- a/manifests/globals.pp +++ b/manifests/globals.pp @@ -28,64 +28,23 @@ # -> class {'mongodb::server': } # -> class {'mongodb::client': } # -# @param 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. -# -# @param client_package_name -# This setting can be used to specify the name of the client package that should be installed. -# If not specified, the module will use whatever service name is the default for your OS distro. -# -# @param mongod_service_manage -# This setting can be used to override the default management of the mongod service. -# By default the module will manage the mongod process. -# @param service_enable -# This setting can be used to specify if the service should be enable at boot -# -# @param service_ensure -# This setting can be used to specify if the service should be running -# -# @param 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. -# -# @param 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. -# -# @param 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. -# -# @param 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. -# -# @param 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. -# -# @param ipv6 -# This setting is used to configure MongoDB to turn on ipv6 support. -# If not specified and ipv6 address is passed to MongoDB bind_ip it will just fail. -# -# @param 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. -# # @param version -# The version of MonogDB to install/manage. This is needed when managing repositories. -# If not specified, the module will use the default for your OS distro. +# The version of MonogDB to install/manage. +# If not specified, the module will ensure packages with `present`. +# +# @param manage_package_repo +# Whether to manage MongoDB software repository. # # @param repo_version # The version of the package repo. # -# @param manage_package_repo -# Whether to use the MongoDB software repository or the OS packages (True) or a Custom repo (False) +# @param use_enterprise_repo +# When manage_package_repo is set to true, this setting indicates if it will use the Community Edition +# (false, the default) or the Enterprise one (true). # -# @param manage_package -# wgether this module willm manage the mongoDB server package +# @param repo_location +# This setting can be used to override the default MongoDB repository location. +# If not specified, the module will use the default repository for your OS distro. # # @param repo_proxy # This will allow you to set a proxy for your repository in case you are behind a corporate firewall. @@ -97,53 +56,19 @@ # @param proxy_password # This sets the password for the proxyserver, should authentication be required # -# @param repo_location -# This setting can be used to override the default MongoDB repository location. -# If not specified, the module will use the default repository for your OS distro. -# -# @param use_enterprise_repo -# When manage_package_repo is set to true, this setting indicates if it will use the Community Edition -# (false, the default) or the Enterprise one (true). -# -# @param 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. -# -# @param pidfilemode -# The file mode of the pid file -# -# @param manage_pidfile -# If true, the pidfile will be managed by puppet +# @param aptkey_options +# Options for debian aptkey # class mongodb::globals ( - $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, - - $user = undef, - $group = undef, - $ipv6 = undef, - $bind_ip = undef, - Optional[String[1]] $version = undef, - String[1] $repo_version = '5.0', - Boolean $manage_package_repo = true, - $manage_package = undef, - $repo_proxy = undef, - $proxy_username = undef, - $proxy_password = undef, - - $repo_location = undef, - $use_enterprise_repo = undef, - - $pidfilepath = undef, - $pidfilemode = undef, - $manage_pidfile = undef, + Optional[String[1]] $version = undef, + Boolean $manage_package_repo = true, + String[1] $repo_version = '5.0', + Boolean $use_enterprise_repo = false, + Optional[String] $repo_location = undef, + Optional[String] $repo_proxy = undef, + Optional[String] $proxy_username = undef, + Optional[String] $proxy_password = undef, + Optional[String[1]] $aptkey_options = undef, ) { if $use_enterprise_repo { $edition = 'enterprise' @@ -159,6 +84,9 @@ use_enterprise_repo => $use_enterprise_repo, repo_location => $repo_location, proxy => $repo_proxy, + proxy_username => $proxy_username, + proxy_password => $proxy_password, + aptkey_options => $aptkey_options, } } } diff --git a/manifests/mongos.pp b/manifests/mongos.pp index 1140836be..d9704b70b 100644 --- a/manifests/mongos.pp +++ b/manifests/mongos.pp @@ -85,30 +85,30 @@ # Specifies whether the service should be restarted on config changes. # class mongodb::mongos ( - Stdlib::Absolutepath $config = $mongodb::mongos::params::config, - Optional[String[1]] $config_content = $mongodb::mongos::params::config_content, - Optional[String[1]] $config_template = $mongodb::mongos::params::config_template, - Variant[String[1], Array[String[1]]] $configdb = $mongodb::mongos::params::configdb, - Optional[Hash] $config_data = $mongodb::mongos::params::config_data, - Boolean $service_manage = $mongodb::mongos::params::service_manage, - Optional[String] $service_provider = $mongodb::mongos::params::service_provider, - Optional[String] $service_name = $mongodb::mongos::params::service_name, - String $service_user = 'mongodb', - String $service_group = 'mongodb', - Optional[String[1]] $service_template = $mongodb::mongos::params::service_template, - Boolean $service_enable = $mongodb::mongos::params::service_enable, - Stdlib::Ensure::Service $service_ensure = $mongodb::mongos::params::service_ensure, - Optional[String] $service_status = $mongodb::mongos::params::service_status, - Variant[Boolean, String] $package_ensure = $mongodb::mongos::params::package_ensure, - String $package_name = $mongodb::mongos::params::package_name, - Optional[Stdlib::Absolutepath] $unixsocketprefix = $mongodb::mongos::params::unixsocketprefix, - Optional[Stdlib::Absolutepath] $pidfilepath = $mongodb::mongos::params::pidfilepath, - Optional[Variant[Boolean, Stdlib::Absolutepath]] $logpath = $mongodb::mongos::params::logpath, - Optional[Boolean] $fork = $mongodb::mongos::params::fork, - Optional[Array[Stdlib::IP::Address]] $bind_ip = $mongodb::mongos::params::bind_ip, - Optional[Stdlib::Port] $port = $mongodb::mongos::params::port, - Boolean $restart = $mongodb::mongos::params::restart, -) inherits mongodb::mongos::params { + Stdlib::Absolutepath $config = '/etc/mongos.conf', + Optional[String[1]] $config_content = undef, + Optional[String[1]] $config_template = undef, + Variant[String[1], Array[String[1]]] $configdb = '127.0.0.1:27019', + Optional[Hash] $config_data = undef, + Boolean $service_manage = true, + Optional[String] $service_provider = undef, + String[1] $service_name = 'mongos', + String[1] $service_user = 'mongodb', + String[1] $service_group = 'mongodb', + String[1] $service_template = 'mongodb/mongos/mongos.service-dropin.epp', + Boolean $service_enable = true, + Stdlib::Ensure::Service $service_ensure = 'running', + Optional[String] $service_status = undef, + String[1] $package_ensure = pick($mongodb::globals::version, 'present'), + String $package_name = "mongodb-${mongodb::globals::edition}-mongos", + Stdlib::Absolutepath $unixsocketprefix = '/var/run/mongodb', + Stdlib::Absolutepath $pidfilepath = '/var/run/mongodb/mongos.pid', + Variant[Boolean, Stdlib::Absolutepath] $logpath = '/var/log/mongodb/mongos.log', + Boolean $fork = true, + Optional[Array[Stdlib::IP::Address]] $bind_ip = undef, + Optional[Stdlib::Port] $port = undef, + Boolean $restart = true, +) inherits mongodb::globals { contain mongodb::mongos::install contain mongodb::mongos::config contain mongodb::mongos::service diff --git a/manifests/mongos/params.pp b/manifests/mongos/params.pp deleted file mode 100644 index 078825344..000000000 --- a/manifests/mongos/params.pp +++ /dev/null @@ -1,40 +0,0 @@ -# @summary mongos params -# -# @api private -# -class mongodb::mongos::params inherits mongodb::globals { - $manage_package = pick($mongodb::globals::manage_package, $mongodb::globals::manage_package_repo, false) - - $version = $mongodb::globals::version - - $package_ensure = pick($version, 'present') - if $manage_package { - $package_name = "mongodb-${mongodb::globals::edition}-mongos" - } elsif $facts['os']['family'] in ['RedHat', 'Suse'] { - $package_name = "mongodb-${mongodb::globals::edition}-mongos" - } else { - $package_name = 'mongodb-server' - } - - $config_content = undef - $config_template = undef - - $config_data = undef - $configdb = '127.0.0.1:27019' - $bind_ip = undef - $port = undef - $restart = true - - $service_name = 'mongos' - $service_manage = true - $service_enable = true - $service_ensure = 'running' - $service_status = undef - - $config = '/etc/mongos.conf' - $pidfilepath = '/var/run/mongodb/mongos.pid' - $unixsocketprefix = '/var/run/mongodb' - $logpath = '/var/log/mongodb/mongos.log' - $fork = true - $service_template = 'mongodb/mongos/mongos.service-dropin.epp' -} diff --git a/manifests/params.pp b/manifests/params.pp deleted file mode 100644 index 18aab19b9..000000000 --- a/manifests/params.pp +++ /dev/null @@ -1,81 +0,0 @@ -# @api private -# -# @summary mongodb params -# -class mongodb::params inherits mongodb::globals { - $ensure = true - $dbpath = '/var/lib/mongodb' - $bind_ip = pick($mongodb::globals::bind_ip, ['127.0.0.1']) - $ipv6 = undef - $service_manage = pick($mongodb::globals::mongod_service_manage, true) - $service_enable = pick($mongodb::globals::service_enable, true) - $service_ensure = pick($mongodb::globals::service_ensure, 'running') - $service_status = $mongodb::globals::service_status - $restart = true - $create_admin = false - $admin_username = 'admin' - $admin_auth_mechanism = 'scram_sha_1' - $admin_roles = [ - 'userAdmin', 'readWrite', 'dbAdmin', 'dbAdminAnyDatabase', 'readAnyDatabase', - 'readWriteAnyDatabase', 'userAdminAnyDatabase', 'clusterAdmin', - 'clusterManager', 'clusterMonitor', 'hostManager', 'root', 'restore', - ] - $handle_creds = true - $store_creds = false - $rcfile = "${facts['root_home']}/.mongorc.js" - $dbpath_fix = false - - $manage_package = pick($mongodb::globals::manage_package, $mongodb::globals::manage_package_repo, false) - $pidfilemode = pick($mongodb::globals::pidfilemode, '0644') - $manage_pidfile = pick($mongodb::globals::manage_pidfile, true) - - $version = $mongodb::globals::version - - $config_data = undef - - if $version { - $package_ensure = $version - $package_ensure_mongos = $version - } else { - $package_ensure = true - $package_ensure_mongos = true - } - - # Amazon Linux's OS Family is 'Linux', operating system 'Amazon'. - case $facts['os']['family'] { - 'RedHat', 'Linux', 'Suse': { - $user = pick($mongodb::globals::user, 'mongod') - $group = pick($mongodb::globals::group, 'mongod') - $server_package_name = pick($mongodb::globals::server_package_name, "mongodb-${mongodb::globals::edition}-server") - - $service_name = pick($mongodb::globals::service_name, 'mongod') - $logpath = '/var/log/mongodb/mongod.log' - $pidfilepath = '/var/run/mongodb/mongod.pid' - $config = '/etc/mongod.conf' - $fork = true - $journal = true - } - 'Debian': { - if $manage_package { - $service_name = pick($mongodb::globals::service_name, 'mongod') - $server_package_name = pick($mongodb::globals::server_package_name, "mongodb-${mongodb::globals::edition}-server") - $config = '/etc/mongod.conf' - $pidfilepath = pick($mongodb::globals::pidfilepath, '/var/run/mongod.pid') - } else { - $server_package_name = pick($mongodb::globals::server_package_name, 'mongodb-server') - $service_name = pick($mongodb::globals::service_name, 'mongodb') - $config = '/etc/mongodb.conf' - $pidfilepath = $mongodb::globals::pidfilepath - } - $user = pick($mongodb::globals::user, 'mongodb') - $group = pick($mongodb::globals::group, 'mongodb') - $logpath = '/var/log/mongodb/mongodb.log' - # avoid using fork because of the init scripts design - $fork = undef - $journal = undef - } - default: { - fail("Osfamily ${facts['os']['family']} is not supported") - } - } -} diff --git a/manifests/server.pp b/manifests/server.pp index dc43d150a..aabe3405a 100644 --- a/manifests/server.pp +++ b/manifests/server.pp @@ -236,7 +236,6 @@ # # @param syslog # Sends all logging output to the host’s syslog system rather than to standard output or a log file. -# Important: You cannot use syslog with logpath. Set logpath to false to disable it. # # @param config_content # Config content if the default doesn't match one needs. @@ -320,32 +319,32 @@ # Store admin credentials in mongoshrc.js file. Uses with create_admin parameter # class mongodb::server ( - Variant[Boolean, String] $ensure = $mongodb::params::ensure, - String $user = $mongodb::params::user, - String $group = $mongodb::params::group, - Stdlib::Absolutepath $config = $mongodb::params::config, - Stdlib::Absolutepath $dbpath = $mongodb::params::dbpath, - Boolean $dbpath_fix = $mongodb::params::dbpath_fix, - Optional[Stdlib::Absolutepath] $pidfilepath = $mongodb::params::pidfilepath, - String $pidfilemode = $mongodb::params::pidfilemode, - Boolean $manage_pidfile = $mongodb::params::manage_pidfile, - String $rcfile = $mongodb::params::rcfile, - Boolean $service_manage = $mongodb::params::service_manage, - Optional[String] $service_provider = $mongodb::params::service_provider, - Optional[String] $service_name = $mongodb::params::service_name, - Boolean $service_enable = $mongodb::params::service_enable, - Enum['stopped', 'running'] $service_ensure = $mongodb::params::service_ensure, - Optional[Enum['stopped', 'running']] $service_status = $mongodb::params::service_status, - Variant[Boolean, String] $package_ensure = $mongodb::params::package_ensure, - String $package_name = $mongodb::params::server_package_name, - Variant[Boolean, Stdlib::Absolutepath] $logpath = $mongodb::params::logpath, - Array[Stdlib::IP::Address] $bind_ip = $mongodb::params::bind_ip, + String[1] $ensure = 'present', + String[1] $user = 'mongod', + String[1] $group = 'mongod', + Stdlib::Absolutepath $config = '/etc/mongod.conf', + Stdlib::Absolutepath $dbpath = '/var/lib/mongodb', + Boolean $dbpath_fix = false, + Optional[Stdlib::Absolutepath] $pidfilepath = undef, + String[4,4] $pidfilemode = '0644', + Boolean $manage_pidfile = false, + String $rcfile = "${facts['root_home']}/.mongorc.js", + Boolean $service_manage = true, + Optional[String[1]] $service_provider = undef, + String[1] $service_name = 'mongod', + Boolean $service_enable = true, + Enum['stopped', 'running'] $service_ensure = 'running', + Optional[Enum['stopped', 'running']] $service_status = undef, + String[1] $package_ensure = pick($mongodb::globals::version, 'present'), + String[1] $package_name = "mongodb-${mongodb::globals::edition}-server", + Stdlib::Absolutepath $logpath = '/var/log/mongodb/mongod.log', + Array[Stdlib::IP::Address] $bind_ip = ['127.0.0.1'], Optional[Boolean] $ipv6 = undef, Boolean $logappend = true, Optional[String] $system_logrotate = undef, - Optional[Boolean] $fork = $mongodb::params::fork, + Boolean $fork = false, Optional[Integer[1, 65535]] $port = undef, - Optional[Boolean] $journal = $mongodb::params::journal, + Optional[Boolean] $journal = undef, Optional[Boolean] $nojournal = undef, Optional[Boolean] $smallfiles = undef, Optional[Boolean] $cpu = undef, @@ -381,7 +380,7 @@ Optional[Stdlib::Absolutepath] $keyfile = undef, Optional[Variant[String[6], Sensitive[String[6]]]] $key = undef, Optional[Variant[String[1], Array[String[1]]]] $set_parameter = undef, - Optional[Boolean] $syslog = undef, + Boolean $syslog = false, $config_content = undef, Optional[String] $config_template = undef, Optional[Hash] $config_data = undef, @@ -397,18 +396,22 @@ Boolean $tls_conn_without_cert = false, Boolean $tls_invalid_hostnames = false, Enum['requireTLS', 'preferTLS', 'allowTLS'] $tls_mode = 'requireTLS', - Boolean $restart = $mongodb::params::restart, + Boolean $restart = true, Optional[String] $storage_engine = undef, - Boolean $create_admin = $mongodb::params::create_admin, - String $admin_username = $mongodb::params::admin_username, + Boolean $create_admin = false, + String $admin_username = 'admin', Optional[Variant[String, Sensitive[String]]] $admin_password = undef, Optional[Variant[String[1], Sensitive[String[1]]]] $admin_password_hash = undef, - Enum['scram_sha_1', 'scram_sha_256'] $admin_auth_mechanism = $mongodb::params::admin_auth_mechanism, + Enum['scram_sha_1', 'scram_sha_256'] $admin_auth_mechanism = 'scram_sha_1', Boolean $admin_update_password = false, - Boolean $handle_creds = $mongodb::params::handle_creds, - Boolean $store_creds = $mongodb::params::store_creds, - Array $admin_roles = $mongodb::params::admin_roles, -) inherits mongodb::params { + Boolean $handle_creds = true, + Boolean $store_creds = false, + Array[String[1]] $admin_roles = [ + 'userAdmin', 'readWrite', 'dbAdmin', 'dbAdminAnyDatabase', 'readAnyDatabase', + 'readWriteAnyDatabase', 'userAdminAnyDatabase', 'clusterAdmin', + 'clusterManager', 'clusterMonitor', 'hostManager', 'root', 'restore', + ], +) inherits mongodb::globals { contain mongodb::server::install contain mongodb::server::config contain mongodb::server::service diff --git a/manifests/server/config.pp b/manifests/server/config.pp index 289cefe29..399cb3607 100644 --- a/manifests/server/config.pp +++ b/manifests/server/config.pp @@ -82,8 +82,6 @@ group => $group, } - if ($logpath and $syslog) { fail('You cannot use syslog with logpath') } - if ($ssl and $tls) { fail('You cannot use ssl and tls options together') } if ($ensure == 'present' or $ensure == true) { diff --git a/spec/classes/server_spec.rb b/spec/classes/server_spec.rb index 6318601ac..5567b3ddc 100644 --- a/spec/classes/server_spec.rb +++ b/spec/classes/server_spec.rb @@ -28,11 +28,7 @@ end let(:log_path) do - if facts[:os]['family'] == 'Debian' - '/var/log/mongodb/mongodb.log' - else - '/var/log/mongodb/mongod.log' - end + '/var/log/mongodb/mongod.log' end describe 'with defaults' do @@ -50,24 +46,22 @@ with_content(%r{^systemLog\.path: #{log_path}$}) end - if facts[:os]['family'] == 'Debian' - it { is_expected.not_to contain_file(config_file).with_content(%r{fork}) } - else - it { is_expected.to contain_file(config_file).with_content(%r{^ fork: true$}) } - end + it { is_expected.to contain_class('mongodb::repo') } + it { is_expected.not_to contain_file(config_file).with_content(%r{fork}) } it { is_expected.to contain_file('/root/.mongorc.js').with_ensure('file').without_content(%r{db\.auth}) } it { is_expected.not_to contain_exec('fix dbpath permissions') } end - describe 'with manage_package => true' do + describe 'with manage_package_repo => false' do let(:pre_condition) do 'class { mongodb::globals: - manage_package => true + manage_package_repo => false }' end it_behaves_like 'server classes' + it { is_expected.not_to contain_class('mongodb::repo') } end describe 'with create_admin => true' do @@ -239,23 +233,11 @@ let :params do { syslog: true, - logpath: false } end it { is_expected.to contain_file(config_file).with_content(%r{^systemLog\.destination: syslog$}) } end - - context 'if logpath is also set an error should be raised' do - let :params do - { - syslog: true, - logpath: '/var/log/mongo/mongod.log' - } - end - - it { is_expected.to raise_error(Puppet::Error, %r{You cannot use syslog with logpath}) } - end end describe 'with store_creds' do @@ -293,6 +275,7 @@ describe 'with custom pidfilemode' do let :params do { + manage_pidfile: true, pidfilepath: '/var/run/mongodb/mongod.pid', pidfilemode: '0640' } diff --git a/templates/mongodb.conf.erb b/templates/mongodb.conf.erb index 5c846a254..317ab000a 100644 --- a/templates/mongodb.conf.erb +++ b/templates/mongodb.conf.erb @@ -2,7 +2,9 @@ #System Log -<% if @logpath -%> +<% if @syslog -%> +systemLog.destination: syslog +<% elsif @logpath -%> systemLog.path: <%= @logpath %> systemLog.destination: file <% if @logappend -%> @@ -11,8 +13,6 @@ systemLog.logAppend: <%= @logappend %> <% if @system_logrotate -%> systemLog.logRotate: <%= @system_logrotate %> <% end -%> -<% elsif @syslog -%> -systemLog.destination: syslog <% end -%> <% if @verbose -%> systemLog.quiet: false