Created
May 31, 2013 19:44
-
-
Save shanestillwell/5687491 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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