Puppet Class: mongodb

Defined in:
manifests/init.pp

Overview

Class: mongodb

This class installs and manages mongodb

Parameters

Refer to github.com/stdmod for official documentation on the stdmod parameters used

Parameters:

  • server_package_name (Any)
  • server_package_ensure (Any) (defaults to: 'present')
  • client_package_name (Any)
  • client_package_ensure (Any) (defaults to: 'present')
  • service_name (Any)
  • service_ensure (Any) (defaults to: 'running')
  • service_enable (Any) (defaults to: true)
  • config_file_path (Any)
  • config_file_require (Any) (defaults to: 'Package[mongodb_server]')
  • config_file_notify (Any) (defaults to: 'Service[mongodb]')
  • config_file_source (Any) (defaults to: undef)
  • config_file_template (Any) (defaults to: undef)
  • config_file_content (Any) (defaults to: undef)
  • config_file_options_hash (Any) (defaults to: { })
  • config_file_owner (Any)
  • config_file_group (Any)
  • config_file_mode (Any)
  • config_dir_path (Any)
  • config_dir_source (Any) (defaults to: undef)
  • config_dir_purge (Any) (defaults to: false)
  • config_dir_recurse (Any) (defaults to: true)
  • process_user (Any)
  • conf_hash (Any) (defaults to: undef)
  • repo_class (Any) (defaults to: undef)
  • my_class (Any) (defaults to: undef)
  • monitor_class (Any) (defaults to: undef)
  • monitor_options_hash (Any) (defaults to: { })
  • firewall_class (Any) (defaults to: undef)
  • firewall_options_hash (Any) (defaults to: { })
  • scope_hash_filter (Any) (defaults to: '(uptime.*|timestamp)')
  • tcp_port (Any) (defaults to: undef)
  • udp_port (Any) (defaults to: undef)


12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
# File 'manifests/init.pp', line 12

class mongodb (

  $server_package_name,
  $server_package_ensure     = 'present',

  $client_package_name,
  $client_package_ensure     = 'present',

  $service_name,
  $service_ensure            = 'running',
  $service_enable            = true,

  $config_file_path,
  $config_file_require       = 'Package[mongodb_server]',
  $config_file_notify        = 'Service[mongodb]',
  $config_file_source        = undef,
  $config_file_template      = undef,
  $config_file_content       = undef,
  $config_file_options_hash  = { } ,
  $config_file_owner,
  $config_file_group,
  $config_file_mode,

  $config_dir_path,
  $config_dir_source         = undef,
  $config_dir_purge          = false,
  $config_dir_recurse        = true,

  $process_user,

  $conf_hash                 = undef,

  $repo_class                = undef,
  $my_class                  = undef,

  $monitor_class             = undef,
  $monitor_options_hash      = { } ,

  $firewall_class            = undef,
  $firewall_options_hash     = { } ,

  $scope_hash_filter         = '(uptime.*|timestamp)',

  $tcp_port                  = undef,
  $udp_port                  = undef,

  ) {


  # Class variables validation and management

  validate_bool($service_enable)
  validate_bool($config_dir_recurse)
  validate_bool($config_dir_purge)
  if $config_file_options_hash { validate_hash($config_file_options_hash) }
  if $monitor_options_hash { validate_hash($monitor_options_hash) }
  if $firewall_options_hash { validate_hash($firewall_options_hash) }

  $manage_config_file_content = default_content($config_file_content, $config_file_template)

  $manage_config_file_notify  = $config_file_notify ? {
    'class_default' => 'Service[mongodb]',
    ''              => undef,
    default         => $config_file_notify,
  }

  if $package_ensure == 'absent' {
    $manage_service_enable = undef
    $manage_service_ensure = stopped
    $config_dir_ensure = absent
    $config_file_ensure = absent
  } else {
    $manage_service_enable = $service_enable ? {
      ''      => undef,
      'undef' => undef,
      default => $service_enable,
    }
    $manage_service_ensure = $service_ensure ? {
      ''      => undef,
      'undef' => undef,
      default => $service_ensure,
    }
    $config_dir_ensure = directory
    $config_file_ensure = present
  }


  # Dependency class
  anchor { '::mongodb::begin': }
  anchor { '::mongodb::end': }

  if $mongodb::repo_class {
    include $mongodb::repo_class
    Anchor['::mongodb::begin']
    -> Class[$mongodb::repo_class]
    -> Package[$mongodb::server_package_name]
    -> Anchor['::mongodb::end']
  }


  # Resources managed

  if $mongodb::server_package_name {
    package { $mongodb::server_package_name:
      ensure   => $mongodb::server_package_ensure,
      name     => $mongodb::server_package_name,
      alias    => 'mongodb_server',
    }
  }

  if $mongodb::client_package_name {
    package { $mongodb::client_package_name:
      ensure   => $mongodb::client_package_ensure,
      name     => $mongodb::client_package_name,
      alias    => 'mongodb_client',
    }
  }

  if $mongodb::config_file_path {
    file { $mongodb::config_file_path:
      ensure  => $mongodb::config_file_ensure,
      path    => $mongodb::config_file_path,
      mode    => $mongodb::config_file_mode,
      owner   => $mongodb::config_file_owner,
      group   => $mongodb::config_file_group,
      source  => $mongodb::config_file_source,
      content => $mongodb::manage_config_file_content,
      notify  => $mongodb::manage_config_file_notify,
      require => $mongodb::config_file_require,
      alias   => 'mongodb.conf',
    }
  }

  if $mongodb::config_dir_source {
    file { $mongodb::config_dir_path:
      ensure  => $mongodb::config_dir_ensure,
      path    => $mongodb::config_dir_path,
      source  => $mongodb::config_dir_source,
      recurse => $mongodb::config_dir_recurse,
      purge   => $mongodb::config_dir_purge,
      force   => $mongodb::config_dir_purge,
      notify  => $mongodb::manage_config_file_notify,
      require => $mongodb::config_file_require,
      alias   => 'mongodb.dir',
    }
  }

  if $mongodb::service_name {
    service { $mongodb::service_name:
      ensure     => $mongodb::manage_service_ensure,
      name       => $mongodb::service_name,
      enable     => $mongodb::manage_service_enable,
      alias      => 'mongodb',
    }
  }


  # Extra classes

  if $conf_hash {
    create_resources('mongodb::conf', $conf_hash)
  }

  if $mongodb::my_class {
    include $mongodb::my_class
  }

  if $mongodb::monitor_class {
    class { $mongodb::monitor_class:
      options_hash => $mongodb::monitor_options_hash,
      scope_hash   => {},
    }
  }

  if $mongodb::firewall_class {
    class { $mongodb::firewall_class:
      options_hash => $mongodb::firewall_options_hash,
      scope_hash   => {},
    }
  }

}