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 dff496b
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/facter/rabbitmq_plugins_dirs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@
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)
if rabbitmq_plugins_dirs_match then
rabbitmq_plugins_dirs_match[1].split(':')
else
nil
end
end
end
end

0 comments on commit dff496b

Please sign in to comment.