簡體   English   中英

create_resources-無法將字符串轉換為哈希

[英]create_resources - can't convert String into Hash

我正在使用來自的Elasticsearch-logstash模塊

https://forge.puppetlabs.com/elasticsearch/logstash

這就是我的希拉的樣子...

---
classes:
  - 'profile::logstash'


profile::logstash::conf:
  package_url: "https://download.elasticsearch.org/logstash/logstash/packages/centos/logstash-contrib-1.4.2-1_efd53ef.noarch.rpm"

這是配置文件中的logstash.pp

class profile::logstash {

  $conf   = hiera('profile::logstash::conf',{})


  validate_hash($conf)


  create_resources('logstash',$conf)

}

我收到此錯誤...

Error: can't convert String into Hash at /tmp/vagrant-puppet-2/modules-0/profile/manifests/logstash.pp:10 on node pw-idx-11.local
Wrapped exception:
can't convert String into Hash
Error: can't convert String into Hash at /tmp/vagrant-puppet-2/modules-0/profile/manifests/logstash.pp:10 on node pw-idx-11.local

更新:

固定使用此...。

class profile::elasticsearch {

  class { '::elasticsearch':
    version => '1.1.1-1'
  }

  $elasticsearch_configs   = hiera_hash('profile::elasticsearch::instance',{})

  validate_hash($elasticsearch_configs)

  create_resources(elasticsearch::instance,$elasticsearch_configs)

  package { 'java-1.7.0-openjdk.x86_64':
    ensure => 'installed'
  }

}

您的數據不適合與create_resources一起使用,后者需要嵌套的哈希。

data_identifier:
  resource_title1:
    res1_param1: value
    res1_param2: value
  resource_title2:
    res2_param1: value
    ...

由於您的數據是平面哈希,因此無法從中創建資源。 您可能需要添加資源標題層。

那是一種復雜的方式,那

class profile::logstash($conf = {}) {
  validate_hash($conf)
  create_resources('logstash',$conf)
}

假設您已經在site.pp中

hiera_include('classes')

請參見https://ask.puppetlabs.com/question/3608/parametrized-classes-with-hiera_includeclasses/

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM