I am creating a configuration for my service in chef attributes. However, at some point I need to turn the mash attribute into a simple ruby ββhash. This worked well in Chef 10:
node.myapp.config.to_hash
However, starting with Chef 11, this will not work. Only the top level of the attribute is converted to a hash, and then the nested values ββstore immutable mash objects. Changing them leads to the following errors:
Chef :: Exceptions :: ImmutableAttributeModification ------------------------------------------- ----- Node attributes are read-only unless you specify which priority level to set. to set the attribute usage code, for example, `node.default [" key "] =" value "'
I tried a bunch of ways to get around this problem, which does not work:
node.myapp.config.dup.to_hash JSON.parse(node.myapp.config.to_json)
A json parsing hack that seems to work fine will result in:
JSON::ParserError unexpected token at '"#<Chef::Node::Attribute:0x000000020eee88>"'
Is there any real reliable way, apart from the nested parsing function in each cookbook, to convert attributes into a simple, plain, old old ruby ββhash code?
source share