diff --git a/README.md b/README.md index cd44586..ec530ee 100644 --- a/README.md +++ b/README.md @@ -109,6 +109,49 @@ To use Chef Server search to automatically detect a node that is the relayhost, **Note** This recipe will set the `node['postfix']['mail_type']` to "master" with an override attribute. +### hash_maps +General recipe to manage any number of hash: tables. You can replace with it recipes like `transport` or `virtual_aliases`, but what is more important - you can create any kinds of hash maps, which has no own recipe. +Examlle: + +```json + "override_attributes": { + "postfix": { + "hash_maps": { + "/etc/postfix/vmailbox": { + "john@example.com": "ok", + "john@example.net": "ok", + }, + "/etc/postfix/virtual": { + "postmaster@example.com": "john@example.com", + "postmaster@example.net": "john@example.net", + "root@mail.example.net": "john@example.net" + }, + "/etc/postfix/envelope_senders": { + "@example.com": "john@example.com", + "@example.net": "john@example.net" + }, + "/etc/postfix/relay_recipients": { + "john@example.net": "ok", + "john@example.com": "ok", + "admin@example.com": "ok", + } + } + } +``` + +To use these files in your configuration reference them in `node['postfix']['main']`, for instance: +```json + "postfix": { + "main": { + "smtpd_sender_login_maps": "hash:/etc/postfix/envelope_senders", + "relay_recipient_maps": "hash:/etc/postfix/relay_recipients", + "virtual_mailbox_maps": "hash:/etc/postfix/vmailbox", + "virtual_alias_maps": "hash:/etc/postfix/virtual", + } + } +``` + + ### aliases Manage `/etc/aliases` with this recipe. Currently only Ubuntu 10.04 platform has a template for the aliases file. Add your aliases template to the `templates/default` or to the appropriate platform+version directory per the File Specificity rules for templates. Then specify a hash of aliases for the `node['postfix']['aliases']` attribute. diff --git a/recipes/default.rb b/recipes/default.rb index adfab98..ae442fa 100644 --- a/recipes/default.rb +++ b/recipes/default.rb @@ -33,3 +33,5 @@ include_recipe 'postfix::virtual_aliases' if node['postfix']['use_virtual_aliase include_recipe 'postfix::virtual_aliases_domains' if node['postfix']['use_virtual_aliases_domains'] include_recipe 'postfix::relay_restrictions' if node['postfix']['use_relay_restrictions_maps'] + +include_recipe 'postfix::hash_maps' if node['postfix']['hash_maps'] diff --git a/recipes/hash_maps.rb b/recipes/hash_maps.rb new file mode 100644 index 0000000..3c382b0 --- /dev/null +++ b/recipes/hash_maps.rb @@ -0,0 +1,30 @@ +# encoding: utf-8 +# Copyright:: Copyright (c) 2012, 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. +# + +node['postfix']['hash_maps'].each do |file, content| + execute "update-postmap-#{file}" do + command "postmap #{file}" + environment PATH: "#{ENV['PATH']}:/opt/omni/bin:/opt/omni/sbin" if platform_family?('omnios') + action :nothing + end + + template file do + source 'hash_maps.erb' + variables(map: content) + notifies :run, "execute[update-postmap-#{file}]" + notifies :restart, 'service[postfix]' + end +end diff --git a/templates/default/hash_maps.erb b/templates/default/hash_maps.erb new file mode 100644 index 0000000..0cde725 --- /dev/null +++ b/templates/default/hash_maps.erb @@ -0,0 +1,9 @@ +# +# This file is generated by Chef for <%= node['fqdn'] %> +# +# Local changes will be overwritten +# + +<% @map.each do |key, value| -%> +<%= key %> <%= value %> +<% end unless @map.nil? -%>