Puppet Class: memcached

Inherits:
memcached::params
Defined in:
manifests/init.pp

Overview

Class: memcached

This class installs and manages memcached

Parameters

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

Parameters:

  • package_name (Any) (defaults to: $memcached::params::package_name)
  • package_ensure (Any) (defaults to: 'present')
  • service_name (Any) (defaults to: $memcached::params::service_name)
  • service_ensure (Any) (defaults to: 'running')
  • service_enable (Any) (defaults to: true)
  • config_file_path (Any) (defaults to: $memcached::params::config_file_path)
  • config_file_require (Any) (defaults to: 'Package[memcached]')
  • config_file_notify (Any) (defaults to: 'Service[memcached]')
  • 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_dir_path (Any) (defaults to: $memcached::params::config_dir_path)
  • config_dir_source (Any) (defaults to: undef)
  • config_dir_purge (Any) (defaults to: false)
  • config_dir_recurse (Any) (defaults to: true)
  • conf_hash (Any) (defaults to: undef)
  • dependency_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
# File 'manifests/init.pp', line 12

class memcached (

  $package_name              = $memcached::params::package_name,
  $package_ensure            = 'present',

  $service_name              = $memcached::params::service_name,
  $service_ensure            = 'running',
  $service_enable            = true,

  $config_file_path          = $memcached::params::config_file_path,
  $config_file_require       = 'Package[memcached]',
  $config_file_notify        = 'Service[memcached]',
  $config_file_source        = undef,
  $config_file_template      = undef,
  $config_file_content       = undef,
  $config_file_options_hash  = { } ,

  $config_dir_path           = $memcached::params::config_dir_path,
  $config_dir_source         = undef,
  $config_dir_purge          = false,
  $config_dir_recurse        = true,

  $conf_hash                 = undef,

  $dependency_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,

  ) inherits memcached::params {


  # 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) }

  $config_file_owner          = $memcached::params::config_file_owner
  $config_file_group          = $memcached::params::config_file_group
  $config_file_mode           = $memcached::params::config_file_mode

  $manage_config_file_content = default_content($config_file_content, $config_file_template)

  $manage_config_file_notify  = $config_file_notify ? {
    'class_default' => 'Service[memcached]',
    ''              => 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
    $manage_service_ensure = $service_ensure
    $config_dir_ensure = directory
    $config_file_ensure = present
  }


  # Dependency class

  if $memcached::dependency_class {
    include $memcached::dependency_class
  }


  # Resources managed

  if $memcached::package_name {
    package { 'memcached':
      ensure   => $memcached::package_ensure,
      name     => $memcached::package_name,
    }
  }

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

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

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


  # Extra classes

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

  if $memcached::my_class {
    include $memcached::my_class
  }

  if $memcached::monitor_class {
    class { $memcached::monitor_class:
      options_hash => $memcached::monitor_options_hash,
      scope_hash   => {}, # TODO: Find a good way to inject class' scope
    }
  }

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

}