Skip to content
This repository was archived by the owner on Mar 3, 2023. It is now read-only.

Commit

Permalink
cortex: add ElasticSearch index creation
Browse files Browse the repository at this point in the history
Signed-off-by: Jakub Sokołowski <[email protected]>
  • Loading branch information
jakubgs committed Oct 22, 2020
1 parent 38a8ef7 commit 04699b5
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
4 changes: 4 additions & 0 deletions ansible/roles/cortex/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ cortex_version: '3.1.0-RC1'
cortex_binary_url: 'https://status-misc.ams3.digitaloceanspaces.com/cortex-{{ cortex_version }}.zip'
cortex_binary_md5: '56ca44fc059b6c094ea2605994948bcb'

# Database
# WARNING: Name changes with versions!
cortex_index_name: 'cortex_4'

# Paths
cortex_install_path: '/opt/{{ cortex_service_name }}'
cortex_conf_path: '/etc/cortex'
Expand Down
20 changes: 20 additions & 0 deletions ansible/roles/cortex/tasks/index.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
- name: Create the ElasticSearch index
uri:
url: 'http://{{ cortex_search_nodes[0].addr }}:{{ cortex_search_nodes[0].port }}/{{ cortex_index_name }}'
method: 'PUT'
return_content: true
status_code: [ 201, 400 ]
register: es_resp

- name: Verify that index was creates
assert:
that: '{{ es_resp.json["acknowledged"] == true }}'
fail_msg: 'Failed to create ElasticSearch index: {{ cortex_index_name }}'
when: es_resp.status == 201

- name: Verify that index already exists
assert:
that: '{{ es_resp.json["error"]["type"] == "resource_already_exists_exception" }}'
fail_msg: 'Failed to create ElasticSearch index: {{ cortex_index_name }}'
when: es_resp.status == 400
7 changes: 5 additions & 2 deletions ansible/roles/cortex/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@
- name: Create config files
import_tasks: config.yml

- name: Create systemd service
- name: Create ElasticSearch Index
import_tasks: index.yml

- name: Create Systemd service
import_tasks: service.yml

- name: Create consul definition
- name: Create Consul definition
import_tasks: consul.yml

0 comments on commit 04699b5

Please sign in to comment.