清单中的Puppet Hiera查找不工作

清单中的Puppet Hiera查找不工作,puppet,hiera,Puppet,Hiera,我正在学习木偶,刚刚读到关于希拉的书 在讨论这个问题之前,我将在下面提供一些配置设置: $ cat /etc/puppetlabs/puppet/puppet.conf [master] codedir = /etc/puppetlabs/code [agent] server = puppet.example.com [master] certname = puppet.example.com [master] vardir = /var/opt/puppetlabs/puppetser

我正在学习木偶,刚刚读到关于希拉的书

在讨论这个问题之前,我将在下面提供一些配置设置:

$ cat /etc/puppetlabs/puppet/puppet.conf
[master]
codedir = /etc/puppetlabs/code

[agent]
server = puppet.example.com

[master]
certname = puppet.example.com

[master]
vardir = /var/opt/puppetlabs/puppetserver
ssldir = $vardir/ssl

[main]
environmentpath = /etc/puppetlabs/code/environments
basemodulepath = /etc/puppetlabs/code/modules


$ cat /etc/puppetlabs/puppet/hiera.yaml
---
:backends:
  - yaml
:hierarchy:
  - "nodes/%{::trusted.certname}"
  - common

:yaml:
# datadir is empty here, so hiera uses its defaults:
# - /etc/puppetlabs/code/environments/%{environment}/hieradata on *nix
# - %CommonAppData%\PuppetLabs\code\environments\%{environment}\hieradata on Windows
# When specifying a datadir, make sure the directory exists.
  :datadir:
更新:通过@um FelixFrank answer后,我更改了默认的Hiera配置文件位置。配置文件包含以下内容:

$ cat /etc/puppetlabs/code/hiera.yaml
---
:backends:
 - yaml
:hierarchy:
 - "hostname/%{facts.hostname}"
 - "os/%{facts.osfamily}"
 - common
:yaml:
 :datadir: /etc/puppetlabs/code/hieradata
我在
/etc/puppetlabs/code

$ ll /etc/puppetlabs/code/
total 4
drwxr-xr-x. 4 root root  32 Dec 20 11:17 environments
drwxr-xr-x. 3 root root  39 Dec 21 12:22 hieradata
-rw-r--r--. 1 root root 153 Dec 20 16:51 hiera.yaml
drwxr-xr-x. 2 root root   6 Dec 21 11:02 modules

$ cat /etc/puppetlabs/code/hieradata/common.yaml
---
puppet::status: 'running'
puppet::enabled: true
我尝试在我的主机名yaml文件中覆盖上述值,如下所述:

$ cat /etc/puppetlabs/code/hieradata/hostname/delvmplgc1.yaml
---
puppet::status: 'stopped'
puppet::enabled: false

$ facter hostname
delvmplgc1
我在Puppet服务器上创建了一个示例清单,以查看是否能够在清单中执行Hiera查找

$ cat /etc/puppetlabs/code/environments/qa/manifests/hierasample.pp
notify { 'welcome':
        message => "Hello!",
}

$status = lookup({ name => 'puppet::status', default_value => 'running' })
$enabled = lookup({ name => 'puppet::enabled', default_value => true })

service { 'puppet':
        ensure => $status,
        enable => $enabled,
}
现在的问题是,当我尝试执行清单时,我没有看到与Hiera相关的消息

$ puppet apply /etc/puppetlabs/code/environments/qa/manifests/hierasample.pp
Notice: Compiled catalog for delvmplgc1.sapient.com in environment production in 0.99 seconds
Notice: Hello!
Notice: /Stage[main]/Main/Notify[welcome]/message: defined 'message' as 'Hello!'
Notice: Applied catalog in 0.10 seconds

任何帮助都将不胜感激。

正如标准
hiera.yaml
中的注释所述,
datadir
位于

/etc/puppetlabs/code/environments/%{environment}/hieradata

因此,不要直接在
/etc/puppetlabs/code
中创建
hieradata
,将其向下移动两个级别到
/etc/puppetlabs/code/environments/qa
和其他环境中。

您可以将
/etc/puppetlabs/puppet/hiera.yaml
的内容添加到问题中吗?用
/etc/puppetlabs/puppet/hiera.yaml
的内容更新了帖子。我尝试更改默认的hiera配置文件位置使用
hiera\u config=$codedir/hiera.yaml
它获取了更改。谢谢你指出错误!:)但是仍然有一个查询:我的帖子中显示的文件delvmplgc1.yaml中被覆盖的值将“status”和“enabled”分别更改为“stopped”和false。但是,puppet输出只提到:
注意:/Stage[main]/main/Service[puppet]/sure:sure将“running”更改为“stopped”
。它还应该提到
注意:/Stage/Main/Service[puppet]/enable:enable将“true”更改为“false”
。你知道为什么它跳过了吗?我已经在我的帖子中粘贴了我自定义的hiera.yaml文件的内容。@Technext这里你的评论的输出与你问题中的输出不一致。另外,Felix Frank告诉你改变你的
hieradata
位置,而不是你的
hiera.yaml
位置。您可能不应该移动它。@Technext请记住,通过使您的Hiera数据环境不可知,您将无法在非prod环境等中进行阶段性更改,因此这通常是一个不好的移动。至于感知到的错误行为,我建议执行一些较低级别的调试,例如使用
notify
打印变量值等等。最后,如果这个动作不断,请避免多次编辑这个问题,并考虑提出一个新的、更尖锐的问题。