Skip to end of metadata
Go to start of metadata

Overview

Chef does deep merging of mutilevel hashes and arrays for role and environment attributes. These can assist in code reuse by allowing you to layer your configuration among many roles, while still making use of default attributes set at the cookbook level.
See Attributes for more background information.

Examples

Simple merge

First our lowest level server role

roles/baseline.rb

next our more customized web server role which uses the baseline role

roles/web.rb

then using a recipe like

cookbooks/baseline/recipes/default.rb

and a run_list set to

run_list/web.json

produces

which mixes the default attributes from cookbooks/apache2/attributes/default.rb, the overrides from baseline.rb and the final overrides from web.rb quite nicely, setting startservers to 30.

With this in mind the examples below will use short hand.

Substitution

Hash - Substitute an existing string
Hash - Substitute an existing boolean
Subtraction using !merge is likely to be removed in the future, potentially in Chef 0.11. See the discussion here for more information.
Array - Substitute an existing string
Substitute an Array with a Hash

when items can't be merged the original data is overwritten

Addition

Hash - Add a string
Array - Add a string
Hash - Multilevel Add
Array - Multilevel Add

Subtraction

Subtraction using !merge is only valid between roles. It will not work in environment or file attributes.
Subtraction using !merge is likely to be removed in the future, potentially in Chef 0.11. See the discussion here for more information.
Hash - Remove a string
Array - Remove a string
!merge (without the colon) can be used in Chef >= 0.10.10
Array - Remove all values
Array - Remove an integer

You can't use !merge:<value> with integers, to get rid of 4 you'll have to dump them all.







Automatic Attributes


Cookbooks



Labels:
None
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.