Manage any hash: tables for postfix with hash_maps recipe
This commit is contained in:
parent
c9613ac670
commit
52a675d1c8
43
README.md
43
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.
|
||||
|
||||
|
@ -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']
|
||||
|
30
recipes/hash_maps.rb
Normal file
30
recipes/hash_maps.rb
Normal file
@ -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
|
9
templates/default/hash_maps.erb
Normal file
9
templates/default/hash_maps.erb
Normal file
@ -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? -%>
|
Loading…
x
Reference in New Issue
Block a user