Skip to content

Instantly share code, notes, and snippets.

@mm53bar
Created February 21, 2013 01:51
Show Gist options
  • Save mm53bar/5001291 to your computer and use it in GitHub Desktop.
Save mm53bar/5001291 to your computer and use it in GitHub Desktop.
Problem: how to reference templates from recipe file?
How about....
* export all attributes as env variables (in install.sh just before the place where the role scripts get injected?)
* add helper method to recipes/sunzi.sh called sunzi::template
* call sunzi::template from recipes and pass in url of template file
* sunzi::template will wget the file to ~/sunzi/files/ unless the file already exists (allows override with local template file)
* sunzi::template will then run the template file through envsubst to substitute the env variables (http://www.oreillynet.com/linux/cmd/cmd.csp?path=e/envsubst)
Added bonii!
* removes the need to run templates through ERB
* Currently, you need to call recipes and pass a list of attributes as parameters. These parameters are referenced in the recipe as $1, $2, etc. If all parameters get exported at the beginning of the script, they're essentially global and don't need to be passed. Normally, global variables are bad but in this case they make it easier to use the recipes.
@ryanjones
Copy link

Looks good to me.

I wonder if there's a way to manage the parameters that belong to a template. It would suck if you brought in a template, but didn't have a "list" of params. Almost like a .env.example.yml but a .params.example.yml (I don't want a separate file, but more some type of "parm list builder magical thing").

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