Workaround CHEF-3918
Recently when migrating all my chef roles to .json
format for use with the wonderful knife-essentials gem, I ran into a problem with roles when provisioning with chef-solo.
The cause was CHEF-3918. 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, 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
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#