Best practice for making temporary file accessible to task

I need to run a command that needs to consume a file for its configuration. What would be the best practice for cases like this where a temporary file needs to be copied remotely and then deleted after a certain task has executed.

Is copying these files to Ansible’s remote_tmp a recommended practice? If so, how can that be achieved (I tried using {{ remote_tmp }} in my task but it didn’t seem to work), and will the file be cleaned up automatically once the playbook finishes running?

Thanks in advance for any input regarding this question.
–Pedro.

The remote temp location is not made available as a variable, nor is it appropriate as it applies only during the lifetime of a single task.

I would probably run ‘mktemp’ via ‘shell’ and register the result, and then clean it up with a final task to using “file: name={{ mktemp.stdout }} state=absent”

There are probably other nice solutions.

Thanks Michael. It clarifies the issue for me and it’s solid suggestion.

–Pedro.