I just found a solution (at least temporarily) in case someone is interested.
Here’s my helper method:
def attributes_to_yaml
hash = node[‘app’][‘config’].to_hash
mutable_hash = JSON.parse(hash.dup.to_json)
mutable_hash.to_yaml
end
Curtis
On Feb 4, 2014, at 5:43 PM, Daniel DeLeo <dan@kallistec.commailto:dan@kallistec.com> wrote:
On Tuesday, February 4, 2014 at 3:35 PM, Curtis Stewart wrote:
I’m trying to allow a settings.yml file to be generated from node attributes.
I assumed the following would work, but I’m left with various “!ruby/hash:Chef::Node::ImmutableMash” lines in my yaml file.
YAML::dump(node[‘applications’][‘settings’].to_hash)
settings: !ruby/hash:Chef::Node::ImmutableMash
foo: !ruby/array:Chef::Node::ImmutableArray
- settingone
bar: !ruby/array:Chef::Node::ImmutableArray
- settingone
I’d like to be able to allow for a very flexible configuration, however, maybe this is just a bad practice and I should use a template with a smaller number of configurations?
Thanks,
Curtis
There’s a patch to make to_hash convert ImmutableMash to regular Hashes, but it doesn’t correctly handle some cases of nested structures, like an Array of Hashes. It’d be great if you could fix it up: https://tickets.opscode.com/browse/CHEF-3953
If that’s beyond the work you’re willing to do, there’s at least some monkey-patch type workarounds to be found in that and related tickets (though monkey patches are inherently brittle and can be accidentally broken in minor or possibly patch releases, so beware).
–
Daniel DeLeo