Platform neutral way to create a temporary file in a chef's recipe

I have a chef recipe that uses a template to generate and an XML document. The location of this document in the file system does not matter; the location just needs to be passed to the command line tool that will read the file and use it to configure the application. The xml file should not be saved after running the command. Therefore, it seems to me that the file should be created in the directory of neutral temporary platform files. C: \ Temp on windows or / TMP on most nix machines. Does the chef help provide tools to create temporary files, detect the temporary location of files, or achieve a different result?

+8
chef chef-recipe
source share
1 answer

Best bet: use Chef::Config['file_cache_path'] , which is used by the chef to store temporary data. Ie: template "#{Chef::Config['file_cache_path']}/myfile.xml" do

To the left (paraphrased) after the comment, as it still stands there for general purposes:

In accordance with the comment, the runtime resource will work in any case with this input to ensure proper configuration of the application, the file should be present only when the runtime resource starts, in other cases, remember that the following is indicated.

One of the chef's key ideas is idempotency, the chef can work 100 times and do something only when necessary.

In this case, the template will be generated once and will never be changed if there is no parameter in the attributes.

In this case (the resulting file must be updated), the chef will notice it, replace it and act accordingly with any notification defined on it.

+11
source share

All Articles