Chef attributes are “Mash” type.
From the Ruby Doc: “Mash allows you to create pseudo-objects that have method-like accessors for hash keys.” Mash is inherited from Hash.
Attributes can hold any data type, but we need to make sure the type does not change as we create more attributes.
In this example we change the type of the attribute from string to Mash, and Chef throws the error:
FATAL: IndexError: string not matched
# ['level1'] is a string type and contains the string 'value1'
default['level1'] = 'value1'
# The type of ['level1'] changed to a Mash and contains the nested Mash ['name2']
default['level1']['name2'] = 'value2'
The solution is, keep the number of levels the same
# ['level1'] is a Mash type and contains the nested Mash ['name1']
default['level1']['name1'] = 'value1'
# ['level1'] is till a Mash type and contains the nested Mash ['name2']
default['level1']['name2'] = 'value2'