Puppet 环境中的节点特定设置 [英] Node specific settings in a puppet environment

查看:52
本文介绍了Puppet 环境中的节点特定设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习木偶,我遇到了一个我认为非常基本的问题.为了简单起见,我使用的是 puppet forge 模块,而不是任何自定义编写的模块.这是我使用的版本明智:

I'm in the process of learning puppet and I'm running into what I assume is a pretty basic issue. For the purposes of keeping things simple, I'm using a puppet forge module rather than anything custom written. Here's what I'm using version wise:

傀儡服务器:5.1.3
傀儡代理:5.3.2
puppetlabs-java: 2.1.0

puppet server: 5.1.3
puppet agent: 5.3.2
puppetlabs-java: 2.1.0

当我安装 puppetlabs-java 模块时,我使用的是 --modulepath/etc/puppetlabs/code/modules/.

When I install the puppetlabs-java module, I am using --modulepath /etc/puppetlabs/code/modules/.

我目前已将代理配置为指向我的 puppet 服务器和我命名为 example 的环境.

I currently have my agent configured to point at my puppet server and an environment I have named example.

目前的环境是这样的:

├── environment.conf
├── hiera.yaml
├── manifests
│   └── init.pp
└── modules
    └── java.pp

我没有对 environment.confhiera.yaml 做任何事情,它们目前是默认值.我的 init.pp 包含:

I have done nothing to environment.conf and hiera.yaml, they are currently defaults. My init.pp contains:

node 'node1' {
}

node 'node2' {
}

我的 java.pp 包含:

and my java.pp contains:

class { 'java':
  distribution => 'jre',
}

我的问题有两个方面.如果我将 java.pp 放在清单文件夹中,它会将 java 应用于两个节点,无论我是否在任一节点中调用了 include java .如果我将 include java 放在任一节点上,它都可以正常工作,一个节点将获得 java 而另一个则不会,但它似乎不尊重我在 java.pp.如何使用 java.pp 文件中的自定义设置仅将 java 安装到 node1?

My issue is two fold. One if I place the java.pp in the manifest folder it applies java to both nodes, regardless of if I have called out an include java in either node. If I put the include java on either node, that works correctly and one node will get java and the other will not, but it does not appear to be respecting any of the settings I have in the java.pp. How can I accomplish only installing java to node1 with my custom settings in the java.pp file?

推荐答案

如果我将 java.pp 放在清单文件夹中,它会将 java 应用于两个节点,无论我是否在任一节点中调用了 include java.

是的.目录构建器为每个节点处理环境的 manifests 目录中的每个清单文件.您的 java.pp 文件包含类 java 的顶级范围声明,因此如果该文件由目录构建器处理,那么它将在目标中包含类java"节点的清单.

Yes. The catalog builder processes every manifest file in the environment's manifests directory for every node. Your java.pp file contains a top-scope declaration of class java, so if that file is processed by the catalog builder then it will include class 'java' in the target node's manifest.

如果我将 include java 放在任一节点上,它都可以正常工作,一个节点将获得 java 而另一个则不会,但它似乎不尊重我的任何设置java.pp.

If I put the include java on either node, that works correctly and one node will get java and the other will not, but it does not appear to be respecting any of the settings I have in the java.pp.

不,不会.include java (or class { 'java': ... }) declares class java,从而指示目录构建器以将该类包含在目标节点的目录中.这两种形式或多或少是可选的,两者都会导致目录构建器在环境的模块路径中查找类 java 的定义.您的 java.pp 没有在该搜索中找到正确的名称或正确的位置,这很好,因为它实际上不包含所需的定义.

No, it wouldn't. include java (or class { 'java': ... }) declares class java, thereby instructing the catalog builder to include that class in the target node's catalog. The two forms are more or less alternatives, and both will cause the catalog builder to look for the a definition of class java in the environment's module path. Your java.pp hasn't either the right name or the right location to be found in that search, which is good because it does not in fact contain the wanted definition.

要自定义类参数,您应该立即开始使用外部数据自动数据绑定.这不是将值绑定到类参数的唯一方式,但它是您应该更喜欢的机制,尤其是在跨模块边界声明类时.

To customize class parameters, you should start right away with external data and automatic data binding. This is not the only way to bind values to class parameters, but it's the mechanism you should prefer, especially for declaring classes across module boundaries.

关于 Hiera 的详细信息,为此目的的非常基本的 Hiera 配置可能包含以下部分:

Regarding Hiera details, a very basic Hiera config for this purpose might consist of these parts:

example/hiera.yaml

# example/hiera.yaml
---
version: 5

defaults:
  datadir: data
  data_hash: yaml_data

hierarchy:
  - name: "Common data"
    path: "common.yaml"

example/data/common.yaml

---
java::distribution: jre

这些文件名中的示例"将是同名环境的主目录.请注意,尽管您可以为每个模块添加一个新的层次结构级别,但这并不常见.使用映射到正在配置的机器的层次分类的层次结构更为典型;上面的命名预期了这样一种安排,其中目前只有一个类别.

The "example" in those file names would be the main directory of your environment of the same name. Note, by the way, that although you can add a new hierarchy level for every module, that would be unusual. It's more typical to use hierarchies that map to an hierarchical categorization of the machines being configured; naming in the above anticipates such an arrangement, in which as yet there is only one category.

更新模块数据后,您可能会发现需要使主服务器的环境缓存过期.一种方法是重启服务.

After having updated the module data, you might find that you need to make the master expire its environment cache. One way to do that would be to restart the service.

这篇关于Puppet 环境中的节点特定设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆