2015-10-22 19:09:53 +01:00
---
# Configure Elasticsearch Node
2015-11-25 15:28:09 +00:00
- set_fact : pid_dir={{es_pid_dir}}/{{inventory_hostname}}-{{ es_instance_name }}
- set_fact : data_dir={{ es_data_dir }}/{{inventory_hostname}}-{{ es_instance_name }}
- set_fact : log_dir={{ es_log_dir }}/{{inventory_hostname}}-{{ es_instance_name }}
- set_fact : work_dir={{ es_work_dir }}/{{inventory_hostname}}-{{ es_instance_name }}
2015-10-22 19:09:53 +01:00
# Create an instance specific default file
- name : Copy Default File for Instance
command : creates={{instance_default_file}} cp "{{default_file}}" "{{instance_default_file}}"
when : instance_default_file != default_file
# Create an instance specific init file
- name : Copy Init File for Instance
command : creates={{instance_init_script}} cp "{{init_script}}" "{{instance_init_script}}"
when : instance_init_script != init_script
#Create Config directory
- name : Create Config Directory
file : path={{ instance_config_directory }} state=directory owner={{ es_user }} group={{ es_group }}
#Copy the config template
- name : Copy configuration file
template : src=elasticsearch.yml.j2 dest={{instance_config_directory}}/elasticsearch.yml owner={{ es_user }} group={{ es_group }} mode=0644 force=yes
# Apply changes to the default file for this instance
- name : Configure config directory
lineinfile : dest={{instance_default_file}} regexp="^CONF_DIR" insertafter="^#CONF_DIR" line="CONF_DIR={{ instance_config_directory }}"
register : elasticsearch_configure
- name : Configure config file
lineinfile : dest={{instance_default_file}} regexp="^CONF_FILE" insertafter="^#CONF_FILE" line="CONF_FILE={{ instance_config_directory }}/elasticsearch.yml"
register : elasticsearch_configure
- name : Configure memory in defaults
lineinfile : dest={{instance_default_file}} regexp="^ES_HEAP_SIZE" insertafter="^#ES_HEAP_SIZE" line="ES_HEAP_SIZE={{ es_heap_size }}"
when : es_heap_size is defined
register : elasticsearch_configure
#We only have to set these if they are specified. The start scripts will by default use the NAME set later on constructing directory names to avoid collisions.
- name : Configure max open files
lineinfile : dest={{instance_default_file}} regexp="^MAX_OPEN_FILES" insertafter="^#MAX_OPEN_FILES" line="MAX_OPEN_FILES={{ es_max_open_files }}"
when : es_max_open_files is defined
register : elasticsearch_configure
2015-11-25 15:28:09 +00:00
#For directories we also use the {{inventory_hostname}}-{{ es_instance_name }} - this helps if we have a shared SAN.
2015-10-22 19:09:53 +01:00
#Create PID directory
- name : Create PID Directory
2015-11-25 15:28:09 +00:00
file : path={{ pid_dir }} state=directory owner={{ es_user }} group={{ es_group }}
2015-10-22 19:09:53 +01:00
- name : Configure PID directory
2015-11-25 15:28:09 +00:00
lineinfile : dest={{instance_default_file}} regexp="^PID_DIR" insertafter="^#PID_DIR" line="PID_DIR={{ pid_dir }}"
2015-10-22 19:09:53 +01:00
register : elasticsearch_configure
#include the host name as potentially shared SAN
- name : Create data dir
2015-11-25 15:28:09 +00:00
file : state=directory path={{ data_dir }} owner={{ es_user }} group={{ es_group }}
2015-10-22 19:09:53 +01:00
- name : Configure data store
2015-11-25 15:28:09 +00:00
lineinfile : dest={{instance_default_file}} regexp="^DATA_DIR" insertafter="^#DATA_DIR" line="DATA_DIR={{ data_dir }}"
2015-10-22 19:09:53 +01:00
register : elasticsearch_configure
- name : Create work dir
2015-11-25 15:28:09 +00:00
file : state=directory path={{ work_dir }} owner={{ es_user }} group={{ es_group }}
2015-10-22 19:09:53 +01:00
- name : Configure work directory
2015-11-25 15:28:09 +00:00
lineinfile : dest={{instance_default_file}} regexp="^WORK_DIR" insertafter="^#WORK_DIR" line="WORK_DIR={{ work_dir }}"
2015-10-22 19:09:53 +01:00
register : elasticsearch_configure
- name : Create log dir
2015-11-25 15:28:09 +00:00
file : state=directory path={{ log_dir }} owner={{ es_user }} group={{ es_group }}
2015-10-22 19:09:53 +01:00
- name : Configure log directory
2015-11-25 15:28:09 +00:00
lineinfile : dest={{instance_default_file}} regexp="^LOG_DIR" insertafter="^#LOG_DIR" line="LOG_DIR={{ log_dir }}"
2015-10-22 19:09:53 +01:00
register : elasticsearch_configure
#required so that the ES_HOME does not change between instances
- name : Configure elasticsearch home
lineinfile : dest={{instance_default_file}} regexp="^ES_HOME" insertafter="^#ES_HOME" line="ES_HOME={{es_home}}"
register : elasticsearch_configure
- name : Configure elasticsearch user
lineinfile : dest={{instance_default_file}} regexp="^ES_USER" insertafter="^#ES_USER" line="ES_USER={{ es_user }}"
when : es_user is defined
register : elasticsearch_configure
- name : Configure elasticsearch group
lineinfile : dest={{instance_default_file}} regexp="^ES_GROUP" insertafter="^#ES_GROUP" line="ES_GROUP={{ es_group }}"
when : es_group is defined
register : elasticsearch_configure
#Apply changes to init script - NAME can be changed in Debian start script
- name : Name Node in Init Script
2015-11-25 15:28:09 +00:00
lineinfile : dest={{instance_init_script}} regexp="^NAME" line="NAME={{es_instance_name}}_{{default_file | basename}}"
2015-10-22 19:09:53 +01:00
register : elasticsearch_configure
when : ansible_os_family == 'Debian'
- debug : msg="For {{ instance_init_script }} using default {{ instance_default_file }}"
- name : Environment in Init Script
lineinfile : dest={{instance_init_script}} regexp="^ES_ENV_FILE" line="ES_ENV_FILE={{instance_default_file}}"
register : elasticsearch_configure
when : ansible_os_family == 'RedHat'
2015-11-25 23:43:01 +00:00
#Copy the logging.yml - TODO: i.e we may template this.
- name : Copy Logging.yml for Instance
command : creates={{instance_config_directory}}/logging.yml cp "{{ es_conf_dir }}/logging.yml" "{{instance_config_directory}}/logging.yml"
when : instance_init_script != init_script
- file : path={{instance_config_directory}}/logging.yml state=touch owner={{ es_user }} group={{ es_group }}