Workaround CHEF-3918
Recently when migrating all my chef roles to .json
format for use with the wonderful [knife-essentials][1] gem, I ran into a problem with roles when provisioning with chef-solo.
The cause was [CHEF-3918][2]. The sed command to fix it was a pain to get working on OSX due to the slight differences between how the GNU and BSD versions of sed [handle newlines][3], so I am sharing this so others can benefit.
Chef Roles
On OSX or BSD-based sed:
for f in $(ls -1 roles/*.json); do sed -i '' -e 's/^{/{\'$'\n "json_class": "Chef::Role",/' $f; done
On Linux or GNU-based sed:
for f in $(ls -1 roles/*.json); do sed -i -e 's/^{/{\n "json_class": "Chef::Role",/' $f; done
Chef Environments
For environments, just replace Chef::Role
with Chef::Environment
.
On OSX or BSD-based sed:
for f in $(ls -1 environments/*.json); do sed -i '' -e 's/^{/{\'$'\n "json_class": "Chef::Environment",/' $f; done
On Linux or GNU-based sed:
for f in $(ls -1 environments/*.json); do sed -i -e 's/^{/{\n "json_class": "Chef::Environment",/' $f; done
[1]: http://rubygems.org/gems/knife-essentials
[2]: https://tickets.opscode.com/browse/CHEF-3918
[3]: http://stackoverflow.com/a/11163357/645491
Written by James Cuzella
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#