Skip to content

Instantly share code, notes, and snippets.

@rockpunk
Created September 17, 2013 17:42
Show Gist options
  • Save rockpunk/6597833 to your computer and use it in GitHub Desktop.
Save rockpunk/6597833 to your computer and use it in GitHub Desktop.
chef_gem 'chef-rewind'
require 'chef/rewind'
include_recipe "postfix::server"
include_recipe "dovecot"
include_recipe "mysql::client"
include_recipe "mi-ssl"
pkgs = []
case node['platform_family']
when 'debian'
pkgs = %w{postfix-mysql libpam-mysql sasl2-bin python-passlib python-mysqldb}
end
pkgs.each {|pkg| package pkg}
rewind "package[postfix]" do
notifies :create, "ruby_block[postfix-uid]", :immediately
end
rewind "package[dovecot-core]" do
notifies :create, "ruby_block[dovecot-uid]", :immediately
end
config = Chef::EncryptedDataBagItem.load('auth','mysql')
template "/etc/pam.d/smtp" do
source 'pam-smtpd.erb'
end
template "/etc/pam-mysql.conf" do
source 'pam-mysql.conf.erb'
variables({:config => config})
end
template "/etc/postfix/mysql_virtual_mailboxes.cf" do
source 'mysql_virtual_mailboxes.cf.erb'
variables({:config => config})
notifies :restart, "service[postfix]"
end
template "/etc/postfix/sasl/smtpd.conf" do
source 'smtpd.conf.erb'
notifies :restart, "service[postfix]"
end
group "sasl" do
action :modify
members 'postfix'
append true
notifies :start, "service[saslauthd]"
end
service "saslauthd" do
supports :status => true, :restart => true
action :enable
end
template "/etc/default/saslauthd" do
source 'default-saslauthd.erb'
end
class Chef::Resource
include Mi::Postfix
end
ruby_block "postfix-uid" do
block do
require 'pp'
assign_uid()
pp node.debug_value('postfix','main')
end
action :create
notifies :create, "template[/etc/postfix/main.cf]", :immediately
end
ruby_block "dovecot-uid" do
block do
assign_uid()
end
action :create
notifies :create, "template[conf.d/auth-system.conf.ext]", :immediately
notifies :create, "template[conf.d/10-mail.conf]", :immediately
end
###### assign_uid looks like:
require 'etc'
module Mi
module Postfix
def assign_uid
begin
user = Etc::getpwnam('postfix')
%w{uid gid}.each do |k|
normal['mi-mailer'][k] = user[k]
normal['postfix']['main']["virtual_#{k}_maps"]="static:#{node['mi-mailer'][k]}"
normal['dovecot']['conf']["first_valid_#{k}"] = node['mi-mailer'][k]
end
normal['dovecot']['auth']['system']['userdb'] = {
'driver' => 'static',
'args' => "uid=#{node['mi-mailer']['uid']} gid=#{node['mi-mailer']['gid']} #{node['mi-mailer']['mail_location']}/%u"
}
rescue
puts "WARNING: postfix uid not set yet. Ignoring..."
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment