Recipe to create file



Can a recipe create a file/template and store under files/ so that next run it can use it if necessary?

I can have file/template skeleton created and stored. During the first run, recipe will detect the skeleton and fill in the information and from that point on every run of the same recipe will just use the file/template and place it on the node, is this possible?




It's just ruby in the cookbooks. You can do almost anything, but I think you're going to hurt yourself this way. And unless one cookbook loads the content back to the Chef server in some way, it won't be available in a normal client setup.

You could write the files to a staging area on the local filesystem, and reference them or script with them in your recipes. Alternatively, one cookbook can publish attributes that can be read by another cookbook, which is a much more normal way to do that. If the file only needs a few aspects tuned based on an earlier cookbook, you might try to do this with attributes and a template in the second cookbook or recipe.


Actually, don't use distinct cookbooks if you can avoid it. Try to use distinct recipes, so that one can include the other specifically and easily and make sure that it always gets run first.