Skip to content

Instantly share code, notes, and snippets.

@miketheman
Created March 10, 2015 16:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save miketheman/4bb1b16618bee1365893 to your computer and use it in GitHub Desktop.
Save miketheman/4bb1b16618bee1365893 to your computer and use it in GitHub Desktop.
Chef Bootstrap Partial Wrapper Example
bash -x -c -e '
echo $(date +%s) > /etc/created
apt-get update
'
<%
def import(fname)
eruby = Erubis::Eruby.new
here = Pathname.new(__FILE__).dirname.realpath
input = File.read(File.join(here, fname))
src = eruby.convert(input)
eval src
end
-%>
sudo <%= import("#{Pathname.new(@config[:template_file]).dirname}/chef-full.erb") %>
@miketheman
Copy link
Author

You can replace:

Pathname.new(@config[:template_file]).dirname

with a direct path to ChefDK's installed template:

/opt/chefdk/embedded/apps/chef/lib/chef/knife/bootstrap/chef-full.erb

Or figure out the Ruby-specific way of inferring "where am I" from ChefDK's context and walk that path instead.

During a knife ec2 server create (or other bootstrap derivatives), provide --template-file wrapper_example.rb to invoke this wrapper, assuming all paths are laid out correctly and files can find each other.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment