Puppet - 环境配置

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

位置

In Puppet,对于所有定义的环境,environment.conf文件位于其主环境的顶层,紧邻清单和模块控制器.举一个例子,如果你的环境在默认目录(Vipin/testing/environment),那么测试环境的配置文件位于 Vipin/testing/environments/test/environment.conf .

示例

# /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

格式

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

值中的相对路径

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

值插值

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

  • $ basemodulepath : 用于在模块路径设置中包含目录. Puppet企业用户通常应该包含 modulepath 的值,因为Puppet引擎在 basemodulepath 中使用模块.

  • $ environment : 可用作config_version脚本的命令行参数.您只能在config_version设置中插入此变量.

  • $ codedir : 用于定位文件.

允许设置

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

  • 模块路径

  • 清单

  • Config_version

  • Environment_timeout

Modulepath

这是environment.conf文件中的关键设置之一.默认情况下,模块路径中定义的所有控制器都由Puppet加载.这是Puppet加载其模块的路径位置.人们需要明确地设置它.如果未设置上述设置,则Puppet中任何环境的默认模块路径将为 :

<MODULES DIRECTORY FROM ENVIRONMENT>:$basemodulepath

清单

这用于定义主清单文件,Puppet master将在启动时使用从定义的清单中编译目录,该清单将用于配置环境.在这里,我们可以定义一个文件,一个文件列表,甚至一个由多个清单文件组成的目录,这些清单文件需要按照定义的字母顺序进行评估和编译.

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

Config_version

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

环境超时

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

示例environment.conf文件

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

在上面的代码中, $ confdir 是环境配置文件所在目录的路径. $ environment 是正在进行配置的环境的名称.

生产就绪环境配置文件

# 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'