Puppet

傀儡沒有拉動希拉的價值

  • October 6, 2017

學習 Puppet 和 Hiera,我遇到了障礙。如果這很簡單,我提前道歉。在我的 GitLab 中為 PuppetClass es_strat 提供以下文件:

傷口.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

初始化程序

# 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 中,我為 Host 設置了以下內容:

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:伺服器錯誤:評估錯誤:評估資源語句時出錯,函式查找()在節點上找不到名稱“es_strat::es_instances”的值

拔掉我的頭髮,因為它似乎應該能夠從 Hiera 那裡獲得價值。非常感謝任何/所有幫助。

好的,所以這個類隨著從 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'],
 }
}

現在,唯一不工作的部分是自動生成將在集群中的其他主機列表。

引用自:https://serverfault.com/questions/876684