Skip to content

Instantly share code, notes, and snippets.

@briancurt
Created September 22, 2021 14:31
Show Gist options
  • Save briancurt/3c43a116f69e3e64a916d0bb8ba59e1b to your computer and use it in GitHub Desktop.
Save briancurt/3c43a116f69e3e64a916d0bb8ba59e1b to your computer and use it in GitHub Desktop.
Quick and dirty way to convert Ruby/Chef template variables to YAML/Ansible.
# <%= @app['config']['foo'] %>
# to
# {{ app.config.foo }}
for file in $(ls -1 templates/); do
sed -i -e "s/<%= @/{{ /" $file # Replace <%= @ with {{
sed -i -e "s/%>/}}/" $file # Replace %> with }}
sed -i -e "s/\['/./" $file # Replace first occurence of [' with .
sed -i -e "s/'\]\['/./g" $file # Replace all middle '][' with .
sed -i -e "s/'\] / /" $file # Remove closing ']
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment