From d3d9bbca1727aa4241002dbd9fb66a87ce7fec5f Mon Sep 17 00:00:00 2001 From: Dale McDiarmid Date: Sat, 23 Jul 2016 20:18:58 +0100 Subject: [PATCH] Templates load user credentials if provided --- tasks/elasticsearch-parameters.yml | 2 +- tasks/elasticsearch-templates.yml | 10 +++++++--- test/integration/helpers/serverspec/multi_spec.rb | 2 +- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/tasks/elasticsearch-parameters.yml b/tasks/elasticsearch-parameters.yml index 3e8281a..c05b81d 100644 --- a/tasks/elasticsearch-parameters.yml +++ b/tasks/elasticsearch-parameters.yml @@ -23,7 +23,7 @@ #Check if working with shield we have an es_api_basic_auth_username and es_api_basic_auth_username - otherwise any http calls wont work - fail: msg="Enabling shield requires an es_api_basic_auth_username and es_api_basic_auth_password to be provided to allow cluster operations" - when: es_enable_xpack and '"shield" in es_xpack_features' and es_api_basic_auth_username is not defined and es_api_basic_auth_username is not defined + when: es_enable_xpack and '"shield" in es_xpack_features' and es_api_basic_auth_username is not defined and es_api_basic_auth_password is not defined - set_fact: instance_default_file={{default_file | dirname}}/{{es_instance_name}}_{{default_file | basename}} - set_fact: instance_init_script={{init_script | dirname }}/{{es_instance_name}}_{{init_script | basename}} diff --git a/tasks/elasticsearch-templates.yml b/tasks/elasticsearch-templates.yml index 8d5aaf0..7649215 100644 --- a/tasks/elasticsearch-templates.yml +++ b/tasks/elasticsearch-templates.yml @@ -22,6 +22,10 @@ shell: find . -maxdepth 1 -type f | sed "s#\./##" | sed "s/.json//" chdir=/etc/elasticsearch/templates register: resultstemplate -- name: Install template(s) - command: "curl -sL -XPUT http://{{es_api_host}}:{{es_api_port}}/_template/{{item}} -d @/etc/elasticsearch/templates/{{item}}.json" - with_items: "{{ resultstemplate.stdout_lines }}" \ No newline at end of file +#The basic auth details here may not be required - send always if they are defined. If not needed they will be ignored. +- name: Install template(s) with auth + command: "curl -sL -XPUT http://{{es_api_host}}:{{es_api_port}}/_template/{{item}} -d @/etc/elasticsearch/templates/{{item}}.json {% if es_api_basic_auth_username is defined and es_api_basic_auth_password is defined%}-u {{es_api_basic_auth_username}}:{{es_api_basic_auth_password}}{% endif %}" + with_items: "{{ resultstemplate.stdout_lines }}" + +#Suppose user removes shield on a running node, doesn't specify es_api_basic_auth_username and es_api_basic_auth_password. The templates will subsequently not be removed. +#Templates should probably be done after a restart therefore - as a handler. \ No newline at end of file diff --git a/test/integration/helpers/serverspec/multi_spec.rb b/test/integration/helpers/serverspec/multi_spec.rb index ee37abd..4d2cc2f 100644 --- a/test/integration/helpers/serverspec/multi_spec.rb +++ b/test/integration/helpers/serverspec/multi_spec.rb @@ -182,7 +182,7 @@ shared_examples 'multi::init' do |es_version,plugins| describe command('curl -s localhost:9201/_nodes/plugins?pretty=true | grep '+plugin) do its(:exit_status) { should eq 0 } end - + describe file('/usr/share/elasticsearch/plugins/'+plugin) do it { should be_directory } it { should be_owned_by 'elasticsearch' }