Изучая Puppet и Hiera, я столкнулся с препятствием. Заранее прошу прощения, если это что-то простое. Учитывая следующие файлы в моем GitLab для PuppetClass es_strat:
hiera.yaml
---
version: 5
defaults:
data_hash: yaml_data
datadir: data
hierarchy:
- name: Hostname
path: "hosts/%{facts.fqdn}.yaml"
- name: hostgroup and environments
path: "hostgroups/%{::hostgroup}/environments/%{facts.env}%{facts.env_num}.yaml"
- name: hostgroup and tier
path: "hostgroups/%{::hostgroup}/tiers/%{facts.tier}.yaml"
- name: hostgroup
path: "hostgroups/%{::hostgroup}.yaml"
- name: tier
path: "tiers/%{facts.tier}.yaml"
- name: Common
path: common.yaml
common.yaml
---
es_strat::es_heap : 16g
es_strat::es_version : 2.3.2
es_strat::kopf_version: v2.1.2
es_strat::java_version: jdk1.7.0_91
es_strat::es_instances:
"%{::hostname}":
config:
bootstrap.mlockall: "true"
cluster.name: "%{::datacenter}%{::env}%{::env_num}stratsrch"
discovery.zen.ping:
multicast:
enabled: "false"
unicast:
hosts: "%{es_masters}"
http:
compression: "true"
enabled: "true"
max_content_length: 500mb
port: "9200"
network.publish_host: "%{::ipaddress}"
network.host: "%{::ipaddress}"
node:
data: "true"
master: "true"
name: "%{::hostname}"
path.logs: /indexes/logs
transport.tcp.compress: "true"
transport.tcp.port: "9300"
indices.store.throttle.type: none
script:
indexed: "true"
udpate: "true"
datadir: /indexes/data
init.pp
# Class: es_strat
#
# This module manages es_strat
#
# Parameters: none
#
# Actions:
#
# Requires: see Modulefile
#
# Sample Usage:
#
class es_strat (
$es_heap = hiera('es_strat::es_heap'),
$es_instances = hiera('es_strat::es_instances'),
$es_version = hiera('es_strat::es_version'),
$java_version = hiera('es_strat::java_version'),
$es_hosts = hiera('es_strat::es_hosts', undef),
$kopf_version = hiera('es_strat::kopf_version', undef),
$es_scripts = hiera('es_strat::es_scripts', undef),
){
# Create Elasticsearch user with reserved UID/GID.
# TODO: Move this to virtual::users module
ensure_resource('group', 'elasticsearch', {
ensure => 'present',
forcelocal => true,
gid => 668981,
before => User['elasticsearch']
})
ensure_resource('user', 'elasticsearch', {
ensure => 'present',
comment => 'elasticsearch user',
forcelocal => true,
home => '/opt/elasticsearch',
shell => '/bin/false',
uid => 3160070,
gid => 668981,
})
# Ensure elasticsearch logs are writeable.
file { [
'/indexes/',
'/indexes/logs',
]:
ensure => directory,
owner => 'elasticsearch',
}
# Define master hosts to connect to.
if ! $es_hosts {
$query_es_nodes = query_nodes("(class['es_strat'] and env=${::env} and env_num='${::env_num}')")
$es_masters = parsejson(inline_template("[<%= @query_es_nodes.map{
|host|
\"\\\"\" + host + \":9300\\\"\"
}.flatten.join(', ')
%>]"
))
}
else {
$es_masters = $es_hosts
}
# Install elasticsearch and setup instances.
class { '::elasticsearch':
version => $es_version,
init_defaults => {
'ES_HEAP_SIZE' => $es_heap,
'JAVA_HOME' => "/opt/java/${java_version}/"
},
# Look these up again so es_masters will be included.
instances => hiera('es_strat::es_instances'),
}
# Install plugin if defined.
if $kopf_version {
elasticsearch::plugin { "lmenezes/elasticsearch-kopf/${kopf_version}":
instances => $::hostname,
proxy_host => 'repos.gspt.net',
proxy_port => 3128
}
}
# Install scripts if defined.
if $es_scripts {
create_resources(elasticsearch::script, $es_scripts)
}
# Setup Java in path so plugins work propperly.
# TODO Remove this once this bug is fixed. https://github.com/elastic/puppet-elasticsearch/issues/619
file {'/etc/sysconfig/mcollective':
content => "export JAVA_HOME=/opt/java/${java_version}/",
notify => Service['mcollective'],
}
}
Затем в Foreman я установил для хоста следующее:
es_heap=hiera("es_strat::es_heap")
es_instances=hiera("es_strat::es_instances")
es_version=hiera("es_strat::es_version")
java_version=hiera("es_strat::java_version")
Однако, когда я запускаю puppet на хосте (а именно: puppet agent -t --no-noop), я получаю следующую ошибку:
Ошибка: не удалось получить каталог с удаленного сервера: ошибка 500 на сервере: ошибка сервера: ошибка оценки: ошибка при оценке инструкции ресурса, функция lookup () не нашла значение для имени es_strat :: es_instances на узле
Выдергиваю волосы, потому что кажется, что они должны получить ценность от Хиеры. Любая / вся помощь приветствуется.
Итак, этот класс сломался при обновлении Puppet 3 до Puppet 4. Мы используем GitLab для управления нашими модулями / классами. При этом я смог получить 99% работоспособности со следующей настройкой:
данные / common.yaml
---
es_strat::es_heap : 16g
es_strat::es_version : 2.3.2
es_strat::kopf_version: v2.1.2
es_strat::java_version: jdk1.7.0_91
es_strat::es_instances:
"%{::hostname}":
config:
bootstrap:
mlockall: true
cluster:
name: "%{::datacenter}%{::env}%{::env_num}stratsrch"
discovery:
zen:
ping:
multicast:
enabled: false
unicast:
hosts: "%{es_masters}"
#hosts: "[]"
http:
compression: true
enabled: true
max_content_length: 500mb
port: 9200
indices:
store:
throttle:
type: none
network:
host: "%{::ipaddress}"
publish_host: "%{::ipaddress}"
node:
data: true
master: true
name: "%{::hostname}"
path:
data: /indexes/data
logs: /indexes/logs
repo: /nfs/lvs/elasticsearch/snapshots/stratsrch
script:
indexed: true
udpate: true
transport:
tcp:
compress: true
port: 9300
# datadir: /indexes/data
#"es_strat::es_scripts":
# test:
# source: "puppet:///modules/es_strat/%{::tier}/test.groovy"
манифесты / init.pp
# Class: es_strat
#
# This module manages es_strat
#
# Parameters: none
#
# Actions:
#
# Requires: see Modulefile
#
# Sample Usage:
#
class es_strat (
$es_heap = $::es_strat::es_heap,
$es_instances = undef,
$es_version = $::es_strat::es_version,
$java_version = $::es_strat::java_version,
$es_hosts = undef,
$kopf_version = $::es_strat::kopf_version,
$es_scripts = undef,
){
# Create Elasticsearch user with reserved UID/GID.
# TODO: Move this to virtual::users module
ensure_resource('group', 'elasticsearch', {
ensure => 'present',
forcelocal => true,
gid => 668981,
before => User['elasticsearch']
})
ensure_resource('user', 'elasticsearch', {
ensure => 'present',
comment => 'elasticsearch user',
forcelocal => true,
home => '/opt/elasticsearch',
shell => '/bin/false',
uid => 3160070,
gid => 668981,
})
# Ensure elasticsearch logs are writeable.
file { [
'/indexes/',
'/indexes/logs',
]:
ensure => directory,
owner => 'elasticsearch',
}
# Define master hosts to connect to.
if ! $es_hosts {
$query_es_nodes = query_nodes("(class['es_strat'] and datacenter=${::datacenter} and env=${::env} and env_num=${::env_num})")
$es_masters = parsejson(inline_template("[<%= @query_es_nodes.map{
|host|
\"\\\"\" + host + \":9300\\\"\"
}.flatten.join(', ')
%>]"
))
}
else {
$es_masters = $es_hosts
}
# Install elasticsearch and setup instances.
class { '::elasticsearch':
version => $es_version,
init_defaults => {
'ES_HEAP_SIZE' => $es_heap,
'JAVA_HOME' => "/opt/java/${java_version}/"
},
# Look these up again so es_masters will be included.
instances => $::es_strat::es_instances,
}
# Install plugin if defined.
if $kopf_version {
elasticsearch::plugin { "lmenezes/elasticsearch-kopf/${kopf_version}":
instances => $::hostname,
proxy_host => 'repos.gspt.net',
proxy_port => 3128
}
}
# Install scripts if defined.
if $es_scripts {
create_resources(elasticsearch::script, $es_scripts)
}
# Setup Java in path so plugins work propperly.
# TODO Remove this once this bug is fixed. https://github.com/elastic/puppet-elasticsearch/issues/619
file {'/etc/sysconfig/mcollective':
content => "export JAVA_HOME=/opt/java/${java_version}/",
notify => Service['mcollective'],
}
}
Прямо сейчас единственная часть, которая не работает, - это автоматическое создание списка других хостов, которые будут в кластере.