I have a chef recipe that uses a template to generate and xml document. The location of that document on the file system is not important; the location simply needs to be handed to a command line tool which will read the file and use it to configure an application. The xml file need not persist beyond the execution of the command. Therefore it seems to me that the file should be created in a platform neutral temporary files directory. C:\Temp on windows or /TMP on most nix machines. Does chef provide a means of creating temporary files, detecting the temporary file location, or otherwise accomplishing the objective?
Best bet: use Chef::Config['file_cache_path']
which is used by chef to store transient datas. I.e: template "#{Chef::Config['file_cache_path']}/myfile.xml" do
Left (rephrased) after comment as it still worth being there for general purpose:
As per comment, the execute resource will run anyway with this input to ensure the app is configured accordingly, the file has to be present only when the execute resource is run, for other cases what is below is to be kept in mind.
One of the key idea behind chef is idempotency, chef may run 100 times and do things only when they need to be done.
In this case, the template would be generated once, and never change unless there's a parameter change in attributes.
In such a case (the resulting file should be updated), chef will notice it, replace it and act accordingly with any notification defined on it.
© 2022 - 2024 — McMap. All rights reserved.