]> gitweb.fluxo.info Git - puppet-apcupsd.git/commitdiff
Merge 'ups' define and 'acpupsd' class into a parametrized class
authorGabriel Filion <lelutin@gmail.com>
Sun, 30 Oct 2011 08:20:51 +0000 (04:20 -0400)
committerGabriel Filion <lelutin@gmail.com>
Sun, 30 Oct 2011 08:20:51 +0000 (04:20 -0400)
The 'ups' define was probably created in order to be able to define
multiple upses. However, the implementation doesn't give that as an
opportunity.

Get rid of the useless complexity and mix everything into a parametrized
class named 'apcupsd'.

manifests/init.pp

index f18867314cc8102ce288cf741f6248347f0c5ec7..2035f47a516e81052a327490623b51fec1e70098 100644 (file)
 # You should have received a copy of the GNU Affero General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-class apcupsd {
+class apcupsd(
+  $upstype = 'apcsmart',
+  $cable = 'smart',
+  $device = '/dev/ttyS0',
+  $ensure = 'present',
+  $nisip = '127.0.0.1',
+  $polltime = '60' )
+{
+
   package { "apcupsd":
     ensure => installed,
   }
 
-  define ups($upstype = 'apcsmart', $cable = 'smart', $device = '/dev/ttyS0', $ensure = 'present',
-             $nisip = '127.0.0.1', $polltime = '60') {
-
-    $ups_configured = $ensure ? {
-      'present' => 'yes',
-      'absent'  => 'no',
-    }
+  $ups_configured = $ensure ? {
+    'present' => 'yes',
+    'absent'  => 'no',
+  }
 
-    $ups_state = $ensure ? {
-      'present' => 'running',
-      'absent'  => 'stopped',
-    }
+  $ups_state = $ensure ? {
+    'present' => 'running',
+    'absent'  => 'stopped',
+  }
 
-    file { "/etc/apcupsd":
-      ensure => 'directory',
-      owner  => 'root',
-      group  => 'root',
-      mode   =>  0755,
-    }
+  file { "/etc/apcupsd":
+    ensure => 'directory',
+    owner  => 'root',
+    group  => 'root',
+    mode   =>  0755,
+  }
 
-    file { "/etc/apcupsd/apcupsd.conf":
-      ensure  => present,
-      owner   => root,
-      group   => root,
-      mode    => 0644,
-      notify  => Service["apcupsd"],
-      require => File["/etc/apcupsd"],
-      content => template('apcupsd/apcupsd.conf.erb'),
-    }
+  file { "/etc/apcupsd/apcupsd.conf":
+    ensure  => present,
+    owner   => root,
+    group   => root,
+    mode    => 0644,
+    notify  => Service["apcupsd"],
+    require => File["/etc/apcupsd"],
+    content => template('apcupsd/apcupsd.conf.erb'),
+  }
 
-    file { "/etc/default/apcupsd": 
-      ensure  => present,
-      owner   => root,
-      group   => root,
-      mode    => 0644,
-      notify  => Service["apcupsd"],
-      content => template('apcupsd/default/apcupsd.erb'),
-    }
+  file { "/etc/default/apcupsd":
+    ensure  => present,
+    owner   => root,
+    group   => root,
+    mode    => 0644,
+    notify  => Service["apcupsd"],
+    content => template('apcupsd/default/apcupsd.erb'),
+  }
 
-    service { "apcupsd":
-      enable     => true,
-      ensure     => $ups_state,
-      hasrestart => true,
-      require    => [ File["/etc/apcupsd/apcupsd.conf"], Package["apcupsd"] ],
-    }
+  service { "apcupsd":
+    enable     => true,
+    ensure     => $ups_state,
+    hasrestart => true,
+    require    => [ File["/etc/apcupsd/apcupsd.conf"], Package["apcupsd"] ],
   }
 }