/postfix-dovecot-cookbook

Chef cookbook example to install and configure a mail server using Postfix, Dovecot, PostfixAdmin and SpamAssassin.

Primary LanguageRuby

Description

Installs and configures a mail server using Postfix, Dovecot, PostfixAdmin and SpamAssassin, including Amazon SES support.

Requirements

Platform:

This cookbook has been tested on the following platforms:

  • Amazon Linux
  • CentOS >= 6.0
  • Debian >= 7.0
  • Fedora >= 17.0
  • Ubuntu >= 12.04

Let me know if you use it successfully on any other platform.

Cookbooks:

Applications:

  • Dovecot >= 2: requires this version of dovecot to be available by the distribution's package manager.

Attributes

Attribute Description Default
node['postfix-dovecot']['postmaster_address'] Postmaster mail address. "postmaster@foo.bar"
node['postfix-dovecot']['hostname'] Hostname. node["fqdn"]
node['postfix-dovecot']['sieve']['enabled'] Whether to enable sieve. true
node['postfix-dovecot']['sieve']['global_path'] Sieve global path. "#{default["dovecot"]["conf_path"]}/sieve/default.sieve"
node['postfix-dovecot']['spamc']['enabled'] Whether to enable SpamAssassin true
node['postfix-dovecot']['spamc']['recipe'] Spamc recipe name to use. "onddo-spamassassin"
node['postfix-dovecot']['vmail']['user'] Virtual mail system user name. "vmail"
node['postfix-dovecot']['vmail']['group'] Virtual mail system group name. node["postfix-dovecot"]["vmail"]["user"]
node['postfix-dovecot']['vmail']['uid'] Virtual mail system user id. 5000
node['postfix-dovecot']['vmail']['gid'] Virtual mail system group id. node["postfix-dovecot"]["vmail"]["uid"]
node['postfix-dovecot']['vmail']['home'] Virtual mail user home path. "/var/vmail"
node['postfix-dovecot']['ses']['enabled'] Whether to enable Amazon SES. false
node['postfix-dovecot']['ses']['username'] Amazon SES SMTP username. See the Obtaining Your Amazon SES SMTP Credentials documentation. "USERNAME"
node['postfix-dovecot']['ses']['password'] Amazon SES SMTP password. "PASSWORD"
node['postfix-dovecot']['ses']['servers'] Amazon SES SMTP servers. [
  'email-smtp.us-east-1.amazonaws.com:25',
  'ses-smtp-prod-335357831.us-east-1.elb.amazonaws.com:25'
]

Recipes

postfix-dovecot::default

Installs and configures everything.

postfix-dovecot::vmail

Creates vmail user.

postfix-dovecot::spam

Installs and configures SpamAssassin.

postfix-dovecot::postfix-full

Installs and configures Postfix.

postfix-dovecot::postfixadmin

Installs and configures PostfixAdmin.

postfix-dovecot::dovecot

Installs and configures Dovecot 2.

Usage Example

Including in a Cookbook Recipe

Running it from a recipe:

node['postfix-dovecot']['postmaster_address'] = 'postmaster@foobar.com'
node['postfix-dovecot']['hostname'] = 'mail.foobar.com'

include_recipe 'postfix-dovecot::default'

postfixadmin_admin 'admin@admindomain.com' do
  password 'sup3r-s3cr3t-p4ss'
  action :create
end

postfixadmin_domain 'foobar.com' do
  login_username 'admin@admindomain.com'
  login_password 'sup3r-s3cr3t-p4ss'
end

postfixadmin_mailbox 'bob@foobar.com' do
  password 'alice'
  login_username 'admin@admindomain.com'
  login_password 'sup3r-s3cr3t-p4ss'
end

postfixadmin_alias 'billing@foobar.com' do
  goto 'bob@foobar.com'
  login_username 'admin@admindomain.com'
  login_password 'sup3r-s3cr3t-p4ss'
end

Don't forget to include the postfix-dovecot cookbook as a dependency in the metadata.

# metadata.rb
[...]

depends 'postfix-dovecot'

Including in the Run List

Another alternative is to include the default recipe in your Run List.

{
  "name": "mail.onddo.com",
  [...]
  "run_list": [
    [...]
    "recipe[postfix-dovecot]"
  ]
}

Testing

Requirements

  • vagrant
  • berkshelf >= 1.4.0
  • test-kitchen >= 1.0.0.alpha
  • kitchen-vagrant >= 0.10.0

Running the tests

$ kitchen test
$ kitchen verify
[...]

Running the tests in the cloud

Requirements:

  • kitchen-vagrant >= 0.10
  • kitchen-digitalocean >= 0.5
  • kitchen-ec2 >= 0.8

You can run the tests in the cloud instead of using vagrant. First, you must set the following environment variables:

  • AWS_ACCESS_KEY_ID
  • AWS_SECRET_ACCESS_KEY
  • AWS_KEYPAIR_NAME: EC2 SSH public key name. This is the name used in Amazon EC2 Console's Key Pars section.
  • EC2_SSH_KEY_PATH: EC2 SSH private key local full path. Only when you are not using an SSH Agent.
  • DIGITAL_OCEAN_CLIENT_ID
  • DIGITAL_OCEAN_API_KEY
  • DIGITAL_OCEAN_SSH_KEY_IDS: DigitalOcean SSH numeric key IDs.
  • DIGITAL_OCEAN_SSH_KEY_PATH: DigitalOcean SSH private key local full path. Only when you are not using an SSH Agent.

Then, you must configure test-kitchen to use .kitchen.cloud.yml configuration file:

$ export KITCHEN_LOCAL_YAML=".kitchen.cloud.yml"
$ kitchen list
[...]

Amazon SES Tests

You need to set the following environment variables:

Then, you must configure test-kitchen to use .kitchen.ses.yml configuration file:

$ export AMAZON_SES_EMAIL_FROM="no-reply@sesdomain.com"
$ export AMAZON_SES_SMTP_USERNAME="..."
$ export AMAZON_SES_SMTP_PASSWORD="..."
$ export KITCHEN_LOCAL_YAML=".kitchen.ses.yml"
$ kitchen list
[...]

Contributing

  1. Fork the repository on Github
  2. Create a named feature branch (like add_component_x)
  3. Write you change
  4. Write tests for your change (if applicable)
  5. Run the tests, ensuring they all pass
  6. Submit a Pull Request using Github

License and Author

Author: Xabier de Zuazo (xabier@onddo.com)
Copyright: Copyright (c) 2013-2014 Onddo Labs, SL. (www.onddo.com)
License: Apache License, Version 2.0

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.