Skip to content

Instantly share code, notes, and snippets.

@sarguru
Created June 22, 2012 05:08
Show Gist options
  • Save sarguru/2970360 to your computer and use it in GitHub Desktop.
Save sarguru/2970360 to your computer and use it in GitHub Desktop.
the main class
class qmail {
$domain = hiera('domain')
$basedn = hiera('basedn')
$deepofix_password = hiera('deepofix_password')
$cluster = hiera('mail_cluster')
$concurrency = hiera('smtpd_concurrency')
$maxrcpt = hiera('maxrcpt')
$qmail_queue = hiera('qmail_queue')
$smtp_port = hiera('smtp_port')
$soft_limit = hiera('soft_limit')
$softlimit = $soft_limit * 1048576
if ($cluster == 'yes') {
$host_array = hiera_array('cluster_hosts')
}
file {'control-dir':
ensure => directory,
path => '/var/qmail/control',
mode => '0644',
owner => 'root',
group => 'qmail',
recurse => true,
source => 'puppet:///modules/qmail/control'
}
file {'/var/qmail/control/defaultdomain':
ensure => present,
mode => '0644',
owner => 'root',
group => 'qmail',
content => template('qmail/defaultdomain.erb')
}
file {'/var/qmail/control/ldapbasedn':
ensure => present,
mode => '0644',
owner => 'root',
group => 'qmail',
content => template('qmail/ldapbasedn.erb')
}
file {'/var/qmail/control/ldaplogin':
ensure => present,
mode => '0644',
owner => 'root',
group => 'qmail',
content => template('qmail/ldaplogin.erb')
}
file {'/var/qmail/control/ldapmailhost':
ensure => present,
mode => '0644',
owner => 'root',
group => 'qmail',
content => template('qmail/ldapmailhost.erb')
}
file {'/var/qmail/control/locals':
ensure => present,
mode => '0644',
owner => 'root',
group => 'qmail',
content => template('qmail/locals.erb')
}
file {'/var/qmail/control/me':
ensure => present,
mode => '0644',
owner => 'root',
group => 'qmail',
content => template('qmail/me.erb')
}
file {'/var/qmail/control/rcpthosts':
ensure => present,
mode => '0644',
owner => 'root',
group => 'qmail',
content => template('qmail/rcpthosts.erb')
}
file {'/etc/sv/qmail-smtpd/env':
ensure => directory
}
file {'/etc/sv/qmail-smtpd/env/CONCURRENCY':
ensure => present,
mode => '0644',
owner => 'root',
group => 'qmail',
content => inline_template("<%= concurrency %>")
}
file {'/etc/sv/qmail-smtpd/env/MAXRCPTCOUNT':
ensure => present,
mode => '0644',
owner => 'root',
group => 'qmail',
content => inline_template("<%= maxrcpt %>")
}
file {'/etc/sv/qmail-smtpd/env/SMTPPORT':
ensure => present,
mode => '0644',
owner => 'root',
group => 'qmail',
content => inline_template("<%= smtp_port %>")
}
file {'/etc/sv/qmail-smtpd/env/SOFTLIMIT':
ensure => present,
mode => '0644',
owner => 'root',
group => 'qmail',
content => inline_template("<%= softlimit %>")
}
file {'/etc/sv/qmail-smtpd/env/RCPTCHECK':
ensure => present,
mode => '0644',
owner => 'root',
group => 'qmail',
content => 'checked'
}
file {'/etc/sv/qmail-smtpd/env/SENDERCHECK':
ensure => present,
mode => '0644',
owner => 'root',
group => 'qmail',
content => 'checked'
}
file {'/etc/sv/qmail-smtpd/env/SMTPAUTH':
ensure => present,
mode => '0644',
owner => 'root',
group => 'qmail',
content => 'checked'
}
if ($qmail_queue == 'default') {
file {'/etc/sv/qmail-smtpd/env/QMAILQUEUE':
ensure => absent,
}
}
else {
file {'/etc/sv/qmail-smtpd/env/QMAILQUEUE':
ensure => present,
mode => '0644',
owner => 'root',
group => 'qmail',
content => inline_template("<%= qmail_queue %>")
}
}
if ( $cluster == 'yes' ) {
file {'/var/qmail/control/ldapcluster':
ensure => present,
mode => '0644',
owner => 'root',
group => 'qmail',
content => "1"
}
file {'/var/qmail/control/host':
ensure => present,
mode => '0644',
owner => 'root',
group => 'qmail',
content => template('qmail/host.erb')
}
file {'/var/log/qmail/qmqpd':
ensure => 'directory',
owner => 'qmaill'
}
common::sv { 'qmail-qmqpd':
name => 'qmail-qmqpd',
namemod => 'qmail-qmqpd'
}
common::srv {'qmail-qmqpd':
name => 'qmail-qmqpd',
require => [Common::Sv['qmail-qmqpd']],
subscribe => File['/var/qmail/control']
}
}
else {
file {'/var/qmail/control/host':
ensure => absent
}
file {'/var/qmail/control/ldapcluster':
ensure =>absent
}
}
$peer_ret = peer_generator('peers')
if ($peer_ret == 'success') {
file {'/etc/sv/qmail-smtpd/peers':
ensure => 'directory',
owner => 'qmaill'
}
}
common::sv { 'qmail-smtpd':
name => 'qmail-smtpd',
namemod => 'qmail'
}
common::srv {'qmail-smtpd':
name => 'qmail-smtpd',
require => [Common::Sv['qmail-smtpd']],
subscribe => File['/var/qmail/control']
}
}
Puppet::Parser::Functions.newfunction(:peer_generator, :type => :rvalue) do |args|
raise Puppet::Error, "peer_generator requires 1 argument; got #{args.length}" if args.length != 1
peer_ips = function_hiera_array(args[0])
peer_ips.each do |peers|
#str = "+RELAYCLIENT="
#File.open("/etc/sv/qmail-smtpd/peers/#{peers}", 'w') {|fd| fd.puts str}
@rtype = qmail::peer_instances
@rname = peers
myresource = {
@rname => {
name => "@rname"
}
}
function_create_resources(@rtype,myresource)
end
return "success"
end
define qmail::peer_instances ($name) {
file {"/etc/sv/qmail-smtpd/peers/$name":
ensure => present,
owner => 'qmaill',
content => "+RELAYCLIENT="
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment