Chef 简明教程
Chef - Environment
Chef 帮助执行特定于环境的配置。为开发、测试和生产准备单独的环境始终是一个好主意。
Chef helps in performing environment specific configuration. It is always a good idea to have a separate environment for development, testing, and production.
Chef 能够将节点分组到单独的环境中,以支持排序的开发流。
Chef enables grouping nodes into separate environments to support an ordered development flow.
Creating an Environment
可以使用刀具实用工具在执行期间创建环境。以下命令将打开 Shell 的默认编辑器,以便修改环境定义。
Creation of environment on the fly can be done using the knife utility. Following command will open a Shell’s default editor, so that one can modify the environment definition.
vipin@laptop:~/chef-repo $ knife environment create book {
"name": "book",
"description": "",
"cookbook_versions": {
},
"json_class": "Chef::Environment",
"chef_type": "environment",
"default_attributes": {
},
"override_attributes": {
}
}
Created book
_default Environment
各个组织始终会从至少一个名为默认环境的环境开始,Chef server 始终提供该环境。无法以任何方式修改默认环境。仅可调整我们创建的自定义环境中的任何类型更改。
Each organization will always start with at least a single environment called default environment, which is always available to the Chef server. A default environment cannot be modified in anyway. Any kind of changes can only be accommodated in the custom environment that we create.
Environment Attributes
可以在环境中定义属性,进而使用这些属性替代节点中的默认设置。当 Chef 客户端运行时,将把这些属性与已经存在于节点中的默认属性进行比较。当环境属性优先于默认属性时,Chef 客户端在每个节点上运行 Chef 客户端时会应用这些设置和值。
An attribute can be defined in an environment and then used to override the default settings in the node. When the Chef client run takes place, then these attributes are compared with the default attributes that are already present in the node. When the environment attributes take precedence over the default attributes, Chef client will apply these settings and values when the Chef client run takes place on each node.
环境属性只能是 default_attribute 或 override_attribute。它不能是普通属性。可以使用 default_attribute 或 override_attribute 方法。
An environment attribute can only be either default_attribute or override_attribute. It cannot be a normal attribute. One can use default_attribute or override_attribute methods.
Attribute Type
Default − 默认属性始终在每次 Chef 客户端运行开始时重置,并且具有最低的属性优先级。
Default − A default attribute is always reset at the start of every Chef client run and have the lowest attribute precedence.
Override − 替代属性始终在每次 Chef 客户端运行开始时重置,并且具有比 default、force_default 和 normal 更高的属性优先级。替代属性最常在食谱中定义,但也可在角色或环境的属性文件。
Override − An override attribute is always reset at the start of every Chef client run and has a higher attribute precedence than default, force_default and normal. An override attribute is most often defined in the recipe but can also be specified in an attribute file for a role or for an environment.