[英]Where to put hiera files in puppet hiera setup
I have a running puppet master-agent setup and currently trying to figure out how to use hiera to provision php. 我有一个正在运行的puppet主代理设置,当前正在尝试弄清楚如何使用hiera来配置php。
My Puppetfile: 我的人偶文件:
forge "http://forge.puppetlabs.com"
mod "jfryman/nginx"
mod "puppetlabs/mysql"
mod "mayflower/php"
mod 'puppetlabs-vcsrepo'
mod 'puppetlabs/ntp', '4.1.0'
mod 'puppetlabs/stdlib'
My site.pp
: 我的site.pp
:
hiera_include('classes')
My environment.conf
, where the modulepath is maintained: 我的environment.conf
,其中维护模块路径:
manifest = site.pp
modulepath = modules:site
My hiera config on puppet master at /etc/puppetlabs/puppet/hiera.yml
: 我在/etc/puppetlabs/puppet/hiera.yml
puppet master上的/etc/puppetlabs/puppet/hiera.yml
配置:
---
:backends:
- yaml
:hierarchy:
- "nodes/%{::trusted.certname}"
- "environment/%{server_facts.environment}"
- 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:
From what I understand, general config that should be present on all servers goes into common.yaml
. 据我了解,应该在所有服务器上都存在的常规配置进入common.yaml
。 With this setup, I managed to install ntp on my node with this config at hieradata/common.yaml
: 通过此设置,我设法使用hieradata/common.yaml
上的此配置在节点上安装了ntp:
---
classes:
- 'profile::base'
ntp::servers:
- server 0.de.pool.ntp.org
- server 1.de.pool.ntp.org
- server 2.de.pool.ntp.org
- server 3.de.pool.ntp.org
Now, my hierarchy also states that all node specific config should go into hieradata/nodes/{fqdn-of-the-node}.yml
. 现在,我的层次结构还指出,所有特定于节点的配置都应放入hieradata/nodes/{fqdn-of-the-node}.yml
。
Now, finally coming to my questions: 现在,终于问到我的问题了:
I have a file hieradata/nodes/myserver.example.com.yml
which holds this: 我有一个文件hieradata/nodes/myserver.example.com.yml
,其中包含以下内容:
classes:
- 'profile::php'
And a manifest under site/profile/manifests/php.pp
: 在site/profile/manifests/php.pp
下的site/profile/manifests/php.pp
:
class profile::php {
class { '::php': }
}
But this does not provision php. 但这不提供php。 As you saw, I use mayflower/php
from the forge. 如您所见,我使用伪造的mayflower/php
。
Now, my two questions are: 现在,我的两个问题是:
Is my hiera file for php in the right location? 我的hiera php文件在正确的位置吗? What am I missing then to make it provision php to my agent? 我想让它为我的经纪人提供php时会丢失什么?
You have multiple issues/possibilities here, so let us go through them iteratively. 您在这里有多个问题/可能性,所以让我们迭代地解决它们。
First, you are using the default datadir
of: 首先,您使用的默认数据datadir
为:
/etc/puppetlabs/code/environments/%{environment}/hieradata
However, you have a priority of: 但是,您的优先级是:
"environment/%{server_facts.environment}"
This does not make sense, since you have a priority that distinguishes data for nodes based on their directory environment, but you also are placing hieradata directly in directory environments. 这没有任何意义,因为您具有根据节点目录环境区分节点数据的优先级,但是您也直接将hieradata放置在目录环境中。 If you want priority based on directory environment, then change your hieradata directory to be outside the direct environments at: 如果要基于目录环境优先级,请在以下位置将hieradata目录更改为直接环境之外:
/etc/puppetlabs/code/hieradata
Otherwise, you should remove that level from your priority as it adds no value and will increase lookup times. 否则,您应该从优先级中删除该级别,因为它没有任何价值,并且会增加查找时间。
Second, you did not show your site.pp
, but did you remember your hiera_include('classes')
? 其次,您没有显示site.pp
,但是您还记得hiera_include('classes')
吗? That will lookup the array classes
and then include them, which is what it seems you want. 这将查找数组classes
,然后包括它们,这似乎是您想要的。 If you are not doing it, then the node provisioning issue you described would occur. 如果您不这样做,则会发生您描述的节点配置问题。
Third, is site
in your modulepath
? 第三, site
在您的modulepath
? You need to append it in either your puppet.conf
or your environment.conf
. 您需要将其附加到puppet.conf
或environment.conf
。
Fourth, your node's fqdn
may not match the certname
. 第四,您节点的fqdn
可能与certname
不匹配。 Check the certs directory on your Puppetmaster for the node's cert. 检查Puppetmaster上的certs目录以获取节点的证书。
Side notes: 旁注:
ntp
worked, I am assuming your module install with r10k
into the environment directories succeeded. 由于ntp
工作,我假设您成功将使用r10k
的模块安装到环境目录中。 Also I am assuming that the modules are present for the directory environment of your node. 我还假设模块存在于您节点的目录环境中。 php
class as global in your declaration with ::php
. 有没有真正的理由指定php
与你的声明类作为全球::php
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.