diff --git a/handlers/elasticsearch-templates.yml b/handlers/elasticsearch-templates.yml index 9c46eed..797ec62 100644 --- a/handlers/elasticsearch-templates.yml +++ b/handlers/elasticsearch-templates.yml @@ -10,7 +10,25 @@ shell: find . -maxdepth 1 -type f | sed "s#\./##" | sed "s/.json//" chdir=/etc/elasticsearch/templates register: resultstemplate -#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 }}" \ No newline at end of file +- name: Install templates without auth + uri: + url: http://{{es_api_host}}:{{es_api_port}}/_template/{{item}} + method: PUT + status_code: 200 + body_format: json + body: "{{ lookup('file', '/etc/elasticsearch/templates/'+item+'.json') }}" + when: not es_enable_xpack or not es_xpack_features is defined or not '"shield" in es_xpack_features' + with_items: "{{ resultstemplate.stdout_lines }}" + +- name: Install templates with auth + uri: + url: http://{{es_api_host}}:{{es_api_port}}/_template/{{item}} + method: PUT + status_code: 200 + user: "{{es_api_basic_auth_username}}" + password: "{{es_api_basic_auth_password}}" + force_basic_auth: yes + body_format: json + body: "{{ lookup('file', '/etc/elasticsearch/templates/'+item+'.json') }}" + when: es_enable_xpack and es_xpack_features is defined and '"shield" in es_xpack_features' + with_items: "{{ resultstemplate.stdout_lines }}" diff --git a/test/integration/helpers/serverspec/xpack_spec.rb b/test/integration/helpers/serverspec/xpack_spec.rb index 57117e6..69583ed 100644 --- a/test/integration/helpers/serverspec/xpack_spec.rb +++ b/test/integration/helpers/serverspec/xpack_spec.rb @@ -195,6 +195,14 @@ shared_examples 'xpack::init' do |es_version| end end + #This is possibly subject to format changes in the response across versions so may fail in the future + describe 'Template Contents Correct' do + it 'should be reported as being installed', :retry => 3, :retry_wait => 10 do + command = command('curl -s "localhost:9200/_template/basic" -u es_admin:changeMe | md5sum') + expect(command.stdout).to match(/153b1a45daf48ccee80395b85c61e332/) + end + end + #Test contents of Elasticsearch.yml file describe file('/etc/elasticsearch/shield_node/elasticsearch.yml') do it { should contain 'shield.authc.realms.file1.order: 0' }