簡體   English   中英

清單中的HiHiera查找不起作用

[英]Puppet Hiera lookup in manifest not working

我正在學習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/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回答后,我更改了默認的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下創建了hieradata目錄

$ 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,
}

現在的問題是,當我嘗試執行清單時,沒有看到與希拉有關的消息。

$ 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

因此, hieradata直接在/etc/puppetlabs/code中創建hieradata/etc/puppetlabs/code將其向下移動兩個級別到/etc/puppetlabs/code/environments/qa和其他環境中。

暫無
暫無

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

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