Skip to content

Instantly share code, notes, and snippets.

@jedi4ever
Created January 16, 2012 08:40
Show Gist options
  • Save jedi4ever/1619758 to your computer and use it in GitHub Desktop.
Save jedi4ever/1619758 to your computer and use it in GitHub Desktop.
rabbitmq - plugins - puppet - provider
rabbitmq_plugin { $rabbitmq_plugin_list:
ensure => present,
require => Class['rabbitmq::server'],
provider => 'rabbitmq_plugins',
state => enabled
}
require 'puppet'
Puppet::Type.type(:rabbitmq_plugin).provide(:rabbitmq_plugins) do
commands :rabbitmq_plugins => 'rabbitmq-plugins'
defaultfor :feature => :posix
def self.instances
raise Puppet::Error, "instances"
rabbitmq_plugins('list','-m').split(/\n/).collect do |line|
new(:name => line)
end
end
def create
raise Puppet::Error, "No way currently to create plugins"
end
def destroy
raise Puppet::Error, "No way currently to destroy plugins"
end
def exists?
rabbitmq_plugins('list','-m').split(/\n/).include?(resource[:name])
end
def enabled?
out = rabbitmq_plugins('list','-m','-e').split(/\n/).detect do |line|
line.match(/^#{resource[:name]}$/)
end
end
def state=(newstate)
raise Puppet::Error, "state setter called"
rabbitmq_plugins('enable', resource[:name])
end
def state
raise Puppet::Error, "state getter called"
end
def enable_plugin
rabbitmq_plugins('enable', resource[:name])
end
def disable_plugin
rabbitmq_plugins('disable', resource[:name])
end
end
Puppet::Type.newtype(:rabbitmq_plugin) do
desc 'Native type for managing rabbitmq plugins'
ensurable do
defaultto(:present)
newvalue(:present) do
provider.create
end
newvalue(:absent) do
provider.destroy
end
end
newparam(:name, :namevar => true) do
desc 'Name of plugin'
newvalues(/^\S+$/)
end
newparam(:state) do
desc 'State of plugin'
newvalues(:enabled,:disabled)
end
validate do
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment