From 80d37848cb634a241b9ddae33c65dbc77ac7b4ee Mon Sep 17 00:00:00 2001 From: Harm de Wit Date: Wed, 11 Jun 2014 13:39:39 -0400 Subject: [PATCH] #55 - Add support for virtual aliases Signed-off-by: Sean OMeara --- attributes/default.rb | 12 +++++++++++ recipes/virtual_aliases.rb | 31 +++++++++++++++++++++++++++ templates/default/virtual_aliases.erb | 10 +++++++++ 3 files changed, 53 insertions(+) create mode 100644 recipes/virtual_aliases.rb create mode 100644 templates/default/virtual_aliases.erb diff --git a/attributes/default.rb b/attributes/default.rb index 615f246..b054420 100644 --- a/attributes/default.rb +++ b/attributes/default.rb @@ -90,6 +90,18 @@ 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'] = {} +end + # # Default main.cf attributes according to `postconf -d` # default['postfix']['main']['relayhost'] = '' # default['postfix']['main']['milter_default_action'] = 'tempfail' diff --git a/recipes/virtual_aliases.rb b/recipes/virtual_aliases.rb new file mode 100644 index 0000000..59f5b75 --- /dev/null +++ b/recipes/virtual_aliases.rb @@ -0,0 +1,31 @@ +# encoding: utf-8 +# Copyright:: Copyright (c) 2012, Opscode, 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. +# + +include_recipe 'postfix' + +execute 'postmap-virtual-alias' do + command "postmap #{node['postfix']['main']['virtual_alias_maps']}" + 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]' +end diff --git a/templates/default/virtual_aliases.erb b/templates/default/virtual_aliases.erb new file mode 100644 index 0000000..0d6a8e4 --- /dev/null +++ b/templates/default/virtual_aliases.erb @@ -0,0 +1,10 @@ +# +# This file is generated by Chef for <%= node['fqdn'] %> +# +# Local changes will be overwritten +# +# See man 5 virtual for format + +<% node['postfix']['virtual_aliases'].each do |key, value| %> +<%= key %> <%= value %> +<% end %>