# Best practice for making temporary file accessible to task

**URL:** <https://forum.ansible.com/t/best-practice-for-making-temporary-file-accessible-to-task/13253>\
**Category:** Ansible Project\
**Created:** [August 4, 2013, 4:06pm UTC](https://forum.ansible.com/t/best-practice-for-making-temporary-file-accessible-to-task/13253 "2013-08-04T16:06:35Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pedro\_Romano](https://avatars.discourse-cdn.com/v4/letter/p/6a8cbe/32.png) [@Pedro\_Romano](https://forum.ansible.com/u/Pedro_Romano)\
**Post date:** [August 4, 2013, 4:06pm UTC](https://forum.ansible.com/t/best-practice-for-making-temporary-file-accessible-to-task/13253/1 "2013-08-04T16:06:35Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [August 4, 2013, 5:56pm UTC](https://forum.ansible.com/t/best-practice-for-making-temporary-file-accessible-to-task/13253/2 "2013-08-04T17:56:22Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Pedro\_Romano](https://avatars.discourse-cdn.com/v4/letter/p/6a8cbe/32.png) [@Pedro\_Romano](https://forum.ansible.com/u/Pedro_Romano)\
**Post date:** [August 4, 2013, 6:06pm UTC](https://forum.ansible.com/t/best-practice-for-making-temporary-file-accessible-to-task/13253/3 "2013-08-04T18:06:09Z")

</div>

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

–Pedro.
