Skip to content

Commit

Permalink
Don't crash on rabbitmq_plugins_dirs fact if rabbitmqctl is not present
Browse files Browse the repository at this point in the history
Before trying to access the contents of a regexp match, see if the
match was successful. On machines without rabbitmqctl this match will
return `nil`, so we can't index it with `[1]`. When that's the case,
the whole rabbitmq_plugins_dirs fact value will now be `nil`, instead
of throwing an exception.

Fixes: voxpupuli#783
  • Loading branch information
jistr committed Mar 26, 2019
1 parent 5477e69 commit 47dbb24
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions lib/facter/rabbitmq_plugins_dirs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,18 @@
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(':')
rabbitmq_plugins_dirs_match = %r{^\{ok\,\"(\/.+\/\w+)}.match(rabbitmq_pluginsdirs_env)
rabbitmq_plugins_dirs_str = if rabbitmq_plugins_dirs_match then
rabbitmq_plugins_dirs_match[1]
else
''
end
rabbitmq_plugins_dirs = rabbitmq_plugins_dirs_str.split(':')
if rabbitmq_plugins_dirs.empty?
nil
else
rabbitmq_plugins_dirs
end
end
end
end

0 comments on commit 47dbb24

Please sign in to comment.