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 27, 2019
1 parent 5477e69 commit 348c3ba
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/facter/rabbitmq_plugins_dirs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
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
rabbitmq_plugins_dirs_match[1].split(':')
end
end
end
end

0 comments on commit 348c3ba

Please sign in to comment.