summaryrefslogtreecommitdiffstats
path: root/lib/puppet
diff options
context:
space:
mode:
authorluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2007-07-11 18:35:51 +0000
committerluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2007-07-11 18:35:51 +0000
commitf570a5f32a03d8ee1e8dde5c0984b83cdbf7b2ad (patch)
tree4360acc6c3f0fc85bef41872ae5184846d34be66 /lib/puppet
parent2d3c920e0fdef4ca38e14677a4a670f0890ff994 (diff)
downloadpuppet-f570a5f32a03d8ee1e8dde5c0984b83cdbf7b2ad.tar.gz
puppet-f570a5f32a03d8ee1e8dde5c0984b83cdbf7b2ad.tar.xz
puppet-f570a5f32a03d8ee1e8dde5c0984b83cdbf7b2ad.zip
Adding a maillist type, with support for mailman. It is not as flexible as I would like, partially because of how mailman is implemented (the "mailman" command is never in the search path), but at least it is working for mailman on debian.
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@2677 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'lib/puppet')
-rwxr-xr-xlib/puppet/provider/maillist/mailman.rb112
-rwxr-xr-xlib/puppet/type/maillist.rb57
2 files changed, 169 insertions, 0 deletions
diff --git a/lib/puppet/provider/maillist/mailman.rb b/lib/puppet/provider/maillist/mailman.rb
new file mode 100755
index 000000000..95abf9b3d
--- /dev/null
+++ b/lib/puppet/provider/maillist/mailman.rb
@@ -0,0 +1,112 @@
+require 'puppet/provider/parsedfile'
+
+Puppet::Type.type(:maillist).provide(:mailman) do
+ commands :list_lists => "list_lists", :rmlist => "rmlist", :newlist => "newlist"
+
+ # This probably won't work for non-Debian installs, but this path is sure not to be in the PATH.
+ commands :mailman => "/var/lib/mailman/mail/mailman"
+
+ mk_resource_methods
+
+ # Return a list of existing mailman instances.
+ def self.instances
+ list_lists.split("\n").reject { |line| line.include?("matching mailing lists") }.collect do |line|
+ name, description = line.sub(/^\s+/, '').sub(/\s+$/, '').split(/\s+-\s+/)
+ if description.include?("no description available")
+ description = :absent
+ end
+ new(:ensure => :present, :name => name, :description => description)
+ end
+ end
+
+ # Prefetch our list list, yo.
+ def self.prefetch(lists)
+ instances.each do |prov|
+ if list = lists[prov.name]
+ list.provider = prov
+ end
+ end
+ end
+
+ def aliases
+ mailman = self.class.command(:mailman)
+ aliases = {self.name => "| #{mailman} post #{self.name}"}
+ %w{admin bounces confirm join leave owner request subscribe unsubscribe}.each do |address|
+ aliases["%s-%s" % [self.name, address]] = "| %s %s %s" % [mailman, address, name]
+ end
+ aliases
+ end
+
+ # Create the list.
+ def create
+ args = []
+ if val = @resource[:mailserver]
+ args << "--emailhost" << val
+ end
+ if val = @resource[:webserver]
+ args << "--urlhost" << val
+ end
+
+ args << self.name
+ if val = @resource[:admin]
+ args << val
+ else
+ raise ArgumentError, "Mailman lists require an administrator email address"
+ end
+ if val = @resource[:password]
+ args << val
+ else
+ raise ArgumentError, "Mailman lists require an administrator password"
+ end
+ newlist(*args)
+ end
+
+ # Delete the list.
+ def delete(purge = false)
+ args = []
+ if purge
+ args << "--archives"
+ end
+ args << self.name
+ rmlist(*args)
+ end
+
+ # Does our list exist already?
+ def exists?
+ properties[:ensure] != :absent
+ end
+
+ # Clear out the cached values.
+ def flush
+ @property_hash.clear
+ end
+
+ # Look up the current status.
+ def properties
+ if @property_hash.empty?
+ @property_hash = query || {:ensure => :absent}
+ if @property_hash.empty?
+ @property_hash[:ensure] = :absent
+ end
+ end
+ @property_hash.dup
+ end
+
+ # Remove the list and its archives.
+ def purge
+ delete(true)
+ end
+
+ # Pull the current state of the list from the full list. We're
+ # getting some double entendre here....
+ def query
+ self.class.instances.each do |list|
+ if list.name == self.name
+ return list.property_hash
+ end
+ end
+ nil
+ end
+end
+
+# $Id$
diff --git a/lib/puppet/type/maillist.rb b/lib/puppet/type/maillist.rb
new file mode 100755
index 000000000..fd536b51e
--- /dev/null
+++ b/lib/puppet/type/maillist.rb
@@ -0,0 +1,57 @@
+module Puppet
+ newtype(:maillist) do
+ @doc = "Manage email lists. This resource type currently can only create
+ and remove lists, it cannot reconfigure them."
+
+ ensurable do
+ defaultvalues
+
+ newvalue(:purged) do
+ provider.purge
+ end
+ end
+
+ newparam(:name, :namevar => true) do
+ desc "The name of the email list."
+ end
+
+ newparam(:description) do
+ desc "The description of the mailing list."
+ end
+
+ newparam(:password) do
+ desc "The admin password."
+ end
+
+ newparam(:webserver) do
+ desc "The name of the host providing web archives and the administrative interface."
+ end
+
+ newparam(:mailserver) do
+ desc "The name of the host handling email for the list."
+ end
+
+ newparam(:admin) do
+ desc "The email address of the administrator."
+ end
+
+ def generate
+ if provider.respond_to?(:aliases)
+ should = self.should(:ensure) || :present
+ if should == :purged
+ should = :absent
+ end
+ atype = Puppet::Type.type(:mailalias)
+ return provider.aliases.collect do |name, recipient|
+ if atype[name]
+ nil
+ else
+ malias = Puppet::Type.type(:mailalias).create(:name => name, :recipient => recipient, :ensure => should)
+ end
+ end.compact
+ end
+ end
+ end
+end
+
+# $Id$