Refactoring trying to fix some logic issues
This commit is contained in:
parent
5195682a0d
commit
489bfaacbe
@ -23,6 +23,7 @@ default['postfix']['use_procmail'] = false
|
||||
default['postfix']['aliases'] = {}
|
||||
default['postfix']['transports'] = {}
|
||||
default['postfix']['access'] = {}
|
||||
default['postfix']['virtual_aliases'] = {}
|
||||
default['postfix']['main_template_source'] = 'postfix'
|
||||
default['postfix']['master_template_source'] = 'postfix'
|
||||
default['postfix']['sender_canonical_map_entries'] = {}
|
||||
@ -33,21 +34,21 @@ when 'smartos'
|
||||
default['postfix']['conf_dir'] = '/opt/local/etc/postfix'
|
||||
default['postfix']['aliases_db'] = '/opt/local/etc/postfix/aliases'
|
||||
default['postfix']['transport_db'] = '/opt/local/etc/postfix/transport'
|
||||
default['postfix']['access_db'] = '/opt/local/etc/postfix/access'
|
||||
default['postfix']['virtual_alias_db'] = '/opt/local/etc/postfix/virtual'
|
||||
when 'omnios'
|
||||
default['postfix']['conf_dir'] = '/opt/omni/etc/postfix'
|
||||
default['postfix']['aliases_db'] = 'opt/omni/etc/postfix/aliases'
|
||||
default['postfix']['transport_db'] = '/opt/omni/etc/postfix/transport'
|
||||
default['postfix']['access_db'] = '/opt/local/etc/postfix/aliases'
|
||||
when 'omnios'
|
||||
default['postfix']['conf_dir'] = '/opt/omni/etc/postfix'
|
||||
default['postfix']['aliases_db'] = 'opt/omni/etc/postfix/aliases'
|
||||
default['postfix']['access_db'] = 'opt/omni/etc/postfix/aliases'
|
||||
default['postfix']['access_db'] = '/opt/omni/etc/postfix/access'
|
||||
default['postfix']['virtual_alias_db'] = '/etc/omni/etc/postfix/virtual'
|
||||
default['postfix']['uid'] = 11
|
||||
else
|
||||
default['postfix']['conf_dir'] = '/etc/postfix'
|
||||
default['postfix']['aliases_db'] = '/etc/aliases'
|
||||
default['postfix']['transport_db'] = '/etc/postfix/transport'
|
||||
default['postfix']['access_db'] = '/etc/postfix/access'
|
||||
default['postfix']['virtual_alias_db'] = '/etc/postfix/virtual'
|
||||
end
|
||||
|
||||
# Non-default main.cf attributes
|
||||
@ -59,11 +60,12 @@ default['postfix']['main']['myorigin'] = '$myhostname'
|
||||
default['postfix']['main']['mydestination'] = [node['postfix']['main']['myhostname'], node['hostname'], 'localhost.localdomain', 'localhost'].compact
|
||||
default['postfix']['main']['smtpd_use_tls'] = 'yes'
|
||||
default['postfix']['main']['smtp_use_tls'] = 'yes'
|
||||
default['postfix']['main']['alias_maps'] = ["hash:#{node['postfix']['aliases_db']}"]
|
||||
default['postfix']['main']['transport_maps'] = [ "hash:#{node['postfix']['transport_db']}" ]
|
||||
default['postfix']['main']['access_maps'] = ["hash:#{node['postfix']['access_db']}"]
|
||||
default['postfix']['main']['mailbox_size_limit'] = 0
|
||||
default['postfix']['main']['smtp_sasl_auth_enable'] = 'no'
|
||||
default['postfix']['main']['use_alias_maps'] = 'no'
|
||||
default['postfix']['main']['use_transport_maps'] = 'no'
|
||||
default['postfix']['main']['use_access_maps'] = 'no'
|
||||
default['postfix']['main']['use_virtual_aliases'] = 'no'
|
||||
default['postfix']['main']['mailbox_size_limit'] = 0
|
||||
default['postfix']['main']['mynetworks'] = nil
|
||||
default['postfix']['main']['inet_interfaces'] = 'loopback-only'
|
||||
|
||||
@ -104,16 +106,20 @@ if node['postfix']['main']['smtp_sasl_auth_enable'] == 'yes'
|
||||
default['postfix']['main']['relayhost'] = ''
|
||||
end
|
||||
|
||||
if node['postfix']['use_virtual_aliases'] == 'yes'
|
||||
default['postfix']['main']['virtual_alias_domains'] = []
|
||||
case node['platform']
|
||||
when 'smartos'
|
||||
default['postfix']['virtual_alias_db'] = '/opt/local/etc/postfix/virtual'
|
||||
else
|
||||
default['postfix']['virtual_alias_db'] = '/etc/postfix/virtual'
|
||||
end
|
||||
default['postfix']['main']['virtual_alias_maps'] = "hash:#{node['postfix']['virtual_alias_db']}"
|
||||
default['postfix']['virtual_aliases'] = {}
|
||||
if node['postfix']['main']['use_alias_maps'] == 'yes'
|
||||
default['postfix']['main']['alias_maps'] = ["hash:#{node['postfix']['aliases_db']}"]
|
||||
end
|
||||
|
||||
if node['postfix']['main']['use_transport_maps'] == 'yes'
|
||||
default['postfix']['main']['transport_maps'] = ["hash:#{node['postfix']['transport_db']}"]
|
||||
end
|
||||
|
||||
if node['postfix']['main']['use_access_maps'] == 'yes'
|
||||
default['postfix']['main']['access_maps'] = ["hash:#{node['postfix']['access_db']}"]
|
||||
end
|
||||
|
||||
if node['postfix']['main']['use_virtual_aliases'] == 'yes'
|
||||
default['postfix']['main']['virtual_alias_maps'] = ["hash:#{node['postfix']['virtual_alias_db']}"]
|
||||
end
|
||||
|
||||
# # Default main.cf attributes according to `postconf -d`
|
||||
|
@ -10,6 +10,7 @@ recipe 'postfix::sasl_auth', 'Set up postfix to auth to a server with sasl'
|
||||
recipe 'postfix::aliases', 'Manages /etc/aliases'
|
||||
recipe 'postfix::transports', 'Manages /etc/postfix/transport'
|
||||
recipe 'postfix::access', 'Manages /etc/postfix/access'
|
||||
recipe 'postfix::virtual_aliases', 'Manages /etc/postfix/virtual'
|
||||
recipe 'postfix::client', 'Searches for the relayhost based on an attribute'
|
||||
recipe 'postfix::server', 'Sets the mail_type attribute to master'
|
||||
|
||||
|
126
recipes/_common.rb
Normal file
126
recipes/_common.rb
Normal file
@ -0,0 +1,126 @@
|
||||
# encoding: utf-8
|
||||
# Author:: Joshua Timberman(<joshua@getchef.com>)
|
||||
# Cookbook Name:: common
|
||||
# Recipe:: default
|
||||
#
|
||||
# Copyright 2009-2014, Chef Software, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
package 'postfix'
|
||||
|
||||
package 'procmail' if node['postfix']['use_procmail']
|
||||
|
||||
case node['platform_family']
|
||||
when 'rhel', 'fedora'
|
||||
service 'sendmail' do
|
||||
action :nothing
|
||||
end
|
||||
|
||||
execute 'switch_mailer_to_postfix' do
|
||||
command '/usr/sbin/alternatives --set mta /usr/sbin/sendmail.postfix'
|
||||
notifies :stop, 'service[sendmail]'
|
||||
notifies :start, 'service[postfix]'
|
||||
not_if '/usr/bin/test /etc/alternatives/mta -ef /usr/sbin/sendmail.postfix'
|
||||
end
|
||||
when 'omnios'
|
||||
manifest_path = ::File.join(Chef::Config[:file_cache_path], 'manifest-postfix.xml')
|
||||
|
||||
# we need to manage the postfix group and user
|
||||
# and then subscribe to the package install because it creates a
|
||||
# postdrop group and adds postfix user to it.
|
||||
group 'postfix' do
|
||||
append true
|
||||
end
|
||||
|
||||
user 'postfix' do
|
||||
uid node['postfix']['uid']
|
||||
gid 'postfix'
|
||||
home '/var/spool/postfix'
|
||||
subscribes :manage, 'package[postfix]'
|
||||
notifies :run, 'execute[/opt/omni/sbin/postfix set-permissions]', :immediately
|
||||
end
|
||||
|
||||
# we don't guard this because if the user creation was successful (or happened out of band), then this won't get executed when the action is :nothing.
|
||||
execute '/opt/omni/sbin/postfix set-permissions'
|
||||
|
||||
template manifest_path do
|
||||
source 'manifest-postfix.xml.erb'
|
||||
owner 'root'
|
||||
group 'root'
|
||||
mode '0644'
|
||||
notifies :run, 'execute[load postfix manifest]', :immediately
|
||||
end
|
||||
|
||||
execute 'load postfix manifest' do
|
||||
action :nothing
|
||||
command "svccfg import #{manifest_path}"
|
||||
notifies :restart, 'service[postfix]'
|
||||
end
|
||||
end
|
||||
|
||||
execute 'update-postfix-sender_canonical' do
|
||||
command "postmap #{node['postfix']['conf_dir']}/sender_canonical"
|
||||
action :nothing
|
||||
end
|
||||
|
||||
unless node['postfix']['sender_canonical_map_entries'].empty?
|
||||
template "#{node['postfix']['conf_dir']}/sender_canonical" do
|
||||
owner 'root'
|
||||
group 0
|
||||
mode '0644'
|
||||
notifies :run, 'execute[update-postfix-sender_canonical]'
|
||||
notifies :reload, 'service[postfix]'
|
||||
end
|
||||
|
||||
unless node['postfix']['main'].key?('sender_canonical_maps')
|
||||
node.set['postfix']['main']['sender_canonical_maps'] = "hash:#{node['postfix']['conf_dir']}/sender_canonical"
|
||||
end
|
||||
end
|
||||
|
||||
execute 'update-postfix-smtp_generic' do
|
||||
command "postmap #{node['postfix']['conf_dir']}/smtp_generic"
|
||||
action :nothing
|
||||
end
|
||||
|
||||
unless node['postfix']['smtp_generic_map_entries'].empty?
|
||||
template "#{node['postfix']['conf_dir']}/smtp_generic" do
|
||||
owner 'root'
|
||||
group 0
|
||||
mode '0644'
|
||||
notifies :run, 'execute[update-postfix-smtp_generic]'
|
||||
notifies :reload, 'service[postfix]'
|
||||
end
|
||||
|
||||
unless node['postfix']['main'].key?('smtp_generic_maps')
|
||||
node.set['postfix']['main']['smtp_generic_maps'] = "hash:#{node['postfix']['conf_dir']}/smtp_generic"
|
||||
end
|
||||
end
|
||||
|
||||
%w{main master}.each do |cfg|
|
||||
template "#{node['postfix']['conf_dir']}/#{cfg}.cf" do
|
||||
source "#{cfg}.cf.erb"
|
||||
owner 'root'
|
||||
group 0
|
||||
mode '0644'
|
||||
notifies :restart, 'service[postfix]'
|
||||
variables(settings: node['postfix'][cfg])
|
||||
cookbook node['postfix']["#{cfg}_template_source"]
|
||||
end
|
||||
end
|
||||
|
||||
service 'postfix' do
|
||||
supports status: true, restart: true, reload: true
|
||||
action :enable
|
||||
end
|
@ -14,15 +14,15 @@
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
include_recipe "postfix"
|
||||
include_recipe 'postfix::_common'
|
||||
|
||||
execute "update-postfix-access" do
|
||||
execute 'update-postfix-access' do
|
||||
command "postmap #{node['postfix']['access_db']}"
|
||||
environment PATH: "#{ENV['PATH']}:/opt/omni/bin:/opt/omni/sbin" if platform_family?('omnios')
|
||||
action :nothing
|
||||
end
|
||||
|
||||
template "/etc/postfix/access" do
|
||||
source "access.erb"
|
||||
notifies :run, "execute[update-postfix-access]"
|
||||
template node['postfix']['access_db'] do
|
||||
source 'access.erb'
|
||||
notifies :run, 'execute[update-postfix-access]'
|
||||
end
|
||||
|
@ -14,7 +14,7 @@
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
include_recipe 'postfix'
|
||||
include_recipe 'postfix::_common'
|
||||
|
||||
execute 'update-postfix-aliases' do
|
||||
command 'newaliases'
|
||||
|
@ -18,109 +18,24 @@
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
package 'postfix'
|
||||
include_recipe 'postfix::_common'
|
||||
|
||||
package 'procmail' if node['postfix']['use_procmail']
|
||||
|
||||
case node['platform_family']
|
||||
when 'rhel', 'fedora'
|
||||
service 'sendmail' do
|
||||
action :nothing
|
||||
end
|
||||
|
||||
execute 'switch_mailer_to_postfix' do
|
||||
command '/usr/sbin/alternatives --set mta /usr/sbin/sendmail.postfix'
|
||||
notifies :stop, 'service[sendmail]'
|
||||
notifies :start, 'service[postfix]'
|
||||
not_if '/usr/bin/test /etc/alternatives/mta -ef /usr/sbin/sendmail.postfix'
|
||||
end
|
||||
when 'omnios'
|
||||
manifest_path = ::File.join(Chef::Config[:file_cache_path], 'manifest-postfix.xml')
|
||||
|
||||
# we need to manage the postfix group and user
|
||||
# and then subscribe to the package install because it creates a
|
||||
# postdrop group and adds postfix user to it.
|
||||
group 'postfix' do
|
||||
append true
|
||||
end
|
||||
|
||||
user 'postfix' do
|
||||
uid node['postfix']['uid']
|
||||
gid 'postfix'
|
||||
home '/var/spool/postfix'
|
||||
subscribes :manage, 'package[postfix]'
|
||||
notifies :run, 'execute[/opt/omni/sbin/postfix set-permissions]', :immediately
|
||||
end
|
||||
|
||||
# we don't guard this because if the user creation was successful (or happened out of band), then this won't get executed when the action is :nothing.
|
||||
execute '/opt/omni/sbin/postfix set-permissions'
|
||||
|
||||
template manifest_path do
|
||||
source 'manifest-postfix.xml.erb'
|
||||
owner 'root'
|
||||
group 'root'
|
||||
mode '0644'
|
||||
notifies :run, 'execute[load postfix manifest]', :immediately
|
||||
end
|
||||
|
||||
execute 'load postfix manifest' do
|
||||
action :nothing
|
||||
command "svccfg import #{manifest_path}"
|
||||
notifies :restart, 'service[postfix]'
|
||||
end
|
||||
if node['postfix']['main']['smtp_sasl_auth_enable'] == 'yes'
|
||||
include_recipe 'postfix::sasl_auth'
|
||||
end
|
||||
|
||||
execute 'update-postfix-sender_canonical' do
|
||||
command "postmap #{node['postfix']['conf_dir']}/sender_canonical"
|
||||
action :nothing
|
||||
if node['postfix']['main']['use_alias_maps'] == 'yes'
|
||||
include_recipe 'postfix::aliases'
|
||||
end
|
||||
|
||||
unless node['postfix']['sender_canonical_map_entries'].empty?
|
||||
template "#{node['postfix']['conf_dir']}/sender_canonical" do
|
||||
owner 'root'
|
||||
group 0
|
||||
mode '0644'
|
||||
notifies :run, 'execute[update-postfix-sender_canonical]'
|
||||
notifies :reload, 'service[postfix]'
|
||||
end
|
||||
|
||||
unless node['postfix']['main'].key?('sender_canonical_maps')
|
||||
node.set['postfix']['main']['sender_canonical_maps'] = "hash:#{node['postfix']['conf_dir']}/sender_canonical"
|
||||
end
|
||||
if node['postfix']['main']['use_transport_maps'] == 'yes'
|
||||
include_recipe 'postfix::transports'
|
||||
end
|
||||
|
||||
execute 'update-postfix-smtp_generic' do
|
||||
command "postmap #{node['postfix']['conf_dir']}/smtp_generic"
|
||||
action :nothing
|
||||
if node['postfix']['main']['use_access_maps'] == 'yes'
|
||||
include_recipe 'postfix::access'
|
||||
end
|
||||
|
||||
if !node['postfix']['smtp_generic_map_entries'].empty?
|
||||
template "#{node['postfix']['conf_dir']}/smtp_generic" do
|
||||
owner 'root'
|
||||
group 0
|
||||
mode '0644'
|
||||
notifies :run, 'execute[update-postfix-smtp_generic]'
|
||||
notifies :reload, 'service[postfix]'
|
||||
end
|
||||
|
||||
if !node['postfix']['main'].key?('smtp_generic_maps')
|
||||
node.set['postfix']['main']['smtp_generic_maps'] = "hash:#{node['postfix']['conf_dir']}/smtp_generic"
|
||||
end
|
||||
end
|
||||
|
||||
%w{main master}.each do |cfg|
|
||||
template "#{node['postfix']['conf_dir']}/#{cfg}.cf" do
|
||||
source "#{cfg}.cf.erb"
|
||||
owner 'root'
|
||||
group 0
|
||||
mode '0644'
|
||||
notifies :restart, 'service[postfix]'
|
||||
variables(settings: node['postfix'][cfg])
|
||||
cookbook node['postfix']["#{cfg}_template_source"]
|
||||
end
|
||||
end
|
||||
|
||||
service 'postfix' do
|
||||
supports status: true, restart: true, reload: true
|
||||
action [:enable, :start]
|
||||
if node['postfix']['main']['use_virtual_aliases'] == 'yes'
|
||||
include_recipe 'postfix::virtual_aliases'
|
||||
end
|
||||
|
@ -19,7 +19,7 @@
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
include_recipe 'postfix'
|
||||
include_recipe 'postfix::_common'
|
||||
|
||||
sasl_pkgs = []
|
||||
|
||||
|
@ -14,15 +14,15 @@
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
include_recipe "postfix"
|
||||
include_recipe 'postfix::_common'
|
||||
|
||||
execute "update-postfix-transport" do
|
||||
execute 'update-postfix-transport' do
|
||||
command "postmap #{node['postfix']['transport_db']}"
|
||||
environment PATH: "#{ENV['PATH']}:/opt/omni/bin:/opt/omni/sbin" if platform_family?('omnios')
|
||||
action :nothing
|
||||
end
|
||||
|
||||
template node['postfix']['transport_db'] do
|
||||
source "transport.erb"
|
||||
notifies :run, "execute[update-postfix-transport]"
|
||||
source 'transport.erb'
|
||||
notifies :run, 'execute[update-postfix-transport]'
|
||||
end
|
||||
|
@ -14,18 +14,15 @@
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
include_recipe 'postfix'
|
||||
include_recipe 'postfix::_common'
|
||||
|
||||
execute 'postmap-virtual-alias' do
|
||||
command "postmap #{node['postfix']['main']['virtual_alias_maps']}"
|
||||
execute 'update-postfix-virtual-alias' do
|
||||
command "postmap #{node['postfix']['virtual_alias_db']}"
|
||||
environment PATH: "#{ENV['PATH']}:/opt/omni/bin:/opt/omni/sbin" if platform_family?('omnios')
|
||||
action :nothing
|
||||
end
|
||||
|
||||
template node['postfix']['virtual_alias_db'] do
|
||||
source 'virtual_aliases.erb'
|
||||
owner 'root'
|
||||
group 'root'
|
||||
mode 0400
|
||||
notifies :run, 'execute[postmap-virtual-alias]', :immediately
|
||||
notifies :restart, 'service[postfix]'
|
||||
notifies :run, 'execute[update-postfix-virtual-alias]'
|
||||
end
|
||||
|
@ -7,4 +7,4 @@
|
||||
|
||||
<% node['postfix']['virtual_aliases'].each do |key, value| %>
|
||||
<%= key %> <%= value %>
|
||||
<% end %>
|
||||
<% end unless node['postfix']['virtual_aliases'].nil? %>
|
||||
|
Loading…
x
Reference in New Issue
Block a user