diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 0000000..3ea6c96 --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,115 @@ +GEM + remote: http://rubygems.org/ + specs: + archive-tar-minitar (0.5.2) + bunny (0.7.9) + chef (10.14.4) + bunny (>= 0.6.0, < 0.8.0) + erubis + highline (>= 1.6.9) + json (>= 1.4.4, <= 1.6.1) + mixlib-authentication (>= 1.3.0) + mixlib-cli (>= 1.1.0) + mixlib-config (>= 1.1.2) + mixlib-log (>= 1.3.0) + mixlib-shellout + moneta + net-ssh (~> 2.2.2) + net-ssh-multi (~> 1.1.0) + ohai (>= 0.6.0) + rest-client (>= 1.0.4, < 1.7.0) + treetop (~> 1.4.9) + uuidtools + yajl-ruby (~> 1.1) + childprocess (0.3.6) + ffi (~> 1.0, >= 1.0.6) + coderay (1.0.8) + erubis (2.7.0) + ffi (1.1.5) + foodcritic (1.6.1) + erubis + gherkin (~> 2.11.1) + gist (~> 3.1.0) + nokogiri (= 1.5.0) + pry (~> 0.9.8.4) + rak (~> 1.4) + treetop (~> 1.4.10) + yajl-ruby (~> 1.1.0) + gherkin (2.11.5) + json (>= 1.4.6) + gist (3.1.0) + hashr (0.0.22) + highline (1.6.15) + i18n (0.6.1) + ipaddress (0.8.0) + json (1.5.4) + librarian (0.0.25) + archive-tar-minitar (>= 0.5.2) + chef (>= 0.10) + highline + thor (~> 0.15) + log4r (1.1.10) + method_source (0.7.1) + mime-types (1.19) + mixlib-authentication (1.3.0) + mixlib-log + mixlib-cli (1.2.2) + mixlib-config (1.1.2) + mixlib-log (1.4.1) + mixlib-shellout (1.1.0) + moneta (0.6.0) + net-scp (1.0.4) + net-ssh (>= 1.99.1) + net-ssh (2.2.2) + net-ssh-gateway (1.1.0) + net-ssh (>= 1.99.1) + net-ssh-multi (1.1) + net-ssh (>= 2.1.4) + net-ssh-gateway (>= 0.99.0) + nokogiri (1.5.0) + ohai (6.14.1) + ipaddress + mixlib-cli + mixlib-config + mixlib-log + systemu + yajl-ruby + polyglot (0.3.3) + pry (0.9.8.4) + coderay (~> 1.0.5) + method_source (~> 0.7.1) + slop (>= 2.4.4, < 3) + rak (1.4) + rest-client (1.6.7) + mime-types (>= 1.16) + slop (2.4.4) + systemu (2.5.2) + test-kitchen (0.6.0) + foodcritic (~> 1.4) + hashr (~> 0.0.20) + highline (>= 1.6.9) + librarian (~> 0.0.20) + mixlib-cli (~> 1.2.2) + vagrant (~> 1.0.2) + yajl-ruby (~> 1.1.0) + thor (0.16.0) + treetop (1.4.11) + polyglot + polyglot (>= 0.3.1) + uuidtools (2.1.3) + vagrant (1.0.5) + archive-tar-minitar (= 0.5.2) + childprocess (~> 0.3.1) + erubis (~> 2.7.0) + i18n (~> 0.6.0) + json (~> 1.5.1) + log4r (~> 1.1.9) + net-scp (~> 1.0.4) + net-ssh (~> 2.2.2) + yajl-ruby (1.1.0) + +PLATFORMS + ruby + +DEPENDENCIES + test-kitchen diff --git a/files/default/tests/minitest/aliases_test.rb b/files/default/tests/minitest/aliases_test.rb new file mode 100644 index 0000000..642afc6 --- /dev/null +++ b/files/default/tests/minitest/aliases_test.rb @@ -0,0 +1,26 @@ +# +# Copyright 2012, Opscode, 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. +# + +require File.expand_path('../support/helpers', __FILE__) + +describe "postfix::aliases" do + include Helpers::Postfix + + it 'manages /etc/aliases' do + file("/etc/aliases").must_match(/^# This file is generated by Chef for/) + end + +end diff --git a/files/default/tests/minitest/client_test.rb b/files/default/tests/minitest/client_test.rb new file mode 100644 index 0000000..d48cf84 --- /dev/null +++ b/files/default/tests/minitest/client_test.rb @@ -0,0 +1,24 @@ +# +# Copyright 2012, Opscode, 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. +# + +require File.expand_path('../support/helpers', __FILE__) + +describe "postfix::client" do + include Helpers::Postfix + it 'doesnt configure postfix because solo is unsupported' do + skip "Postfix may be set up by default on the system, but not configured by Chef because this test assumes it is run under Chef Solo" + end +end diff --git a/files/default/tests/minitest/default_test.rb b/files/default/tests/minitest/default_test.rb new file mode 100644 index 0000000..a4613f1 --- /dev/null +++ b/files/default/tests/minitest/default_test.rb @@ -0,0 +1,38 @@ +# +# Copyright 2012, Opscode, 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. +# + +require File.expand_path('../support/helpers', __FILE__) + +describe "postfix::default" do + include Helpers::Postfix + + it 'installs the postfix package' do + package("postfix").must_be_installed + end + + it 'enables the postfix service' do + service("postfix").must_be_enabled + end + + it 'starts the postfix service' do + service("postfix").must_be_running + end + + it 'configures postfix main.cf' do + file("/etc/postfix/main.cf").must_match(/^# Generated by Chef for /) + end + +end diff --git a/files/default/tests/minitest/sasl_auth_test.rb b/files/default/tests/minitest/sasl_auth_test.rb new file mode 100644 index 0000000..a63f2fb --- /dev/null +++ b/files/default/tests/minitest/sasl_auth_test.rb @@ -0,0 +1,25 @@ +# +# Copyright 2012, Opscode, 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. +# +require File.expand_path('../support/helpers', __FILE__) + +describe "postfix::sasl_auth" do + include Helpers::Postfix + + it 'manages /etc/postfix/sasl_passwd' do + file("/etc/postfix/sasl_passwd").must_match(/^# This file is generated by Chef for/) + end + +end diff --git a/files/default/tests/minitest/server_test.rb b/files/default/tests/minitest/server_test.rb new file mode 100644 index 0000000..65b603c --- /dev/null +++ b/files/default/tests/minitest/server_test.rb @@ -0,0 +1,23 @@ +# +# Copyright 2012, Opscode, 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. +# +require File.expand_path('../support/helpers', __FILE__) + +describe "postfix::server" do + include Helpers::Postfix + it 'doesnt configure postfix because solo is unsupported' do + skip "Postfix may be set up by default on the system, but not configured by Chef because this test assumes it is run under Chef Solo" + end +end diff --git a/files/default/tests/minitest/support/helpers.rb b/files/default/tests/minitest/support/helpers.rb new file mode 100644 index 0000000..6ed3df6 --- /dev/null +++ b/files/default/tests/minitest/support/helpers.rb @@ -0,0 +1,24 @@ +# +# Copyright 2012, Opscode, 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. +# + +module Helpers + module Postfix + include MiniTest::Chef::Assertions + include MiniTest::Chef::Context + include MiniTest::Chef::Resources + + end +end diff --git a/recipes/aliases.rb b/recipes/aliases.rb index 30a4891..60ff605 100644 --- a/recipes/aliases.rb +++ b/recipes/aliases.rb @@ -1,3 +1,19 @@ +# +# Copyright:: Copyright (c) 2012, Opscode, 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. +# + require_recipe "postfix" execute "update-postfix-aliases" do @@ -7,7 +23,5 @@ end template "/etc/aliases" do source "aliases.erb" - notifies :run, resources("execute[update-postfix-aliases]") - #notifies :reload, resources(:service => "postfix") + notifies :run, "execute[update-postfix-aliases]" end - diff --git a/recipes/default.rb b/recipes/default.rb index e81ac8a..682f807 100644 --- a/recipes/default.rb +++ b/recipes/default.rb @@ -18,14 +18,12 @@ # limitations under the License. # -package "postfix" do - action :install -end +package "postfix" + +if node['postfix']['use_procmail'] + + package "procmail" -if node['postfix']['use_procmail'] then - package "procmail" do - action :install - end end @@ -34,26 +32,31 @@ service "postfix" do action :enable end -case node[:platform] -when "redhat", "centos", "amazon", "scientific" +case node['platform_family'] +when "rhel", "fedora" + service "sendmail" do action :nothing end + execute "switch_mailer_to_postfix" do command "/usr/sbin/alternatives --set mta /usr/sbin/sendmail.postfix" - notifies :stop, resources(:service => "sendmail") - notifies :start, resources(:service => "postfix") + notifies :stop, "service[sendmail]" + notifies :start, "service[postfix]" not_if "/usr/bin/test /etc/alternatives/mta -ef /usr/sbin/sendmail.postfix" end + end %w{main master}.each do |cfg| + template "/etc/postfix/#{cfg}.cf" do source "#{cfg}.cf.erb" owner "root" - group "root" - mode 0644 - notifies :restart, resources(:service => "postfix") + group 0 + mode 00644 + notifies :restart, "service[postfix]" + end end diff --git a/recipes/sasl_auth.rb b/recipes/sasl_auth.rb index 7ea922d..914aaf4 100644 --- a/recipes/sasl_auth.rb +++ b/recipes/sasl_auth.rb @@ -18,10 +18,29 @@ # limitations under the License. # -%w{ libsasl2-2 ca-certificates}.each do |pkg| - package pkg do - action :install +include_recipe "postfix" + +sasl_pkgs = [] + +# We use case instead of value_for_platform_family because we need +# version specifics for RHEL. +case node['platform_family'] +when "debian" + sasl_pkgs = %w{libsasl2-2 ca-certificates} +when "rhel" + if node['platform_version'].to_i < 6 + sasl_pkgs = %w{cyrus-sasl openssl} + else + sasl_pkgs = %w{cyrus-sasl ca-certificates} end +when "fedora" + sasl_pkgs = %w{cyrus-sasl ca-certificates} +end + +sasl_pkgs.each do |pkg| + + package pkg + end execute "postmap-sasl_passwd" do @@ -34,7 +53,6 @@ template "/etc/postfix/sasl_passwd" do owner "root" group "root" mode 0400 - notifies :run, resources(:execute => "postmap-sasl_passwd"), :immediately - notifies :restart, resources(:service => "postfix") + notifies :run, "execute[postmap-sasl_passwd]", :immediately + notifies :restart, "service[postfix]" end - diff --git a/templates/default/main.cf.erb b/templates/default/main.cf.erb index 77cf9b9..cae3e7a 100644 --- a/templates/default/main.cf.erb +++ b/templates/default/main.cf.erb @@ -24,12 +24,12 @@ myhostname = <%= node['postfix']['myhostname'] %> mydomain = <%= node['postfix']['mydomain'] %> <% end -%> myorigin = <%= node['postfix']['myorigin'] %> -smtpd_banner = $myhostname ESMTP $mail_name +smtpd_banner = $myhostname ESMTP $mail_name alias_maps = hash:/etc/aliases alias_database = hash:/etc/aliases mydestination = <%= node['postfix']['myhostname'] %>, <%= node['hostname'] %>, localhost.localdomain, localhost <% if node['postfix']['mail_type'] == "master" -%> -relayhost = +relayhost = mynetworks = <%= node['postfix']['mail_relay_networks'] %> inet_interfaces = all <% else -%> diff --git a/templates/default/sasl_passwd.erb b/templates/default/sasl_passwd.erb index e10535e..f4fc56d 100644 --- a/templates/default/sasl_passwd.erb +++ b/templates/default/sasl_passwd.erb @@ -1 +1,2 @@ -<%= node[:postfix][:relayhost] %> <%= node[:postfix][:smtp_sasl_user_name] %>:<%= node[:postfix][:smtp_sasl_passwd] %> +# This file is generated by Chef for <%= node['fqdn'] %> +<%= node['postfix']['relayhost'] %> <%= node['postfix']['smtp_sasl_user_name'] %>:<%= node['postfix']['smtp_sasl_passwd'] %> diff --git a/test/kitchen/Kitchenfile b/test/kitchen/Kitchenfile index 3d10eb9..f455233 100644 --- a/test/kitchen/Kitchenfile +++ b/test/kitchen/Kitchenfile @@ -1,3 +1,7 @@ cookbook "postfix" do - runtimes [] + configuration "default" + configuration "aliases" + configuration "client" + configuration "server" + configuration "sasl_auth" end