Search code examples
chef-infraconfiguration-management

During a chef run how does node differ from node.default?


I've noticed that attributes in environments do not get applied if I use node.default in cookbooks (instead the cookbook attributes get applied). But, the attributes changed in environments get applied if I use node instead; why? I thought node and node.default are one and the same?


Solution

  • Node attribute precedence can be confusing. The document does help, once you read it a couple of times

    https://docs.chef.io/attributes.html

    My advice is as follows:

    1. Set default attributes in an attributes file within your cookbook. Don't confuse yourself by doing this within recipes as well.
    2. Override the attributes of other cookbooks by setting "normal" attributes and again do this in an attributes file within your cookbook
    3. At runtime using Environment or Role attributes to override all attributes set within cookbooks.
    4. Never edit the node attributes directly on the chef server. There is no transactional locking, which means your update could be lost if a chef client is running at the same time....

    The objective here is consistency