Sometimes when working with ansible you might need a temporary folder to do some work in. Perhaps it’s going to store some large files or secrets and so should be cleaned up afterwards. Below is a sample playbook that can be used to do just that.
- hosts: localhost tasks: - name: Create temp directory for doing work in command: mktemp -d /tmp/mytempdir-XXXXXX register: mktemp - set_fact: tempdir: "{{ mktemp.stdout }}" # insert your code using {{ tempdir }} here - name: Cleanup temp directory file: path: "{{ tempdir }}" state: absent
You can grab the code directly from our github repo
https://github.com/alistairfay/code-snippets/blob/master/tempdir.yml
I got what you intend,bookmarked, very decent website.
Very interesting details you have noted, appreciate it for putting up.
There is definately a lot to learn about this topic. I love all the points you made. Cindra Ermin Shushan