Skip to content

Commit

Permalink
Add a custom fact for rabbitmq's plugins folder
Browse files Browse the repository at this point in the history
If you want to add third party plugins with puppet you need to know
where the plugins folder is located.
This can differ depending on rabbitmq version or OS.
  • Loading branch information
TomRitserveldt committed Feb 13, 2019
1 parent 5283ed8 commit 902d9b4
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/facter/rabbitmq_plugins_dirs.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Facter.add(:rabbitmq_plugins_dirs) do
setcode do
if Facter::Util::Resolution.which('rabbitmqctl')
rabbitmq_pluginsdirs_env = Facter::Core::Execution.execute("rabbitmqctl eval 'application:get_env(rabbit, plugins_dir).'")
rabbitmq_plugins_dirs = %r{^\{ok\,\"(\/.+\/\w+)}.match(rabbitmq_pluginsdirs_env)[1]
rabbitmq_plugins_dirs.split(':')
end
end
end
39 changes: 39 additions & 0 deletions spec/unit/facter/util/fact_rabbitmq_plugins_dirs_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
require 'spec_helper'

describe Facter::Util::Fact do
before { Facter.clear }

describe 'rabbitmq_plugins_dirs' do
context 'with multiple plugins dirs' do
it do
Facter::Util::Resolution.expects(:which).with('rabbitmqctl').returns(true)
Facter::Core::Execution.expects(:execute).with("rabbitmqctl eval 'application:get_env(rabbit, plugins_dir).'").returns('{ok,"/usr/lib/rabbitmq/plugins:/usr/lib/rabbitmq/lib/rabbitmq_server-3.7.10/plugins"}')
expect(Facter.fact(:rabbitmq_plugins_dirs).value).to match_array(
[
'/usr/lib/rabbitmq/plugins',
'/usr/lib/rabbitmq/lib/rabbitmq_server-3.7.10/plugins'
]
)
end
end

context 'with only 1 plugins dir' do
it do
Facter::Util::Resolution.expects(:which).with('rabbitmqctl').returns(true)
Facter::Core::Execution.expects(:execute).with("rabbitmqctl eval 'application:get_env(rabbit, plugins_dir).'").returns('{ok,"/usr/lib/rabbitmq/lib/rabbitmq_server-0.0.0/plugins"}')
expect(Facter.fact(:rabbitmq_plugins_dirs).value).to match_array(
[
'/usr/lib/rabbitmq/lib/rabbitmq_server-0.0.0/plugins'
]
)
end
end

context 'rabbitmqctl is not in path' do
it do
Facter::Util::Resolution.expects(:which).with('rabbitmqctl').returns(false)
expect(Facter.fact(:rabbitmq_plugins_dirs).value).to be_nil
end
end
end
end

0 comments on commit 902d9b4

Please sign in to comment.