鉴于这些文件:
# 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
Run Code Online (Sandbox Code Playgroud)
我期望以下返回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
Run Code Online (Sandbox Code Playgroud)
来自 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
Run Code Online (Sandbox Code Playgroud)
在 hiera 的调试日志中,我们可以清楚地看到搜索路径中缺少的环境:(/etc/puppetlabs/code/environments//hieradata/common.json
注意//
之前的双倍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
Run Code Online (Sandbox Code Playgroud)
我猜这一次,路径是正确的,找到了数据文件,但没有返回值。
我期待 Puppet 运行以找到该值。我究竟做错了什么?
# 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
Run Code Online (Sandbox Code Playgroud)
在你的文件中/etc/puppetlabs/code/environments/production/hieradata/common.yaml
你需要写puppetdb::password: mypass2
在 yaml 语法中,这是一个散列而不是一个简单的变量
puppetdb:
password: "mypass2"
Run Code Online (Sandbox Code Playgroud)
这样你就有了一个简单的变量
puppetdb::password: mypass2
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
2260 次 |
最近记录: |