Overriding attributes in the recipe

前端 未结 3 848
我在风中等你
我在风中等你 2020-12-24 05:46

Let\'s say I have a default attribute in a cookbook:

default.nginx_upstreams = {
    \'service1\' => [\'service1.server.com\'],
    \'service2\' => [\'         


        
3条回答
  •  难免孤独
    2020-12-24 06:23

    Just wanted to give further insight on Chef attributes, it is very important for users, who is going to refer this question on node attribute override.

    File Methods corresponds to attributes

    Use the following methods within the attributes file for a cookbook or within a recipe. These methods correspond to the attribute type of the same name:

    • override
    • default
    • normal (or set, where set is an alias for normal)
    • _unless
    • attribute?

    Attribute Precedence

    Attributes are always applied by the chef-client in the following order:

    1. A default attribute located in a cookbook attribute file
    2. A default attribute located in a recipe
    3. A default attribute located in an environment
    4. A default attribute located in role
    5. A force_default attribute located in a cookbook attribute file
    6. A force_default attribute located in a recipe
    7. A normal attribute located in a cookbook attribute file
    8. A normal attribute located in a recipe
    9. An override attribute located in a cookbook attribute file
    10. An override attribute located in a recipe
    11. An override attribute located in a role
    12. An override attribute located in an environment
    13. A force_override attribute located in a cookbook attribute file
    14. A force_override attribute located in a recipe
    15. An automatic attribute identified by Ohai at the start of the chef-client run

    where the last attribute in the list is the one that is applied to the node.

    It means that, OHAI attribute will have the highest precedence, where as the default attribute in cookbook attribute file will have the lowest precedence.

    Note: Provided the important details from Chef docs for attributes for the benefit of users. Because sometimes the URL will be moved or invalid.

提交回复
热议问题