Best practice for making temporary file accessible to task

8,403 views
Skip to first unread message

Pedro Romano

unread,
Aug 4, 2013, 12:06:35 PM8/4/13
to ansible...@googlegroups.com
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.

Michael DeHaan

unread,
Aug 4, 2013, 1:56:22 PM8/4/13
to ansible...@googlegroups.com
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.








--Pedro.

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 



--
Michael DeHaan <mic...@ansibleworks.com>
CTO, AnsibleWorks, Inc.
http://www.ansibleworks.com/

Pedro Romano

unread,
Aug 4, 2013, 2:06:09 PM8/4/13
to ansible...@googlegroups.com
Thanks Michael. It clarifies the issue for me and it's solid suggestion.

--Pedro.
Reply all
Reply to author
Forward
0 new messages