Skip to content

Instantly share code, notes, and snippets.

@shanestillwell
Created May 31, 2013 19:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shanestillwell/5687491 to your computer and use it in GitHub Desktop.
Save shanestillwell/5687491 to your computer and use it in GitHub Desktop.
Puppet::Type.type(:a2mod).provide(:amazon) do
desc "Manage Apache 2 modules on Amazon OS"
confine :operatingsystem => :amazon
defaultfor :operatingsystem => :amazon
require 'pathname'
# modpath: Path to default apache modules directory /etc/httpd/mod.d
# modfile: Path to module load configuration file; Default: resides under modpath directory
# libfile: Path to actual apache module library. Added in modfile LoadModule
attr_accessor :modfile, :libfile
class << self
attr_accessor :modpath
def preinit
@modpath = "/etc/httpd/mod.d"
end
end
self.preinit
def create
File.open(modfile,'w') do |f|
f.puts "LoadModule #{resource[:identifier]} #{libfile}"
end
end
def destroy
File.delete(modfile)
end
def exists?
File.exists?(modfile) and File.read(modfile).match(libfile)
end
def self.instances
modules = []
Dir.glob("#{modpath}/*.load").each do |file|
m = file.match(/(\w+)\.load$/)
modules << m[1] if m
end
modules.map do |mod|
new(
:name => mod,
:ensure => :present,
:provider => :redhat
)
end
end
def modfile
modfile ||= "#{self.class.modpath}/#{resource[:name]}.load"
end
# Set libfile path: If absolute path is passed, then maintain it. Else, make it default from 'modules' dir.
def libfile
libfile = Pathname.new(resource[:lib]).absolute? ? resource[:lib] : "modules/#{resource[:lib]}"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment