为什么我的傀儡大师不使用 hiera?

为什么我的傀儡大师不使用 hiera?

我已经设置了一个 Puppet Master(版本 3.8.1),其中有一个 hiera.yaml 文件,我认为该文件设置正确,如下所示:

pete@ip-172-31-4-61:~$ cat /etc/puppet/hiera.yaml
---
:hierarchy:
    - "%{::fqdn}"
:backends:
    - yaml
:yaml:
    :datadir: '/etc/puppet/hieradata'

当我运行以下命令时:

sudo puppet master --verbose --debug --compile ip-10-1-3-7

(ip-10-1-3-7 是我的节点之一)我没有在目录中看到基于我的 hiera 数据的任何信息。更令人困惑的是,我没有在调试中看到这一行:

Debug: hiera(): Hiera YAML backend starting

我确实看到其他与 Hiera 合作的木偶大师

更新:我已经编辑了我的 puppet.conf 文件以包含hiera_配置按照下面的评论,重新启动了 puppetmaster,但它仍然不起作用。

pete@ip-172-31-4-61:~$ cat /etc/puppet/puppet.conf
[main]
logdir=/var/log/puppet
vardir=/var/lib/puppet
ssldir=/var/lib/puppet/ssl
rundir=/var/run/puppet
factpath=$vardir/lib/facter
certname = master
dns_alt_names = puppet
hiera_config = $confdir/hiera.yaml

[master]
# These are needed when the puppetmaster is run by passenger
# and can safely be removed if webrick is used.
ssl_client_header = SSL_CLIENT_S_DN
ssl_client_verify_header = SSL_CLIENT_VERIFY

我正在运行 Ubuntu 14.04,使用来自 puppetlabs 的软件包仓库:

pete@ip-172-31-4-61:~$ cat /etc/issue
Ubuntu 14.04.2 LTS \n \l

pete@ip-172-31-4-61:~$ dpkg -l "puppet*"
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name                        Version            Architecture       Description
+++-===========================-==================-==================-============================================================
rc  puppet                      3.8.1-1puppetlabs1 all                Centralized configuration management - agent startup and com
ii  puppet-common               3.8.1-1puppetlabs1 all                Centralized configuration management
un  puppet-el                   <none>             <none>             (no description available)
un  puppetdb-terminus           <none>             <none>             (no description available)
ii  puppetlabs-release          1.0-11             all                "Package to install Puppet Labs gpg key and apt repo"
un  puppetlabs-release-devel    <none>             <none>             (no description available)
rc  puppetlabs-release-pc1      0.9.2-1trusty      all                Release packages for the Puppet Labs PC1 repository
ii  puppetmaster                3.8.1-1puppetlabs1 all                Centralized configuration management - master startup and co
ii  puppetmaster-common         3.8.1-1puppetlabs1 all                Puppet master common scripts

更新:hieradata 目录的布局:

pete@ip-172-31-4-61:~$ tree /etc/puppet/hieradata
/etc/puppet/hieradata
└── ip-10-1-3-7.yaml

hiera节点文件的内容:

pete@ip-172-31-4-61:~$ cat /etc/puppet/hieradata/ip-10-1-3-7.yaml
---
classes:
  - nginx

nginx::nginx_upstreams:
  'app':
    ensure: present
    members:
      - localhost:5000
  'site':
    ensure: present
    members:
      - site.my-app.com

nginx::nginx_vhosts:
  'localhost':
    proxy: 'http://site'
    proxy_read_timeout: '5'

nginx::nginx_locations:
  app:
    location: '~ "^/(members|login|logout)"'
    vhost: localhost
    proxy: 'http://app'
    proxy_read_timeout: '20'
    ssl: false
    location_cfg_append:
      proxy_set_header:
        - 'X-Forwarded-Host $http_host'

我有理由相信这与 hieradata 节点文件无关,因为即使在另一个没有主机节点文件的 Puppet Master 上,我仍然会得到调试:hiera():Hiera YAML 后端正在启动调试线。

答案1

验证此行是否存在于您的site.pp

hiera_include('classes')

然后尝试运行此命令:

puppet master --compile host.domain.tld --debug 2>&1 | grep hiera

这应该会给你如下输出:

Debug: hiera(): Hiera YAML backend starting
[...]
Debug: hiera(): Looking up $KEY in YAML backend
Debug: hiera(): Looking for data source common
Debug: hiera(): Looking for data source node/host.domain.tld
Debug: hiera(): Found $KEY in node/host.domain.tld

运行上面的命令(不带该| grep部分)也应该会得到类似的结果:

Debug: importing '/etc/puppet/environments/production/modules/xxx/manifests/init.pp' in environment production

证明类正在被加载。

您分享的数据没有明确说明任何类被分配给客户端,因此如果没有加载类,则不会进行隐式层次查找。

以下是我的木偶大师的一个例子:

Info: Not using expired facts for host.corp from cache; expired at 2015-07-21 19:42:37 +0200
Info: Caching facts for host.corp
Info: Caching node for host.corp
Debug: hiera(): Hiera YAML backend starting
Debug: hiera(): Looking up classes in YAML backend
Debug: hiera(): Looking for data source kernel/Linux
Debug: hiera(): Found classes in kernel/Linux
Debug: hiera(): Looking for data source osfamily/RedHat
Debug: hiera(): Looking for data source os/CentOS
Debug: hiera(): Found classes in os/CentOS
Debug: hiera(): Looking for data source node/host.corp
Debug: hiera(): Found classes in node/host.corp
Debug: hiera(): Looking for data source common
Debug: hiera(): Found classes in common
Debug: hiera(): Looking for data source corp

尝试hiera自行调试(此处的示例是使用查找字符串值-c):

hiera --debug -c /etc/puppet/hiera.yaml "sample::foo" bla "::fqdn=host.corp" osfamily='RedHat' "::environment=production"
DEBUG: 2015-07-22 16:49:20 +0200: Hiera YAML backend starting
DEBUG: 2015-07-22 16:49:20 +0200: Looking up sample::foo in YAML backend
DEBUG: 2015-07-22 16:49:20 +0200: Looking for data source node/host.corp
DEBUG: 2015-07-22 16:49:20 +0200: Found sample::foo in node/host.corp
bar

另外,检查facter -p您的节点提供的值是否正确。

相关内容