Attribute Precedence - AWS OpsWorks

Attribute Precedence

Important

The AWS OpsWorks Stacks service reached end of life on May 26, 2024 and has been disabled for both new and existing customers. We strongly recommend customers migrate their workloads to other solutions as soon as possible. If you have questions about migration, reach out to the AWS Support Team on AWS re:Post or through AWS Premium Support.

If an attribute is uniquely defined, Chef simply incorporates it into the node object. However, any attribute source can define any attribute, so it is possible for the same attribute to have multiple definitions with different values. For example, the built-in apache2 cookbook defines node[:apache][:keepalive], but you could also define that attribute in custom JSON or in a custom cookbook. If an attribute has multiple definitions, they are evaluated in an order that is described later and the node object receives the definition with the highest precedence.

An attribute is defined as follows:

node.type[:attribute][:sub_attribute][:...]=value

If an attribute has multiple definitions, the type determines which definition has precedence, and that definition is incorporated into the node object. AWS OpsWorks Stacks uses the following attribute types:

  • default–This is the most common type, and it essentially means "use this value if the attribute hasn't already been defined." If all definitions of an attribute are default type, the first definition in the evaluation order has precedence and subsequent values are ignored. Note that AWS OpsWorks Stacks sets all stack configuration and deployment attribute definitions to default type.

  • normal–Attributes with this type override any default or normal attributes that were defined earlier in the evaluation order. For example, if the first attribute is from a built-in cookbook and has a default type and the second is a user-defined attribute with has a normal type, the second definition has precedence.

  • set–This is a deprecated type that you might see in older cookbooks. It has been superseded by normal, which has the same precedence.

Chef supports several additional attribute types, including an automatic type that takes precedence over all other attribute definitions. The attribute definitions generated by Chef's Ohai tool are all automatic types, so they are effectively read-only. This isn't usually an issue, because there is no reason to override them and they are distinct from AWS OpsWorks Stacks' attributes. However, you should be careful to name your custom cookbook attributes so they are distinct from the Ohai attributes. For more information, see About Attributes.

Note

The Ohai tool is an executable that you can run from the command line. To list an instance's Ohai attributes, log in to the instance and run ohai in a terminal window. Be aware that it produces a very long output.

Here are the steps that incorporate the various attribute definitions into the node object:

  1. Merge any custom stack configuration attributes into the stack configuration and deployment attributes.

    Custom JSON attributes can be set for the stack, or for a particular deployment. They are first in the evaluation order and are effectively normal types. If one or more stack configuration attributes are also defined in custom JSON, the custom JSON values take precedence. Otherwise AWS OpsWorks Stacks simply incorporates the custom JSON attributes into the stack configuration.

  2. Merge any deployment custom JSON attributes into the stack configuration and deployment attributes.

    Deployment custom JSON attributes are also effectively normal types, so they take precedence over built-in and custom stack configuration JSON and built-in deployment JSON.

  3. Merge the stack configuration and deployment attributes into the instance's node object.

  4. Merge the instance's built-in cookbook attributes into the node object.

    The built-in cookbook attributes are all default types. If the one or more built-in cookbook attributes are also defined in the stack configuration and deployment attributes—typically because you defined them with custom JSON—the stack configuration definitions take precedence over the built-in cookbook definitions. All other built-in cookbook attributes are simply incorporated into the node object.

  5. Merge the instance's custom cookbook attributes into the node object.

    Custom c ookbook attributes are usually either normal or default types. Unique attributes are incorporated into the node object. If any custom cookbook attributes are also defined in Steps 1–3 (typically because you defined them with custom JSON), precedence depends on the custom cookbook attribute's type:

    • Attributes defined in Steps 1–3 take precedence over custom cookbook default attributes.

    • Custom c ookbook normal attributes take precedence over definitions from Steps 1–3.

Important

Do not use custom cookbook default attributes to override stack configuration or built-in cookbook attributes. Because custom cookbook attributes are evaluated last, the default attributes have the lowest precedence, and cannot override anything.