From c9613ac6702f0ac805a2f310207a24e23b92e228 Mon Sep 17 00:00:00 2001 From: Stanislav Voroniy Date: Fri, 11 Sep 2015 14:37:33 +0200 Subject: [PATCH 1/9] Fixes for Travis CI --- Berksfile | 4 +-- Gemfile | 2 +- attributes/default.rb | 3 +- recipes/_common.rb | 4 +-- recipes/aliases.rb | 2 +- recipes/default.rb | 29 +++++-------------- recipes/relay_restrictions.rb | 1 - spec/wrapper_spec.rb | 1 + .../cookbooks/wrapper/attributes/default.rb | 14 +++++---- test/fixtures/cookbooks/wrapper/metadata.rb | 1 + .../cookbooks/wrapper/recipes/default.rb | 2 +- .../helpers/serverspec/spec_helper.rb | 17 +++++------ 12 files changed, 33 insertions(+), 47 deletions(-) diff --git a/Berksfile b/Berksfile index 3d60e57..71d3d18 100644 --- a/Berksfile +++ b/Berksfile @@ -5,6 +5,6 @@ metadata group :integration do cookbook 'apt' cookbook 'yum' - cookbook 'fake', :path => 'test/fixtures/cookbooks/fake' - cookbook 'wrapper', :path => 'test/fixtures/cookbooks/wrapper' + cookbook 'fake', path: 'test/fixtures/cookbooks/fake' + cookbook 'wrapper', path: 'test/fixtures/cookbooks/wrapper' end diff --git a/Gemfile b/Gemfile index 46455bc..9fdfd97 100644 --- a/Gemfile +++ b/Gemfile @@ -36,4 +36,4 @@ group :development do gem 'rake' gem 'fauxhai' gem 'pry-nav' -end \ No newline at end of file +end diff --git a/attributes/default.rb b/attributes/default.rb index f14a4cf..d3b857b 100644 --- a/attributes/default.rb +++ b/attributes/default.rb @@ -16,7 +16,7 @@ # limitations under the License. # Generic cookbook attributes -default['postfix']['mail_type'] = 'client' +default['postfix']['mail_type'] = 'client' default['postfix']['relayhost_role'] = 'relayhost' default['postfix']['multi_environment_relay'] = false default['postfix']['use_procmail'] = false @@ -145,4 +145,3 @@ end if node['postfix']['use_relay_restirictions_maps'] default['postfix']['main']['smtpd_relay_restrictions'] = "hash:#{node['postfix']['relay_restrictions_db']}, reject" end - diff --git a/recipes/_common.rb b/recipes/_common.rb index b8fc106..4d764c6 100644 --- a/recipes/_common.rb +++ b/recipes/_common.rb @@ -57,7 +57,7 @@ when 'omnios' # 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 + template manifest_path do source 'manifest-postfix.xml.erb' owner 'root' group node['root_group'] @@ -100,7 +100,7 @@ unless node['postfix']['smtp_generic_map_entries'].empty? template "#{node['postfix']['conf_dir']}/smtp_generic" do owner 'root' group node['root_group'] - mode '0644' + mode '0644' notifies :run, 'execute[update-postfix-smtp_generic]' notifies :reload, 'service[postfix]' end diff --git a/recipes/aliases.rb b/recipes/aliases.rb index cd2eb3c..bbecd1d 100644 --- a/recipes/aliases.rb +++ b/recipes/aliases.rb @@ -20,7 +20,7 @@ execute 'update-postfix-aliases' do command 'newaliases' environment PATH: "#{ENV['PATH']}:/opt/omni/bin:/opt/omni/sbin" if platform_family?('omnios') # On FreeBSD, /usr/sbin/newaliases is the sendmail command, and it's in the path before postfix's /usr/local/bin/newaliases - environment ({ 'PATH' => "/usr/local/bin:#{ENV['PATH']}" }) if platform_family?('freebsd') + environment('PATH' => "/usr/local/bin:#{ENV['PATH']}") if platform_family?('freebsd') action :nothing end diff --git a/recipes/default.rb b/recipes/default.rb index ba28cdc..adfab98 100644 --- a/recipes/default.rb +++ b/recipes/default.rb @@ -20,31 +20,16 @@ include_recipe 'postfix::_common' -if node['postfix']['main']['smtp_sasl_auth_enable'] == 'yes' - include_recipe 'postfix::sasl_auth' -end +include_recipe 'postfix::sasl_auth' if node['postfix']['main']['smtp_sasl_auth_enable'] == 'yes' -if node['postfix']['use_alias_maps'] - include_recipe 'postfix::aliases' -end +include_recipe 'postfix::aliases' if node['postfix']['use_alias_maps'] -if node['postfix']['use_transport_maps'] - include_recipe 'postfix::transports' -end +include_recipe 'postfix::transports' if node['postfix']['use_transport_maps'] -if node['postfix']['use_access_maps'] - include_recipe 'postfix::access' -end +include_recipe 'postfix::access' if node['postfix']['use_access_maps'] -if node['postfix']['use_virtual_aliases'] - include_recipe 'postfix::virtual_aliases' -end +include_recipe 'postfix::virtual_aliases' if node['postfix']['use_virtual_aliases'] -if node['postfix']['use_virtual_aliases_domains'] - include_recipe 'postfix::virtual_aliases_domains' -end - -if node['postfix']['use_relay_restrictions_maps'] - include_recipe 'postfix::relay_restrictions' -end +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'] diff --git a/recipes/relay_restrictions.rb b/recipes/relay_restrictions.rb index a96d482..fe4e557 100644 --- a/recipes/relay_restrictions.rb +++ b/recipes/relay_restrictions.rb @@ -26,4 +26,3 @@ template node['postfix']['relay_restrictions_db'] do source 'relay_restrictions.erb' notifies :run, 'execute[update-postfix-relay-restrictions]' end - diff --git a/spec/wrapper_spec.rb b/spec/wrapper_spec.rb index 9820302..2084e39 100644 --- a/spec/wrapper_spec.rb +++ b/spec/wrapper_spec.rb @@ -15,6 +15,7 @@ describe 'wrapper::default' do expect(chef_run.node['postfix']['main']['relayhost']).to eq('please') expect(chef_run.node['postfix']['main']['smtp_sasl_security_options']).to eq('keep') expect(chef_run.node['postfix']['sasl']['smtp_sasl_user_name']).to eq('us') + expect(chef_run.node['postfix']['sasl']['smtp_sasl_passwd']).to eq('happy') end end end diff --git a/test/fixtures/cookbooks/wrapper/attributes/default.rb b/test/fixtures/cookbooks/wrapper/attributes/default.rb index 6ea324e..10c20e0 100644 --- a/test/fixtures/cookbooks/wrapper/attributes/default.rb +++ b/test/fixtures/cookbooks/wrapper/attributes/default.rb @@ -1,6 +1,8 @@ - -default['postfix']['main']['smtp_sasl_auth_enable'] = 'yes' - -default['postfix']['main']['relayhost'] = 'please' -default['postfix']['sasl']['smtp_sasl_user_name'] = 'keep' -default['postfix']['sasl']['smtp_sasl_passwd'] = 'us' + +default['postfix']['main']['smtp_sasl_auth_enable'] = 'yes' + +default['postfix']['main']['relayhost'] = 'please' +default['postfix']['main']['smtp_sasl_security_options'] = 'keep' +default['postfix']['sasl']['smtp_sasl_user_name'] = 'us' +default['postfix']['sasl']['smtp_sasl_passwd'] = 'happy' +default['postfix']['sender_canonical_map_entries'] = {} diff --git a/test/fixtures/cookbooks/wrapper/metadata.rb b/test/fixtures/cookbooks/wrapper/metadata.rb index e92f14f..14d7590 100644 --- a/test/fixtures/cookbooks/wrapper/metadata.rb +++ b/test/fixtures/cookbooks/wrapper/metadata.rb @@ -1,3 +1,4 @@ name 'wrapper' version '0.0.1' description 'Wrapper cookbook, used for testing only.' +depends 'postfix' diff --git a/test/fixtures/cookbooks/wrapper/recipes/default.rb b/test/fixtures/cookbooks/wrapper/recipes/default.rb index 6bd393a..51a1cb3 100644 --- a/test/fixtures/cookbooks/wrapper/recipes/default.rb +++ b/test/fixtures/cookbooks/wrapper/recipes/default.rb @@ -1,2 +1,2 @@ -include 'postfix' +include_recipe 'postfix' diff --git a/test/integration/helpers/serverspec/spec_helper.rb b/test/integration/helpers/serverspec/spec_helper.rb index fb6f099..66b445e 100644 --- a/test/integration/helpers/serverspec/spec_helper.rb +++ b/test/integration/helpers/serverspec/spec_helper.rb @@ -3,25 +3,24 @@ require 'serverspec' set :backend, :exec set :path, '/sbin:/usr/local/sbin:$PATH' -def get_family +def which_family fam = 'solaris2' return fam unless File.exist? '/etc/release' - File.open("/etc/release") do |file| - while line = file.gets - case line - when /^\s*(OmniOS)/ - fam = 'omnios' - end + File.open('/etc/release') do |file| + while (line = file.gets) + case line + when /^\s*(OmniOS)/ + fam = 'omnios' end + end end fam end def postfix_conf_path - if os[:family] == 'solaris' && get_family == 'omnios' + if os[:family] == 'solaris' && which_family == 'omnios' '/opt/omni/etc/postfix/' else '/etc/postfix' end end - From 52a675d1c89af150e829d05474480bdb33a8e7c6 Mon Sep 17 00:00:00 2001 From: Stanislav Voroniy Date: Fri, 11 Sep 2015 15:02:18 +0200 Subject: [PATCH 2/9] Manage any hash: tables for postfix with hash_maps recipe --- README.md | 43 +++++++++++++++++++++++++++++++++ recipes/default.rb | 2 ++ recipes/hash_maps.rb | 30 +++++++++++++++++++++++ templates/default/hash_maps.erb | 9 +++++++ 4 files changed, 84 insertions(+) create mode 100644 recipes/hash_maps.rb create mode 100644 templates/default/hash_maps.erb 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? -%> From 3b2a268d6d213d401d8d267432328b5e3b0c1da3 Mon Sep 17 00:00:00 2001 From: Stanislav Voroniy Date: Sat, 12 Sep 2015 10:53:28 +0200 Subject: [PATCH 3/9] Fully customizable master.cf file --- README.md | 67 +++++++- attributes/default.rb | 260 +++++++++++++++++++++++++++++++- recipes/_attributes.rb | 12 ++ templates/default/master.cf.erb | 131 ++++++++-------- 4 files changed, 392 insertions(+), 78 deletions(-) diff --git a/README.md b/README.md index ec530ee..9d49063 100644 --- a/README.md +++ b/README.md @@ -84,9 +84,74 @@ Example of json role config, for setup *_map_entries: `}` ### master.cf template attributes -* `node['postfix']['master']['submission'] - Whether to use submission (TCP 587) daemon. (true/false); default false +The master.cf template has been changed to allow full customization of the file content. For purpose of backwards compatibility default attributes generate the same master.cf. But via `node['postfix']['master']` data structure in your role for instance it can be completelly rewritten. +Examples of json role config, for customize master.cf: + +`postfix : {` + +`...` + +turn some services off or on: +```json + "master" : { + "smtps": { + "active": true + }, + "old-cyrus": { + "active": false + }, + "cyrus": { + "active": false + }, + "uucp": { + "active": false + }, + "ifmail": { + "active": false + }, +``` + +`...` +define you own service: +```json + "spamfilter": { + "comment": "My own spamfilter", + "active": true, + "order": 590, + "type": "unix", + "unpriv": false, + "chroot": false, + "command": "pipe", + "args": ["flags=Rq user=spamd argv=/usr/bin/spamfilter.sh -oi -f ${sender} ${recipient}"] + } +``` + +`...` + +` }` +`}` + +The possible service hash fields and their meanings: +hash key - have to be unique, unless you wish to override default definition. + +| Field | Mandatory | Description | +| ----------- | --------- |-------------------------------------------------------------------------| +|active | Yes | Boolean. Defines whether or not the service needs to be in master.cf | +|comment | No | If you would like to add a comment line before service line | +|order | Yes | Number to define the order of lines in the file | +|type | Yes | Type of the service (inet, unix, fifo) | +|private | No | Boolean. If present replaced by `y` or `n`, otherwise by `-` | +|unpriv | No | Boolean. If present replaced by `y` or `n`, otherwise by `-` | +|chroot | No | Boolean. If present replaced by `y` or `n`, otherwise by `-` | +|wakeup | No | String. If present value placed in file, otherwise replaced by `-` | +|maxproc | No | String. If present value placed in file, otherwise replaced by `-` | +|command | Yes | String. The command to be executed. | +|args | Yes | String. Arguments passed to command. | + +For more information about meaning of the fields consult `master (5)` manual: +http://www.postfix.org/master.5.html Recipes ------- ### default diff --git a/attributes/default.rb b/attributes/default.rb index d3b857b..b527d6c 100644 --- a/attributes/default.rb +++ b/attributes/default.rb @@ -118,7 +118,261 @@ end # default['postfix']['main']['canonical_maps'] = nil # Master.cf attributes -default['postfix']['master']['submission'] = false +default['postfix']['master']['smtp']['active'] = true +default['postfix']['master']['smtp']['order'] = 10 +default['postfix']['master']['smtp']['type'] = 'inet' +default['postfix']['master']['smtp']['private'] = false +default['postfix']['master']['smtp']['chroot'] = false +default['postfix']['master']['smtp']['command'] = 'smtpd' +default['postfix']['master']['smtp']['args'] = [] + +default['postfix']['master']['submission']['active'] = false +default['postfix']['master']['submission']['order'] = 20 +default['postfix']['master']['submission']['type'] = 'inet' +default['postfix']['master']['submission']['private'] = false +default['postfix']['master']['submission']['chroot'] = false +default['postfix']['master']['submission']['command'] = 'smtpd' +default['postfix']['master']['submission']['args'] = ['-o smtpd_enforce_tls=yes', ' -o smtpd_sasl_auth_enable=yes', '-o smtpd_client_restrictions=permit_sasl_authenticated,reject'] + +default['postfix']['master']['smtps']['active'] = false +default['postfix']['master']['smtps']['order'] = 30 +default['postfix']['master']['smtps']['type'] = 'inet' +default['postfix']['master']['smtps']['private'] = false +default['postfix']['master']['smtps']['chroot'] = false +default['postfix']['master']['smtps']['command'] = 'smtpd' +default['postfix']['master']['smtps']['args'] = ['-o smtpd_tls_wrappermode=yes', '-o smtpd_sasl_auth_enable=yes', '-o smtpd_client_restrictions=permit_sasl_authenticated,reject'] + +default['postfix']['master']['628']['active'] = false +default['postfix']['master']['628']['order'] = 40 +default['postfix']['master']['628']['type'] = 'inet' +default['postfix']['master']['628']['private'] = false +default['postfix']['master']['628']['chroot'] = false +default['postfix']['master']['628']['command'] = 'qmqpdd' +default['postfix']['master']['628']['args'] = [] + +default['postfix']['master']['pickup']['active'] = true +default['postfix']['master']['pickup']['order'] = 50 +default['postfix']['master']['pickup']['type'] = 'fifo' +default['postfix']['master']['pickup']['private'] = false +default['postfix']['master']['pickup']['chroot'] = false +default['postfix']['master']['pickup']['wakeup'] = '60' +default['postfix']['master']['pickup']['maxproc'] = '1' +default['postfix']['master']['pickup']['command'] = 'pickup' +default['postfix']['master']['pickup']['args'] = [] + +default['postfix']['master']['cleanup']['active'] = true +default['postfix']['master']['cleanup']['order'] = 60 +default['postfix']['master']['cleanup']['type'] = 'unix' +default['postfix']['master']['cleanup']['private'] = false +default['postfix']['master']['cleanup']['chroot'] = false +default['postfix']['master']['cleanup']['maxproc'] = '0' +default['postfix']['master']['cleanup']['command'] = 'cleanup' +default['postfix']['master']['cleanup']['args'] = [] + +default['postfix']['master']['qmgr']['active'] = true +default['postfix']['master']['qmgr']['order'] = 70 +default['postfix']['master']['qmgr']['type'] = 'fifo' +default['postfix']['master']['qmgr']['private'] = false +default['postfix']['master']['qmgr']['chroot'] = false +default['postfix']['master']['qmgr']['wakeup'] = '300' +default['postfix']['master']['qmgr']['maxproc'] = '1' +default['postfix']['master']['qmgr']['command'] = 'qmgr' +default['postfix']['master']['qmgr']['args'] = [] + +default['postfix']['master']['tlsmgr']['active'] = true +default['postfix']['master']['tlsmgr']['order'] = 80 +default['postfix']['master']['tlsmgr']['type'] = 'unix' +default['postfix']['master']['tlsmgr']['chroot'] = false +default['postfix']['master']['tlsmgr']['wakeup'] = '1000?' +default['postfix']['master']['tlsmgr']['maxproc'] = '1' +default['postfix']['master']['tlsmgr']['command'] = 'tlsmgr' +default['postfix']['master']['tlsmgr']['args'] = [] + +default['postfix']['master']['rewrite']['active'] = true +default['postfix']['master']['rewrite']['order'] = 90 +default['postfix']['master']['rewrite']['type'] = 'unix' +default['postfix']['master']['rewrite']['chroot'] = false +default['postfix']['master']['rewrite']['command'] = 'trivial-rewrite' +default['postfix']['master']['rewrite']['args'] = [] + +default['postfix']['master']['bounce']['active'] = true +default['postfix']['master']['bounce']['order'] = 100 +default['postfix']['master']['bounce']['type'] = 'unix' +default['postfix']['master']['bounce']['chroot'] = false +default['postfix']['master']['bounce']['maxproc'] = '0' +default['postfix']['master']['bounce']['command'] = 'bounce' +default['postfix']['master']['bounce']['args'] = [] + +default['postfix']['master']['defer']['active'] = true +default['postfix']['master']['defer']['order'] = 110 +default['postfix']['master']['defer']['type'] = 'unix' +default['postfix']['master']['defer']['chroot'] = false +default['postfix']['master']['defer']['maxproc'] = '0' +default['postfix']['master']['defer']['command'] = 'bounce' +default['postfix']['master']['defer']['args'] = [] + +default['postfix']['master']['trace']['active'] = true +default['postfix']['master']['trace']['order'] = 120 +default['postfix']['master']['trace']['type'] = 'unix' +default['postfix']['master']['trace']['chroot'] = false +default['postfix']['master']['trace']['maxproc'] = '0' +default['postfix']['master']['trace']['command'] = 'bounce' +default['postfix']['master']['trace']['args'] = [] + +default['postfix']['master']['verify']['active'] = true +default['postfix']['master']['verify']['order'] = 130 +default['postfix']['master']['verify']['type'] = 'unix' +default['postfix']['master']['verify']['chroot'] = false +default['postfix']['master']['verify']['maxproc'] = '1' +default['postfix']['master']['verify']['command'] = 'verify' +default['postfix']['master']['verify']['args'] = [] + +default['postfix']['master']['flush']['active'] = true +default['postfix']['master']['flush']['order'] = 140 +default['postfix']['master']['flush']['type'] = 'unix' +default['postfix']['master']['flush']['private'] = false +default['postfix']['master']['flush']['chroot'] = false +default['postfix']['master']['flush']['wakeup'] = '1000?' +default['postfix']['master']['flush']['maxproc'] = '0' +default['postfix']['master']['flush']['command'] = 'flush' +default['postfix']['master']['flush']['args'] = [] + +default['postfix']['master']['proxymap']['active'] = true +default['postfix']['master']['proxymap']['order'] = 150 +default['postfix']['master']['proxymap']['type'] = 'unix' +default['postfix']['master']['proxymap']['chroot'] = false +default['postfix']['master']['proxymap']['command'] = 'proxymap' +default['postfix']['master']['proxymap']['args'] = [] + +default['postfix']['master']['smtpunix']['service'] = 'smtp' +default['postfix']['master']['smtpunix']['active'] = true +default['postfix']['master']['smtpunix']['order'] = 160 +default['postfix']['master']['smtpunix']['type'] = 'unix' +default['postfix']['master']['smtpunix']['chroot'] = false +default['postfix']['master']['smtpunix']['maxproc'] = '500' +default['postfix']['master']['smtpunix']['command'] = 'smtp' +default['postfix']['master']['smtpunix']['args'] = [] + +default['postfix']['master']['relay']['active'] = true +default['postfix']['master']['relay']['comment'] = 'When relaying mail as backup MX, disable fallback_relay to avoid MX loops' +default['postfix']['master']['relay']['order'] = 170 +default['postfix']['master']['relay']['type'] = 'unix' +default['postfix']['master']['relay']['chroot'] = false +default['postfix']['master']['relay']['command'] = 'smtp' +default['postfix']['master']['relay']['args'] = ['-o smtp_fallback_relay='] + +default['postfix']['master']['showq']['active'] = true +default['postfix']['master']['showq']['order'] = 180 +default['postfix']['master']['showq']['type'] = 'unix' +default['postfix']['master']['showq']['private'] = false +default['postfix']['master']['showq']['chroot'] = false +default['postfix']['master']['showq']['command'] = 'showq' +default['postfix']['master']['showq']['args'] = [] + +default['postfix']['master']['error']['active'] = true +default['postfix']['master']['error']['order'] = 190 +default['postfix']['master']['error']['type'] = 'unix' +default['postfix']['master']['error']['chroot'] = false +default['postfix']['master']['error']['command'] = 'error' +default['postfix']['master']['error']['args'] = [] + +default['postfix']['master']['discard']['active'] = true +default['postfix']['master']['discard']['order'] = 200 +default['postfix']['master']['discard']['type'] = 'unix' +default['postfix']['master']['discard']['chroot'] = false +default['postfix']['master']['discard']['command'] = 'discard' +default['postfix']['master']['discard']['args'] = [] + +default['postfix']['master']['local']['active'] = true +default['postfix']['master']['local']['order'] = 210 +default['postfix']['master']['local']['type'] = 'unix' +default['postfix']['master']['local']['unpriv'] = false +default['postfix']['master']['local']['chroot'] = false +default['postfix']['master']['local']['command'] = 'local' +default['postfix']['master']['local']['args'] = [] + +default['postfix']['master']['virtual']['active'] = true +default['postfix']['master']['virtual']['order'] = 220 +default['postfix']['master']['virtual']['type'] = 'unix' +default['postfix']['master']['virtual']['unpriv'] = false +default['postfix']['master']['virtual']['chroot'] = false +default['postfix']['master']['virtual']['command'] = 'virtual' +default['postfix']['master']['virtual']['args'] = [] + +default['postfix']['master']['lmtp']['active'] = true +default['postfix']['master']['lmtp']['order'] = 230 +default['postfix']['master']['lmtp']['type'] = 'unix' +default['postfix']['master']['lmtp']['chroot'] = false +default['postfix']['master']['lmtp']['command'] = 'lmtp' +default['postfix']['master']['lmtp']['args'] = [] + +default['postfix']['master']['anvil']['active'] = true +default['postfix']['master']['anvil']['order'] = 240 +default['postfix']['master']['anvil']['type'] = 'unix' +default['postfix']['master']['anvil']['chroot'] = false +default['postfix']['master']['anvil']['maxproc'] = '1' +default['postfix']['master']['anvil']['command'] = 'anvil' +default['postfix']['master']['anvil']['args'] = [] + +default['postfix']['master']['scache']['active'] = true +default['postfix']['master']['scache']['order'] = 250 +default['postfix']['master']['scache']['type'] = 'unix' +default['postfix']['master']['scache']['chroot'] = false +default['postfix']['master']['scache']['maxproc'] = '1' +default['postfix']['master']['scache']['command'] = 'scache' +default['postfix']['master']['scache']['args'] = [] + +default['postfix']['master']['maildrop']['active'] = true +default['postfix']['master']['maildrop']['comment'] = 'See the Postfix MAILDROP_README file for details. To main.cf will be added: maildrop_destination_recipient_limit=1' +default['postfix']['master']['maildrop']['order'] = 510 +default['postfix']['master']['maildrop']['type'] = 'unix' +default['postfix']['master']['maildrop']['unpriv'] = false +default['postfix']['master']['maildrop']['chroot'] = false +default['postfix']['master']['maildrop']['command'] = 'pipe' +default['postfix']['master']['maildrop']['args'] = ['flags=DRhu user=vmail argv=/usr/local/bin/maildrop -d ${recipient}'] + +default['postfix']['master']['old-cyrus']['active'] = false +default['postfix']['master']['old-cyrus']['comment'] = 'The Cyrus deliver program has changed incompatibly, multiple times.' +default['postfix']['master']['old-cyrus']['order'] = 520 +default['postfix']['master']['old-cyrus']['type'] = 'unix' +default['postfix']['master']['old-cyrus']['unpriv'] = false +default['postfix']['master']['old-cyrus']['chroot'] = false +default['postfix']['master']['old-cyrus']['command'] = 'pipe' +default['postfix']['master']['old-cyrus']['args'] = ['flags=R user=cyrus argv=/usr/lib/cyrus-imapd/deliver -e -m ${extension} ${user}'] + +default['postfix']['master']['cyrus']['active'] = true +default['postfix']['master']['cyrus']['comment'] = 'Cyrus 2.1.5 (Amos Gouaux). To main.cf will be added: cyrus_destination_recipient_limit=1' +default['postfix']['master']['cyrus']['order'] = 530 +default['postfix']['master']['cyrus']['type'] = 'unix' +default['postfix']['master']['cyrus']['unpriv'] = false +default['postfix']['master']['cyrus']['chroot'] = false +default['postfix']['master']['cyrus']['command'] = 'pipe' +default['postfix']['master']['cyrus']['args'] = ['user=cyrus argv=/usr/lib/cyrus-imapd/deliver -e -r ${sender} -m ${extension} ${user}'] + +default['postfix']['master']['uucp']['active'] = true +default['postfix']['master']['uucp']['comment'] = 'See the Postfix UUCP_README file for configuration details.' +default['postfix']['master']['uucp']['order'] = 540 +default['postfix']['master']['uucp']['type'] = 'unix' +default['postfix']['master']['uucp']['unpriv'] = false +default['postfix']['master']['uucp']['chroot'] = false +default['postfix']['master']['uucp']['command'] = 'pipe' +default['postfix']['master']['uucp']['args'] = ['flags=Fqhu user=uucp argv=uux -r -n -z -a$sender - $nexthop!rmail ($recipient)'] + +default['postfix']['master']['ifmail']['active'] = false +default['postfix']['master']['ifmail']['order'] = 550 +default['postfix']['master']['ifmail']['type'] = 'unix' +default['postfix']['master']['ifmail']['unpriv'] = false +default['postfix']['master']['ifmail']['chroot'] = false +default['postfix']['master']['ifmail']['command'] = 'pipe' +default['postfix']['master']['ifmail']['args'] = ['flags=F user=ftn argv=/usr/lib/ifmail/ifmail -r $nexthop ($recipient)'] + +default['postfix']['master']['bsmtp']['active'] = true +default['postfix']['master']['bsmtp']['order'] = 560 +default['postfix']['master']['bsmtp']['type'] = 'unix' +default['postfix']['master']['bsmtp']['unpriv'] = false +default['postfix']['master']['bsmtp']['chroot'] = false +default['postfix']['master']['bsmtp']['command'] = 'pipe' +default['postfix']['master']['bsmtp']['args'] = ['flags=Fq. user=foo argv=/usr/local/sbin/bsmtp -f $sender $nexthop $recipient'] # OS Aliases case node['platform'] @@ -141,7 +395,3 @@ when 'freebsd' else default['postfix']['aliases'] = {} end - -if node['postfix']['use_relay_restirictions_maps'] - default['postfix']['main']['smtpd_relay_restrictions'] = "hash:#{node['postfix']['relay_restrictions_db']}, reject" -end diff --git a/recipes/_attributes.rb b/recipes/_attributes.rb index 7340b1e..aaaf8c1 100644 --- a/recipes/_attributes.rb +++ b/recipes/_attributes.rb @@ -58,3 +58,15 @@ end if node['postfix']['use_virtual_aliases_domains'] node.default_unless['postfix']['main']['virtual_alias_domains'] = ["#{node['postfix']['virtual_alias_domains_db_type']}:#{node['postfix']['virtual_alias_domains_db']}"] end + +if node['postfix']['use_relay_restirictions_maps'] + default['postfix']['main']['smtpd_relay_restrictions'] = "hash:#{node['postfix']['relay_restrictions_db']}, reject" +end + +if node['postfix']['master']['maildrop']['active'] + node.default_unless['postfix']['main']['maildrop_destination_recipient_limit'] = 1 +end + +if node['postfix']['master']['cyrus']['active'] + node.default_unless['postfix']['main']['cyrus_destination_recipient_limit'] = 1 +end diff --git a/templates/default/master.cf.erb b/templates/default/master.cf.erb index ffa2aa5..52b6a1a 100644 --- a/templates/default/master.cf.erb +++ b/templates/default/master.cf.erb @@ -1,3 +1,6 @@ +# This file is generated by Chef for <%= node['fqdn'] %> +# +# Local changes will be overwritten # # Postfix master process configuration file. For details on the format # of the file, see the master(5) manual page (command: "man 5 master"). @@ -6,76 +9,60 @@ # service type private unpriv chroot wakeup maxproc command + args # (yes) (yes) (yes) (never) (100) # ========================================================================== -smtp inet n - n - - smtpd -<% if @settings['submission'] -%> -submission inet n - n - - smtpd - -o smtpd_enforce_tls=yes - -o smtpd_sasl_auth_enable=yes - -o smtpd_client_restrictions=permit_sasl_authenticated,reject +<% @settings.sort_by{|k,v| v['order']}.map do |service, properties| -%> +<% next if !properties['active'] -%> +<% if properties.has_key?('comment') -%> +# +#<%= properties['comment'] %> +<% end -%> +<% if properties.has_key?('service') -%> +<%= properties['service'].ljust(10) -%> +<% else -%> +<%= service.ljust(10) -%> +<% end -%> + <%= properties['type'].ljust(6) -%> +<% if properties.has_key?('private') -%> +<% if properties['private'] -%> +<% priv='y' -%> +<% else -%> +<% priv='n' -%> +<% end -%> +<% else -%> +<% priv='-' -%> +<% end -%> +<%= priv.ljust(8) -%> +<% if properties.has_key?('unpriv') -%> +<% if properties['unpriv'] -%> +<% unpriv='y' -%> +<% else -%> +<% unpriv='n' -%> +<% end -%> +<% else -%> +<% unpriv='-' -%> +<% end -%> +<%= unpriv.ljust(8) -%> +<% if properties.has_key?('chroot') -%> +<% if properties['chroot'] -%> +<% chroot='y' -%> +<% else -%> +<% chroot='n' -%> +<% end -%> +<% else -%> +<% chroot='-' -%> +<% end -%> +<%= chroot.ljust(7) -%> +<% if properties.has_key?('wakeup') -%> + <%= properties['wakeup'].ljust(7) -%> +<% else -%> + <%= '-'.ljust(7) -%> +<% end -%> +<% if properties.has_key?('maxproc') -%> + <%= properties['maxproc'].ljust(7) -%> +<% else -%> + <%= '-'.ljust(7) -%> +<% end -%> + <%= properties['command'] %> +<% properties['args'].each do |arg| -%> + <%= arg %> +<% end -%> <% end -%> -#smtps inet n - n - - smtpd -# -o smtpd_tls_wrappermode=yes -# -o smtpd_sasl_auth_enable=yes -# -o smtpd_client_restrictions=permit_sasl_authenticated,reject -#628 inet n - n - - qmqpd -pickup fifo n - n 60 1 pickup -cleanup unix n - n - 0 cleanup -qmgr fifo n - n 300 1 qmgr -#qmgr fifo n - n 300 1 oqmgr -tlsmgr unix - - n 1000? 1 tlsmgr -rewrite unix - - n - - trivial-rewrite -bounce unix - - n - 0 bounce -defer unix - - n - 0 bounce -trace unix - - n - 0 bounce -verify unix - - n - 1 verify -flush unix n - n 1000? 0 flush -proxymap unix - - n - - proxymap -smtp unix - - n - 500 smtp -# When relaying mail as backup MX, disable fallback_relay to avoid MX loops -relay unix - - n - - smtp - -o smtp_fallback_relay= -# -o smtp_helo_timeout=5 -o smtp_connect_timeout=5 -showq unix n - n - - showq -error unix - - n - - error -discard unix - - n - - discard -local unix - n n - - local -virtual unix - n n - - virtual -lmtp unix - - n - - lmtp -anvil unix - - n - 1 anvil -scache unix - - n - 1 scache -# -# ==================================================================== -# Interfaces to non-Postfix software. Be sure to examine the manual -# pages of the non-Postfix software to find out what options it wants. -# -# Many of the following services use the Postfix pipe(8) delivery -# agent. See the pipe(8) man page for information about ${recipient} -# and other message envelope options. -# ==================================================================== -# -# maildrop. See the Postfix MAILDROP_README file for details. -# Also specify in main.cf: maildrop_destination_recipient_limit=1 -# -maildrop unix - n n - - pipe - flags=DRhu user=vmail argv=/usr/local/bin/maildrop -d ${recipient} -# -# The Cyrus deliver program has changed incompatibly, multiple times. -# -old-cyrus unix - n n - - pipe - flags=R user=cyrus argv=/usr/lib/cyrus-imapd/deliver -e -m ${extension} ${user} -# Cyrus 2.1.5 (Amos Gouaux) -# Also specify in main.cf: cyrus_destination_recipient_limit=1 -cyrus unix - n n - - pipe - user=cyrus argv=/usr/lib/cyrus-imapd/deliver -e -r ${sender} -m ${extension} ${user} -# -# See the Postfix UUCP_README file for configuration details. -# -uucp unix - n n - - pipe - flags=Fqhu user=uucp argv=uux -r -n -z -a$sender - $nexthop!rmail ($recipient) -# -# Other external delivery methods. -# -ifmail unix - n n - - pipe - flags=F user=ftn argv=/usr/lib/ifmail/ifmail -r $nexthop ($recipient) -bsmtp unix - n n - - pipe - flags=Fq. user=foo argv=/usr/local/sbin/bsmtp -f $sender $nexthop $recipient From 525d67394ac37fc188d2de8965622f66a5b5de5a Mon Sep 17 00:00:00 2001 From: Stanislav Voroniy Date: Wed, 30 Sep 2015 09:54:46 +0200 Subject: [PATCH 4/9] Support for any kind of postfix lookup tables --- README.md | 52 ++++++++++++------- recipes/default.rb | 2 +- recipes/hash_maps.rb | 30 ----------- recipes/maps.rb | 50 ++++++++++++++++++ templates/default/{hash_maps.erb => maps.erb} | 2 +- 5 files changed, 84 insertions(+), 52 deletions(-) delete mode 100644 recipes/hash_maps.rb create mode 100644 recipes/maps.rb rename templates/default/{hash_maps.erb => maps.erb} (80%) diff --git a/README.md b/README.md index 9d49063..d89999a 100644 --- a/README.md +++ b/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'" + } } } } diff --git a/recipes/default.rb b/recipes/default.rb index ae442fa..82dc22a 100644 --- a/recipes/default.rb +++ b/recipes/default.rb @@ -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'] diff --git a/recipes/hash_maps.rb b/recipes/hash_maps.rb deleted file mode 100644 index 3c382b0..0000000 --- a/recipes/hash_maps.rb +++ /dev/null @@ -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 diff --git a/recipes/maps.rb b/recipes/maps.rb new file mode 100644 index 0000000..4078fc4 --- /dev/null +++ b/recipes/maps.rb @@ -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 diff --git a/templates/default/hash_maps.erb b/templates/default/maps.erb similarity index 80% rename from templates/default/hash_maps.erb rename to templates/default/maps.erb index 0cde725..f3bfc72 100644 --- a/templates/default/hash_maps.erb +++ b/templates/default/maps.erb @@ -5,5 +5,5 @@ # <% @map.each do |key, value| -%> -<%= key %> <%= value %> +<%= key %><%= @separator %><%= value %> <% end unless @map.nil? -%> From 331cc10e6cba5e6ddd3b377ab72c3794d916b2a6 Mon Sep 17 00:00:00 2001 From: Stanislav Voroniy Date: Wed, 30 Sep 2015 10:04:29 +0200 Subject: [PATCH 5/9] Update metadata. I believe all these changes deserve a version increase. --- metadata.rb | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/metadata.rb b/metadata.rb index cc73aa1..cf84510 100644 --- a/metadata.rb +++ b/metadata.rb @@ -4,7 +4,7 @@ maintainer_email 'cookbooks@chef.io' license 'Apache 2.0' description 'Installs and configures postfix for client or outbound relayhost, or to do SASL auth' long_description IO.read(File.join(File.dirname(__FILE__), 'README.md')) -version '3.7.0' +version '3.8.0' issues_url 'https://github.com/chef-cookbooks/postfix/issues' if respond_to?(:source_url) source_url 'https://github.com/chef-cookbooks/postfix' if respond_to?(:issues_url) @@ -16,6 +16,7 @@ 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' +recipe 'postfix::maps', 'Manages any number of any type postfix lookup tables' %w(ubuntu debian redhat centos amazon oracle scientific smartos).each do |os| supports os @@ -26,6 +27,11 @@ attribute 'postfix/main', description: 'Hash of Postfix main.cf attributes', type: 'hash' +attribute 'postfix/master', + display_name: 'Postfix master.cf configuration', + description: 'Hash to configure the content of the second most important config file - master.cf. Defaults to the standard master.cf content.', + type: 'hash' + attribute 'postfix/aliases', display_name: 'Postfix Aliases', description: "Hash of Postfix aliases mapping a name to a value. Example 'root' => 'operator@example.com'. See aliases man page for details.", @@ -65,3 +71,9 @@ attribute 'postfix/use_procmail', display_name: 'Postfix Use procmail?', description: 'Whether procmail should be used as the local delivery agent for a server', default: 'no' + +attribute 'postfix/maps', + display_name: 'Postfix lookup tables', + description: 'Hash to manage any kind of any postfix lookup tables', + type: 'hash' + default: 'no' From 2b91f3513f15e051c4335b18aee7a2f9f369de84 Mon Sep 17 00:00:00 2001 From: Stanislav Voroniy Date: Tue, 6 Oct 2015 09:23:35 +0200 Subject: [PATCH 6/9] fix sysntax issue --- metadata.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/metadata.rb b/metadata.rb index cf84510..39c7419 100644 --- a/metadata.rb +++ b/metadata.rb @@ -76,4 +76,3 @@ attribute 'postfix/maps', display_name: 'Postfix lookup tables', description: 'Hash to manage any kind of any postfix lookup tables', type: 'hash' - default: 'no' From 0c0580f7e55531b4920a9b6d3c817855c41a581a Mon Sep 17 00:00:00 2001 From: Stanislav Voroniy Date: Tue, 6 Oct 2015 10:17:11 +0200 Subject: [PATCH 7/9] Make foodcritic and rubocop happy again --- Gemfile | 1 - recipes/maps.rb | 31 ++++++++++++++----------------- 2 files changed, 14 insertions(+), 18 deletions(-) diff --git a/Gemfile b/Gemfile index 9fdfd97..6cb27d4 100644 --- a/Gemfile +++ b/Gemfile @@ -3,7 +3,6 @@ source 'https://rubygems.org' group :lint do gem 'foodcritic', '~> 4.0' gem 'rubocop', '~> 0.33' - gem 'rake' end group :unit do diff --git a/recipes/maps.rb b/recipes/maps.rb index 4078fc4..b112bc1 100644 --- a/recipes/maps.rb +++ b/recipes/maps.rb @@ -16,32 +16,29 @@ node['postfix']['maps'].each do |type, maps| if node['platform_family'] == 'debian' - if ['pgsql', 'mysql', 'ldap', 'cdb'].include?(type) - package "postfix-#{type}" - end + package "postfix-#{type}" if %w(pgsql mysql ldap cdb).include?(type) end + if %w(pgsql mysql ldap memcache sqlite).include?(type) + separator = ' = ' + else + separator = ' ' + 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 + 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 if %w(btree cdb dbm hash sdbm).include?(type) + template "#{file}-#{type}" do + path file source 'maps.erb' only_if "postconf -m | grep -q #{type}" variables( map: content, separator: separator ) - if ['btree', 'cdb', 'dbm', 'hash', 'sdbm'].include?(type) + if %w(btree cdb dbm hash sdbm).include?(type) notifies :run, "execute[update-postmap-#{file}]" end notifies :restart, 'service[postfix]' From a4dca01665af2074c864a90e52361221477b77c8 Mon Sep 17 00:00:00 2001 From: Stanislav Voroniy Date: Tue, 6 Oct 2015 11:15:53 +0200 Subject: [PATCH 8/9] Force version 3.2 - otherwise Travis loads 3.3 --- Gemfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index 6cb27d4..6b05f2e 100644 --- a/Gemfile +++ b/Gemfile @@ -6,7 +6,7 @@ group :lint do end group :unit do - gem 'berkshelf', '~> 3.2' + gem 'berkshelf', '3.2' gem 'chefspec', '~> 4.3' end From 89a411f8284a05ef8463d11d50ec77a82057bc8a Mon Sep 17 00:00:00 2001 From: Stanislav Voroniy Date: Tue, 22 Dec 2015 13:24:56 +0100 Subject: [PATCH 9/9] fix test for travis --- test/fixtures/cookbooks/wrapper/attributes/default.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/test/fixtures/cookbooks/wrapper/attributes/default.rb b/test/fixtures/cookbooks/wrapper/attributes/default.rb index b2fea3a..57d5d9a 100644 --- a/test/fixtures/cookbooks/wrapper/attributes/default.rb +++ b/test/fixtures/cookbooks/wrapper/attributes/default.rb @@ -1,5 +1,6 @@ default['postfix']['main']['smtp_sasl_auth_enable'] = 'yes' default['postfix']['main']['relayhost'] = 'please' -default['postfix']['sasl']['smtp_sasl_user_name'] = 'keep' -default['postfix']['sasl']['smtp_sasl_passwd'] = 'us' +default['postfix']['main']['smtp_sasl_security_options'] = 'keep' +default['postfix']['sasl']['smtp_sasl_user_name'] = 'us' +default['postfix']['sasl']['smtp_sasl_passwd'] = 'happy' default['postfix']['sender_canonical_map_entries'] = {}