Support for any kind of postfix lookup tables
This commit is contained in:
parent
3b2a268d6d
commit
525d67394a
52
README.md
52
README.md
@ -174,31 +174,43 @@ 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.
|
||||
### maps
|
||||
General recipe to manage any number of any type postfix lookup tables. You can replace with it recipes like `transport` or `virtual_aliases`, but what is more important - you can create any kinds of maps, which has no own recipe, including database lookup maps configuration.
|
||||
`maps` is a hash keys of which is a lookup table type and value is another hash with filenames as the keys and hash with file content as the value. File content is an any number of key/value pairs which meaning depends on lookup table type.
|
||||
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",
|
||||
"maps": {
|
||||
"hash": {
|
||||
"/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",
|
||||
}
|
||||
},
|
||||
"pgsql": {
|
||||
"/etc/postfix/pgtest": {
|
||||
"hosts": "db.local:2345",
|
||||
"user": "postfix",
|
||||
"password": "test",
|
||||
"dbname": "postdb",
|
||||
"query": "SELECT replacement FROM aliases WHERE mailbox = '%s'"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -34,4 +34,4 @@ include_recipe 'postfix::virtual_aliases_domains' if node['postfix']['use_virtua
|
||||
|
||||
include_recipe 'postfix::relay_restrictions' if node['postfix']['use_relay_restrictions_maps']
|
||||
|
||||
include_recipe 'postfix::hash_maps' if node['postfix']['hash_maps']
|
||||
include_recipe 'postfix::maps' if node['postfix']['maps']
|
||||
|
@ -1,30 +0,0 @@
|
||||
# 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
|
50
recipes/maps.rb
Normal file
50
recipes/maps.rb
Normal file
@ -0,0 +1,50 @@
|
||||
# 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']['maps'].each do |type, maps|
|
||||
if node['platform_family'] == 'debian'
|
||||
if ['pgsql', 'mysql', 'ldap', 'cdb'].include?(type)
|
||||
package "postfix-#{type}"
|
||||
end
|
||||
end
|
||||
|
||||
maps.each do |file, content|
|
||||
if ['btree', 'cdb', 'dbm', 'hash', 'sdbm'].include?(type)
|
||||
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
|
||||
end
|
||||
if ['pgsql', 'mysql', 'ldap', 'memcache', 'sqlite'].include?(type)
|
||||
separator = " = "
|
||||
else
|
||||
separator = " "
|
||||
end
|
||||
template file do
|
||||
source 'maps.erb'
|
||||
only_if "postconf -m | grep -q #{type}"
|
||||
variables(
|
||||
map: content,
|
||||
separator: separator
|
||||
)
|
||||
if ['btree', 'cdb', 'dbm', 'hash', 'sdbm'].include?(type)
|
||||
notifies :run, "execute[update-postmap-#{file}]"
|
||||
end
|
||||
notifies :restart, 'service[postfix]'
|
||||
end
|
||||
end
|
||||
end
|
@ -5,5 +5,5 @@
|
||||
#
|
||||
|
||||
<% @map.each do |key, value| -%>
|
||||
<%= key %> <%= value %>
|
||||
<%= key %><%= @separator %><%= value %>
|
||||
<% end unless @map.nil? -%>
|
Loading…
x
Reference in New Issue
Block a user