diff --git a/.travis.yml b/.travis.yml index 0bb6bdf..aa17d24 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,6 @@ language: ruby rvm: - - 1.9.3 + - 2.1.6 env: - USE_SYSTEM_GECODE=1 before_install: diff --git a/chefignore b/chefignore index 96ccf87..6cc426f 100644 --- a/chefignore +++ b/chefignore @@ -90,3 +90,7 @@ Vagrantfile # Travis # ########## .travis.yml + +# Kitchen # +########### +.kitchen diff --git a/libraries/plugins.rb b/libraries/plugins.rb new file mode 100644 index 0000000..5821169 --- /dev/null +++ b/libraries/plugins.rb @@ -0,0 +1,90 @@ +# Encoding: utf-8 +# Cookbook Name:: kibana +# Resrouce/Provider:: plugins +# Author:: John E. Vincent +# Author:: Paul Czarkowski +# License:: Apache 2.0 +# +# Copyright 2014, John E. Vincent + +class Chef + class Resource::KibanaPlugin < Chef::Resource::LWRPBase + provides :kibana_plugin + actions(:create, :remove) + default_action(:create) + + attribute(:name, kind_of: String, name_attribute: true) + attribute(:base_directory, kind_of: String, default: lazy { node['kibana']['version'] }) + attribute(:version, kind_of: String, default: lazy { node['kibana']['plugins_version'] }) + attribute(:checksum, kind_of: String, default: lazy { node['kibana']['plugins_checksum'] }) + attribute(:source_url, kind_of: String, default: lazy { node['kibana']['plugins_source_url'] }) + attribute(:user, kind_of: String, default: lazy { node['kibana']['user'] }) + attribute(:group, kind_of: String, default: lazy { node['kibana']['group'] }) + attribute(:install_dir, kind_of: String, default: lazy { node['kibana']['install_dir'] }) + attribute(:install_type, kind_of: String, default: lazy { node['kibana']['plugins_install_type'] }) + attribute(:install_check, kind_of: String, default: lazy { node['kibana']['plugins_check_if_installed'] }) + end + + class Provider::KibanaPlugin < Chef::Provider::LWRPBase # ~FC057, ~FC058 + provides :kibana_plugin + include Chef::DSL::Recipe # required under chef 12, see poise/poise #8 + + action :create do + kb_args = kibana_resources + + case kb_args[:install_type] + when 'native' + ex = execute "bin/kibana plugin --install #{kb_args[:name]}" do + command "bin/kibana plugin --install #{kb_args[:name]}" + user kb_args[:user] + group kb_args[:group] + cwd "#{kb_args[:install_dir]}/kibana-#{kb_args[:base_directory]}" + notifies :restart, 'service[kibana]' + timeout 600 + # this is a temp workaround to make the plugin command idempotent. + not_if { ::File.exist?("#kb_args[:install_dir]}/#{kb_args[:install_check]}") } + end + new_resource.updated_by_last_action(ex.updated_by_last_action?) + when 'tarball' + @run_context.include_recipe 'ark::default' + arkit = ark "#{kb_instance}_contrib" do + name kb_args[:kb_instance] + url kb_args[:kb_source_url] + checksum kb_args[:kb_checksum] + owner kb_args[:kb_user] + group kb_args[:kb_group] + mode 0755 + version kb_args[:kb_version] + path kb_args[:kb_basedir] + action [:put] + notifies :restart, 'service[kibana]' + # this is a temp workaround to ensure idempotent. + not_if { ::File.exist?("#{kb_args[:install_dir]}/#{kb_args[:install_check]}") } + end + new_resource.updated_by_last_action(arkit.updated_by_last_action?) + else + Chef::Application.fatal!("Unknown install type: #{kb_args[:install_type]}") + end # case + end # action + + action :remove do + Chef::Log.warn('Kibana plugin removal is not supported!') + end # action + + private + + def kibana_resources + kb = { + name: new_resource.name, + user: new_resource.user, + group: new_resource.group, + install_dir: new_resource.install_dir, + install_type: new_resource.install_type, + base_directory: new_resource.base_directory, + version: new_resource.version, + checksum: new_resource.checksum + } + kb + end # def + end # end class +end # end classes diff --git a/test/fixtures/kibana_test/recipes/default.rb b/test/fixtures/kibana_test/recipes/default.rb index c093bd4..5c1bfea 100644 --- a/test/fixtures/kibana_test/recipes/default.rb +++ b/test/fixtures/kibana_test/recipes/default.rb @@ -2,6 +2,12 @@ include_recipe 'elasticsearch::default' include_recipe 'kibana_lwrp::install' +# sample plugin installation +kibana_plugin 'kibana/timelion' do + install_type 'native' + action [:create] +end + elasticsearch_service 'elasticsearch' do action :start end