Reputation: 1138
I am trying to render a yaml object in chef template it is working fine but as we know in yaml spaces also matters so it is creating new properties.
collection: <%= @collection.to_hash.to_yaml %>
Where collection is a json object
collection = { "name": "col1", "nested": { "nKey": 1 } }
Expected result is
collection:
name: col1
nested:
nKey: 1
Getting result
collection: ---
name: col1
nested: !ruby/hash:Mash #nested is not part of collection.
nKey: 1
And second is there any way to remove types(!ruby/hash:Mash
) and ---
from to_yaml function ?
Upvotes: 0
Views: 441
Reputation: 54267
You usually want to use to_json
, since all JSON is valid YAML. It's a bit ugly, but usually works better :)
Upvotes: 0