class heartbeat {

    package { "heartbeat":
        ensure  => installed,
        require => Yumrepo["extras"],
    }

    service { "heartbeat":
        hasstatus  => true,
        hasrestart => true,
    }

}

define heartbeat::hacf (
    $logfacility = 'local0'    $bcast         = 'bond0',,
    $keepalive   = '1',        $auto_failback = 'on',
    $deadtime    = '10',       $hosts,
    $warntime    = '3',        $ping,
    $initdead    = '30',       $crm           = true
){

    file { "/etc/ha.d/ha.cf":
        mode    => 0644,
        content => template("heartbeat/ha.cf.erb"),
        notify  => Service["heartbeat"],
    }

}

define heartbeat::haresources ( $node, $ipaddr, $service = '') {

    file { "/etc/ha.d/haresources":
        mode    => 0644,
        replace => false,
        content => template("heartbeat/haresources.erb"),
    }

    # Run the conversion file to create cib.xml for heartbeat v2.
    # the haresources2cib.py script checks for cib.xml.

    exec { "/usr/lib/heartbeat/haresources2cib.py":
        creates => "/var/lib/heartbeat/crm/cib.xml",
        require => File["/etc/ha.d/haresources"],
    }

}

define heartbeat::authkeys ($signature = 'sha1', $password = 'Hash This!") {

    file { "/etc/ha.d/authkeys":
        mode    => 0600,
        content => template("heartbeat/authkeys.erb"),
        notify  => Service["heartbeat"],
    }

}

##### Templates:
ha.cf.erb:
logfacility     <%= logfacility %>

keepalive       <%= keepalive %>
deadtime        <%= deadtime %>
warntime        <%= warntime %>
initdead        <%= initdead %>

bcast           <%= bcast %>
auto_failback   <%= auto_failback %>

node            <% hosts.each {|h| -%><%= h %> <% } %>
ping            <% ping.each  {|p| -%><%= p %> <% } %>

crm             <%= crm %>

authkeys.erb:
<% require 'digest/md5'-%>auth 1
1 <%= signature %> <% hash = Digest::MD5.hexdigest(password) -%><%= hash %>