为什么Hiera没有find环境,也不是傀儡

鉴于这些文件:

# find /etc/puppetlabs/code -type f | grep -v modules | xargs head -n 100 ==> /etc/puppetlabs/code/environments/production/hieradata/common.yaml <== pgwatch: password: "mypass1" puppetdb: password: "mypass2" ==> /etc/puppetlabs/code/environments/production/manifests/site.pp <== node "todd.ca.seevibes.com" { class { 'postgresql::globals': encoding => 'UTF-8', locale => 'en_US.UTF-8', manage_package_repo => true, version => '9.1', } -> class{'postgresql::server': } -> postgresql::server::db{'puppetdb': user => 'puppetdb', password => postgresql_password('puppetdb', hiera('puppetdb::password')), } -> postgresql::server::db{'pgwatch': user => 'pgwatch', password => postgresql_password('pgwatch', hiera('pgwatch::password')), } postgresql::server::pg_hba_rule{'allow pgwatch from anywhere': address => '0.0.0.0/32', auth_method => 'md5', database => 'pgwatch', user => 'pgwatch', } } ==> /etc/puppetlabs/code/hiera.yaml <== --- :backends: - json - yaml :yaml: # Use the default value for datadir :datadir: :json: # Use the default value for datadir :datadir: :hierarchy: - "node/%{::fqdn}" - "node/%{::hostname}" - "%{::domain}" - common 

我期望以下内容返回pgwatch::password值:

 # hiera --debug pgwatch::password DEBUG: 2015-12-09 22:35:06 +0000: Hiera JSON backend starting DEBUG: 2015-12-09 22:35:06 +0000: Looking up pgwatch::password in JSON backend DEBUG: 2015-12-09 22:35:06 +0000: Looking for data source common DEBUG: 2015-12-09 22:35:06 +0000: Cannot find datafile /etc/puppetlabs/code/environments//hieradata/common.json, skipping DEBUG: 2015-12-09 22:35:06 +0000: Hiera YAML backend starting DEBUG: 2015-12-09 22:35:06 +0000: Looking up pgwatch::password in YAML backend DEBUG: 2015-12-09 22:35:06 +0000: Looking for data source common DEBUG: 2015-12-09 22:35:06 +0000: Cannot find datafile /etc/puppetlabs/code/environments//hieradata/common.yaml, skipping nil 

来自Puppet的同样的查询也失败了:

 # puppet agent -t Info: Using configured environment 'production' Info: Retrieving pluginfacts Info: Retrieving plugin Info: Loading facts Error: Could not retrieve catalog from remote server: Error 400 on SERVER: Evaluation Error: Error while evaluating a Function Call, Could not find data item puppetdb::password in any Hiera data file and no default supplied at /etc/puppetlabs/code/environments/production/manifests/site.pp:10:49 on node todd.ca.seevibes.com Warning: Not using cache on failed catalog Error: Could not retrieve catalog; skipping run 

在hiera的debugging日志中,我们可以在searchpath中清楚地看到缺less的环境: /etc/puppetlabs/code/environments//hieradata/common.json (注意hieradata之前的hieradata )。

我发现如何在命令行上为Hiera指定$ environment? 最好的答案说:通过::environment=production ,这并没有改变。 当我通过environment=production ,然后查找“成功”,但什么也没有返回:

 # hiera --debug pgwatch::password 'environment=production' DEBUG: 2015-12-09 22:42:12 +0000: Hiera JSON backend starting DEBUG: 2015-12-09 22:42:12 +0000: Looking up pgwatch::password in JSON backend DEBUG: 2015-12-09 22:42:12 +0000: Looking for data source common DEBUG: 2015-12-09 22:42:12 +0000: Cannot find datafile /etc/puppetlabs/code/environments/production/hieradata/common.json, skipping DEBUG: 2015-12-09 22:42:12 +0000: Hiera YAML backend starting DEBUG: 2015-12-09 22:42:12 +0000: Looking up pgwatch::password in YAML backend DEBUG: 2015-12-09 22:42:12 +0000: Looking for data source common nil 

我猜,这一次,path是正确的,数据文件被find,但没有返回的值。

我期待一个木偶运行find价值。 我究竟做错了什么?

 # uname -a Linux todd 3.10.23-xxxx-grs-ipv6-64 #1 SMP Mon Dec 9 16:02:37 CET 2013 x86_64 x86_64 x86_64 GNU/Linux # puppet --version 4.3.1 # hiera --version 3.0.5 # puppet agent --configprint environment production # which puppet /opt/puppetlabs/bin/puppet # which hiera /opt/puppetlabs/bin/hiera 

在你的文件/etc/puppetlabs/code/environments/production/hieradata/common.yaml你需要写puppetdb::password: mypass2

在yaml语法中,这不是一个简单的variables

 puppetdb: password: "mypass2" 

这样你就有了一个简单的variables

 puppetdb::password: mypass2