diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..7bd34cd --- /dev/null +++ b/Gemfile @@ -0,0 +1,7 @@ +source 'https://rubygems.org' + +puppetversion = ENV.key?('PUPPET_VERSION') ? "= #{ENV['PUPPET_VERSION']}" : ['>= 3.3'] +gem 'puppet', puppetversion +gem 'puppetlabs_spec_helper', '>= 0.1.0' +gem 'puppet-lint', '>= 0.3.2' +gem 'facter', '>= 1.7.0' diff --git a/README.md b/README.md new file mode 100644 index 0000000..3a6fb20 --- /dev/null +++ b/README.md @@ -0,0 +1,79 @@ +# postfix + +#### Table of Contents + +1. [Overview](#overview) +2. [Module Description - What the module does and why it is useful](#module-description) +3. [Setup - The basics of getting started with postfix](#setup) + * [What postfix affects](#what-postfix-affects) + * [Setup requirements](#setup-requirements) + * [Beginning with postfix](#beginning-with-postfix) +4. [Usage - Configuration options and additional functionality](#usage) +5. [Reference - An under-the-hood peek at what the module is doing and how](#reference) +5. [Limitations - OS compatibility, etc.](#limitations) +6. [Development - Guide for contributing to the module](#development) + +## Overview + +A one-maybe-two sentence summary of what the module does/what problem it solves. +This is your 30 second elevator pitch for your module. Consider including +OS/Puppet version it works with. + +## Module Description + +If applicable, this section should have a brief description of the technology +the module integrates with and what that integration enables. This section +should answer the questions: "What does this module *do*?" and "Why would I use +it?" + +If your module has a range of functionality (installation, configuration, +management, etc.) this is the time to mention it. + +## Setup + +### What postfix affects + +* A list of files, packages, services, or operations that the module will alter, + impact, or execute on the system it's installed on. +* This is a great place to stick any warnings. +* Can be in list or paragraph form. + +### Setup Requirements **OPTIONAL** + +If your module requires anything extra before setting up (pluginsync enabled, +etc.), mention it here. + +### Beginning with postfix + +The very basic steps needed for a user to get the module up and running. + +If your most recent release breaks compatibility or requires particular steps +for upgrading, you may wish to include an additional section here: Upgrading +(For an example, see http://forge.puppetlabs.com/puppetlabs/firewall). + +## Usage + +Put the classes, types, and resources for customizing, configuring, and doing +the fancy stuff with your module here. + +## Reference + +Here, list the classes, types, providers, facts, etc contained in your module. +This section should include all of the under-the-hood workings of your module so +people know what the module is touching on their system but don't need to mess +with things. (We are working on automating this section!) + +## Limitations + +This is where you list OS compatibility, version compatibility, etc. + +## Development + +Since your module is awesome, other users will want to play with it. Let them +know what the ground rules for contributing are. + +## Release Notes/Contributors/Etc **Optional** + +If you aren't using changelog, put your release notes here (though you should +consider using changelog). You may also add any additional sections you feel are +necessary or important to include here. Please use the `## ` header. diff --git a/Rakefile b/Rakefile new file mode 100644 index 0000000..4b62f2d --- /dev/null +++ b/Rakefile @@ -0,0 +1,20 @@ +require 'rubygems' +require 'puppetlabs_spec_helper/rake_tasks' +require 'puppet-lint/tasks/puppet-lint' +PuppetLint.configuration.send('disable_80chars') +PuppetLint.configuration.send('disable_autoloader_layout') +PuppetLint.configuration.send('disable_variable_scope') +PuppetLint.configuration.ignore_paths = ["spec/**/*.pp", "pkg/**/*.pp"] + +desc "Validate manifests, templates, and ruby files" +task :validate do + Dir['manifests/**/*.pp'].each do |manifest| + sh "puppet parser validate --parser=future --noop #{manifest}" + end + Dir['spec/**/*.rb','lib/**/*.rb'].each do |ruby_file| + sh "ruby -c #{ruby_file}" unless ruby_file =~ /spec\/fixtures/ + end + Dir['templates/**/*.erb'].each do |template| + sh "erb -P -x -T '-' #{template} | ruby -c" + end +end diff --git a/manifests/init.pp b/manifests/init.pp new file mode 100644 index 0000000..d4d3f42 --- /dev/null +++ b/manifests/init.pp @@ -0,0 +1,64 @@ +# == Class: postfix +# +# Manage postfix configuration with Debian preseeding +# +# === Parameters +# +# [*relayhost*] +# Set the relayhost for the machine +# +# [*main_mailer_type*] +# Set the main mailer type as would be asked through debconf. +# Values: 'No configuration', 'Internet Site', 'Internet with smarthost', 'Satellite system', 'Local only' +# Default: 'Satellite system' +# +# [*root_address*] +# Set the forward address for mail sent to root. +# Default: '' (keeping the current root alias) +# +# [*mailname*] +# The default domain for outgoing mail +# Default: $::fqdn +# +# [*destinations*] +# Array of domains for whose the mail is locally delivered +# Default: [$::fqdn] +# +# [*mynetworks*] +# Array of networks from which to accept mail +# Default: ['127.0.0.0/8', '[::ffff:127.0.0.0]/104', '[::1]/128'] (only accept local mail) +# === Examples +# +# class { 'postfix': +# relayhost => '[smtp.example.com]', +# } +# +# === Authors +# +# Nicolas Dandrimont +# +# === Copyright +# +# Copyright 2015 Nicolas Dandrimont +# +class postfix ( + $relayhost = undef, + $main_mailer_type = 'Satellite system', + $root_address = '', + $mailname = $::fqdn, + $destinations = [$::fqdn], + $mynetworks = ['127.0.0.0/8', '[::ffff:127.0.0.0]/104', '[::1]/128'], +){ + + validate_string($relayhost) + validate_string($main_mailer_type) + validate_string($root_address) + validate_string($mailname) + assert_type(Array[String], $destinations) + assert_type(Array[String], $mynetworks) + + ::debconf_package {'postfix': + ensure => present, + content => template('postfix/preseed.erb'), + } +} diff --git a/metadata.json b/metadata.json new file mode 100644 index 0000000..c9e433c --- /dev/null +++ b/metadata.json @@ -0,0 +1,14 @@ +{ + "name": "swh-postfix", + "version": "0.1.0", + "author": "swh", + "summary": "Manage postfix installation through Debian preseeding", + "license": "Apache 2.0", + "source": "git@git.softwareheritage.org:swh/sysadm/puppet/swh-postfix", + "project_page": null, + "issues_url": null, + "dependencies": [ + {"name":"puppetlabs-stdlib","version_requirement":">= 1.0.0"}, + {"name":"rlenglet-debconf_package","version_requirement":">= 0.1.1"} + ] +} diff --git a/spec/classes/init_spec.rb b/spec/classes/init_spec.rb new file mode 100644 index 0000000..ace8912 --- /dev/null +++ b/spec/classes/init_spec.rb @@ -0,0 +1,7 @@ +require 'spec_helper' +describe 'postfix' do + + context 'with defaults for all parameters' do + it { should contain_class('postfix') } + end +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 0000000..2c6f566 --- /dev/null +++ b/spec/spec_helper.rb @@ -0,0 +1 @@ +require 'puppetlabs_spec_helper/module_spec_helper' diff --git a/templates/preseed.erb b/templates/preseed.erb new file mode 100644 index 0000000..2e72908 --- /dev/null +++ b/templates/preseed.erb @@ -0,0 +1,19 @@ +# Template for postfix preseeding +postfix postfix/main_mailer_type select <%= @main_mailer_type %> +postfix postfix/mailbox_limit string 0 +postfix postfix/relay_restrictions_warning boolean +postfix postfix/tlsmgr_upgrade_warning boolean +postfix postfix/root_address string <%= @root_address %> +postfix postfix/chattr boolean false +postfix postfix/relayhost string <%= @relayhost %> +postfix postfix/procmail boolean false +postfix postfix/rfc1035_violation boolean false +postfix postfix/mailname string <%= @mailname %> +postfix postfix/protocols select all +postfix postfix/destinations string <%= @destinations.join(", ") %> +postfix postfix/recipient_delim string + +postfix postfix/sqlite_warning boolean +postfix postfix/retry_upgrade_warning boolean +postfix postfix/mynetworks string <%= @mynetworks.join(" ") %> +postfix postfix/kernel_version_warning boolean +postfix postfix/mydomain_warning boolean diff --git a/tests/init.pp b/tests/init.pp new file mode 100644 index 0000000..31e2b4b --- /dev/null +++ b/tests/init.pp @@ -0,0 +1,12 @@ +# The baseline for module testing used by Puppet Labs is that each manifest +# should have a corresponding test manifest that declares that class or defined +# type. +# +# Tests are then run by using puppet apply --noop (to check for compilation +# errors and view a log of events) or by fully applying the test in a virtual +# environment (to compare the resulting system state to the desired state). +# +# Learn more about module testing here: +# http://docs.puppetlabs.com/guides/tests_smoke.html +# +include postfix