# Install ElasticSearch plugin
#
define :install_plugin do

  bash "/usr/local/bin/plugin -install #{params[:name]}" do
    user "root"
    code "/usr/local/bin/plugin -install #{params[:name]}"

    notifies :restart, resources(:service => 'elasticsearch')

    not_if do
      Dir.entries("#{node.elasticsearch[:dir]}/elasticsearch-#{node.elasticsearch[:version]}/plugins/").any? do |plugin|
        params[:name].include? plugin
      end
    end

  end
  
end

# Install ElasticSearch plugin
#
define :install_plugin do

  bash "/usr/local/bin/plugin -install #{params[:name]}" do
    user "root"
    code "/usr/local/bin/plugin -install #{params[:name]}"

    notifies :restart, resources(:service => 'elasticsearch')

    not_if do
      Dir.entries("#{node.elasticsearch[:dir]}/elasticsearch-#{node.elasticsearch[:version]}/plugins/").any? do |plugin|
        params[:name].include? plugin
      end rescue false
    end

  end
  
end

Fix a failed provisioning where `$ES_HOME/plugins` does not exist on the first run
[FIX] Fix a failed provisioning where `$ES_HOME/plugins` does not exist on the first run
