Puppet 简明教程

Puppet - Environment Conf

在 Puppet 中,所有环境都有 environment.conf 文件。每当主服务器为该特定环境分配的任何节点或所有节点提供服务时,此文件可以覆盖多个默认设置。

In Puppet, all environments have the environment.conf file. This file can override several default settings whenever the master is serving any of the nodes or all the nodes assigned to that particular environment.

Location

在 Puppet 中,对于所有定义的环境,environment.conf 文件都位于其主环境的顶层,紧邻清单和模块目录。考虑一个示例,如果您的环境位于默认目录 (Vipin/testing/environment) 中,则测试环境的配置文件位于 Vipin/testing/environments/test/environment.conf 中。

In Puppet, for all the environments which are defined, environment.conf file is located at the top level of its home environment, very next to the manifest and modules directors. Considering an example, if your environment is in default directories (Vipin/testing/environment), then test environment’s config file is located at Vipin/testing/environments/test/environment.conf.

Example

# /etc/testingdir/code/environments/test/environment.conf
# Puppet Enterprise requires $basemodulepath; see note below under modulepath".
modulepath = site:dist:modules:$basemodulepath
# Use our custom script to get a git commit for the current state of the code:
config_version = get_environment_commit.sh

Format

Puppet 中的所有配置文件都以相同的方式使用相同的类似 INI 的格式。 environment.conf 文件遵循与其他文件(如 puppet.conf 文件)相同的类似 INI 的格式。environment.conf 和 puppet.conf 之间的唯一区别是 environment.conf 文件不能包含 [main] 部分。environment.conf 文件中的所有设置都必须位于任何配置部分之外。

All the configuration files in Puppet uses the same INI-like format in the same way. environment.conf file follow the same INI-like format as others do like puppet.conf file. The only difference between environment.conf and puppet.conf is environment.conf file cannot contain the [main] section. All settings in the environment.conf file must be outside any config section.

Relative Path in Values

大多数允许的设置都接受文件路径或路径列表作为值。如果任何路径都是相对路径,则它们不以前导斜杠或驱动器号开头 - 它们大多将相对于该环境的主目录解析。

Most of the allowed settings accept file path or list of path as the value. If any of the paths are relevant path, they start without a leading slash or drive letter – they will be mostly resolved relative to that environment’s main directory.

Interpolation in Values

Environment.conf 设置文件能够将其他设置的值用作变量。有多个有用的变量可以内插到 environment.conf 文件中。以下是几个重要变量的列表 -

Environment.conf settings file is capable of using values of other settings as variable. There are multiple useful variables which could be interpolated into the environment.conf file. Here is a list of few important variables −

  1. $basemodulepath − Useful for including directories in the module path settings. Puppet enterprise user should usually include this value of modulepath since the Puppet engine uses module in the basemodulepath.

  2. $environment − Useful as a command line argument to your config_version script. You can interpolate this variable only in the config_version setting.

  3. $codedir − Useful for locating files.

Allowed Settings

默认情况下,Puppet environment.conf 文件仅允许覆盖配置中列出的四项设置。

By default, Puppet environment.conf file is only allowed to override four settings in the configuration as listed.

  1. Modulepath

  2. Manifest

  3. Config_version

  4. Environment_timeout

Modulepath

这是 environment.conf 文件中的一个关键设置。模块路径中定义的所有目录都将默认由 Puppet 加载。这是 Puppet 加载其模块的路径位置。需要显式设置此项。如果未设置此上述设置,则 Puppet 中任何环境的默认模块路径为 -

This is one of the key settings in environment.conf file. All the directors defined in modulepath are by default loaded by Puppet. This is the path location from where Puppet loads its modules. One needs to explicitly set this up. If this above setting is not set, the default modulepath of any environment in Puppet will be −

<MODULES DIRECTORY FROM ENVIRONMENT>:$basemodulepath

Manifest

这用于定义主清单文件,Puppet 主机在启动并根据定义的清单(将用于配置环境)编译编录时将使用该文件。在此,我们可以定义一个文件、一个文件列表,甚至一个包含多个清单文件的目录,需要按定义的字母顺序对其进行评估和编译。

This is used to define the main manifest file, which Puppet master will use while booting up and compiling the catalog out of the defined manifest which is going to be used to configure the environment. In this, we can define a single file, a list of files, or even a directory consisting of multiple manifest files which needs to be evaluated and compiled in a defined alphabetical sequence.

需要在 environment.conf 文件中明确定义此设置。如果没有,则 Puppet 将使用环境默认清单目录作为其主清单。

One needs to explicitly define this setting in the environment.conf file. If not, then Puppet will use environments default manifest directory as its main manifest.

Config_version

config_version 可以定义为用于识别目录和事件的明确版本。当 Puppet 默认编译任何清单文件时,它会向生成的目录以及当 Puppet 主机在 Puppet 节点上应用任何定义的目录时生成的报告添加一个配置版本。Puppet 运行脚本来执行上述所有步骤,并将所有生成的输出用作 Config_version。

Config_version can be defined as a definite version used to identify catalogs and events. When Puppet compiles any manifest file by default, it adds a config version to the generated catalogs as well as to the reports which gets generated when the Puppet master applies any defined catalog on Puppet nodes. Puppet runs a script to perform all the above steps and uses all the generated output as Config_version.

Environment Timeout

它用于获取 Puppet 用于为给定环境加载数据所需时间量的信息。如果在 puppet.conf 文件中定义了该值,则这些值将覆盖默认超时值。

It is used to get the details about the amount of time which Puppet should use to load data for a given environment. If the value is defined in puppet.conf file, then these values will override the default timeout value.

Sample environment.conf File

[master]
   manifest =  $confdir/environments/$environment/manifests/site.pp
   modulepath =  $confdir/environments/$environment/modules

在上述代码 $confdir 中是环境配置文件所在的目录的路径。 $environment 是正在对其执行配置的环境的名称。

In the above code $confdir is the path of the directory, where environment configuration files are located. $environment is the name of the environment for which the configuration is being done.

Production Ready environment config File

# The environment configuration file
# The main manifest directory or file where Puppet starts to evaluate code
# This is the default value. Works with just a site.pp file or any other
manifest = manifests/
# The directories added to the module path, looked in first match first used order:
# modules - Directory for external modules, populated by r10k based on Puppetfile
# $basemodulepath - As from: puppet config print basemodulepath
modulepath = site:modules:$basemodulepath
# Set the cache timeout for this environment.
# This overrides what is set directly in puppet.conf for the whole Puppet server
# environment_timeout = unlimited
# With caching you need to flush the cache whenever new Puppet code is deployed
# This can also be done manually running: bin/puppet_flush_environment_cache.sh
# To disable catalog caching:
environment_timeout = 0
# Here we pass to one in the control repo the Puppet environment (and git branch)
# to get title and essential info of the last git commit
config_version = 'bin/config_script.sh $environment'