-
-
Notifications
You must be signed in to change notification settings - Fork 599
/
provider_plugin.rb
49 lines (38 loc) · 1.71 KB
/
provider_plugin.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
require 'poise'
class Chef
class Provider::ElasticsearchPlugin < Provider
include Poise
include ElasticsearchCookbook::Helpers
include Chef::Mixin::ShellOut
def action_install
name = new_resource.plugin_name
version = new_resource.version ? "/#{new_resource.version}" : nil
url = new_resource.url ? " -url #{new_resource.url}" : nil
# nasty workaround to find a nice default for plugin dir
unless new_resource.plugin_dir
found_installs = run_context.resource_collection.select { |r| r.instance_variable_get(:@resource_name) == :elasticsearch_install }
unless found_installs.empty?
install_resource = found_installs.first
es_version = install_resource.instance_variable_get(:@version)
es_dir = get_tarball_root_dir(install_resource, node)
new_resource.plugin_dir "#{es_dir}/elasticsearch-#{es_version}/plugins"
end
end
raise 'Could not determine the plugin directory. Please set plugin_dir on this resource.' unless new_resource.plugin_dir
return if Dir.entries(new_resource.plugin_dir).any? do |plugin|
next if plugin =~ /^\./
name.include? plugin
end rescue false
directory new_resource.plugin_dir do
owner new_resource.user
group new_resource.group
mode 0755
recursive true
end
# automatically raises on error, logs command output
shell_out!("#{new_resource.bindir}/plugin -install #{name}#{version}#{url}".split(' '))
# Ensure proper permissions
shell_out!("chown -R #{new_resource.user}:#{new_resource.group} #{new_resource.plugin_dir}".split(' '))
end # action
end # provider
end # chef class