Rewrite ES config states to pyobjects, support many data dirs

This commit is contained in:
Antsiferov Grigory 2018-11-15 14:32:06 +03:00
parent 7858784019
commit 09e1dc995b
2 changed files with 24 additions and 17 deletions

View File

@ -1,22 +1,23 @@
#!pydsl
#!pyobjects
# -*- mode: python -*-
from salt.utils import dictupdate
import yaml
state('/etc/elasticsearch/').file.directory(
File.directory(
'/etc/elasticsearch/',
create=True, mode=755, user='root', group='root')
fqdn = __salt__['grains.get']('fqdn')
fqdn_ipv6 = __salt__['grains.get']('fqdn_ipv6')
hosts = __salt__['pillar.get']('elastic:hosts', [])
fqdn = grains('fqdn')
fqdn_ipv6 = grains('fqdn_ipv6')
hosts = pillar('elastic:hosts', [])
limits = __salt__['pillar.get']('elastic:limits', {})
limits = pillar('elastic:limits', {})
l_nofile = limits.get('nofile', 1048576)
l_memlock = limits.get('memlock', 'unlimited')
max_map_count = limits.get('max_map_count', 262144)
max_threads = limits.get('max_threads', 4096)
jvm = __salt__['pillar.get']('elastic:jvm', {})
jvm = pillar('elastic:jvm', {})
jvm_heap_size = jvm.get('heap_size', '1g')
jvm_stack_size = jvm.get('stack_size', '1m')
jvm_extra_options = jvm.get('extra_options', {})
@ -28,10 +29,6 @@ config = {
'master': False, 'data': False, 'ingest': False,
'max_local_storage_nodes': 1,
},
'path': {
'data': '/var/lib/elasticsearch',
'logs': '/var/log/elasticsearch',
},
'bootstrap': {'memory_lock': True},
'network': { 'host': '${HOSTNAME}' },
'http': { 'port': 9200 },
@ -45,25 +42,29 @@ config = {
config['discovery']['zen']['ping']['unicast']['hosts'] = filter(
lambda x: x != fqdn and x not in fqdn_ipv6,
hosts)
dictupdate.update(config, __pillar__['elastic']['config'])
dictupdate.update(config, pillar('elastic:config'))
state('/etc/elasticsearch/elasticsearch.yml').file.managed(
File.managed(
'/etc/elasticsearch/elasticsearch.yml',
mode=644, user='root', group='root',
contents="# This file is generated by Salt\n" + yaml.dump(config))
state('/etc/elasticsearch/jvm.options').file.managed(
File.managed(
'/etc/elasticsearch/jvm.options',
mode=644, user='root', group='root',
template='jinja', source='salt://elasticsearch/files/jvm.options.tpl',
defaults={'heap_size': jvm_heap_size, 'stack_size': jvm_stack_size,
'extra_options': jvm_extra_options})
state('/etc/conf.d/elasticsearch').file.managed(
File.managed(
'/etc/conf.d/elasticsearch',
mode=644, user='root', group='root',
template='jinja', source="salt://elasticsearch/files/elasticsearch.confd.tpl",
defaults={'es_java_opts': '', 'l_nofile': l_nofile, 'l_memlock': l_memlock,
'max_map_count': max_map_count, 'max_threads': max_threads, 'es_startup_sleep_time': 10})
state('/etc/security/limits.d/elasticsearch.conf').file.managed(
File.managed(
'/etc/security/limits.d/elasticsearch.conf',
mode=644, user='root', group='root',
contents='\n'.join([
"elasticsearch soft nofile {0}".format(l_nofile),

View File

@ -9,7 +9,13 @@
CONF_DIR=/etc/elasticsearch
# Elasticsearch data directory
DATA_DIR=/var/lib/elasticsearch
{% set data_path = '/var/lib/elasticsearch' %}
{% set data_count = salt['pillar.get']('elastic:data-dir-count', False) %}
{% if data_dir_count %}
DATA_DIR="{{ ','.join([data_path + '/data' + str(i) for i in range(0, data_count)]) }}"
{% else %}
DATA_DIR="{{ data_path }}"
{% endif %}
# Elasticsearch logs directory
LOG_DIR=/var/log/elasticsearch