Skip to content

Instantly share code, notes, and snippets.

@skamithi
Created May 6, 2018 04:16
Show Gist options
  • Save skamithi/5da62ca94b97be4dbfb2748b18a517fa to your computer and use it in GitHub Desktop.
Save skamithi/5da62ca94b97be4dbfb2748b18a517fa to your computer and use it in GitHub Desktop.
block rescue
- hosts: linuxsimbasvr
gather_facts: no
tasks:
- block:
- name: create tempfile
tempfile:
state: file
suffix: ".file.tmp"
register: mytmpfile
- name: write something cool to the tempfile
template:
src: "coolstuff.j2"
dest: "{{ mytmpfile.path }}"
rescue:
- name: delete the tempfile if it was created
file:
state: absent
path: "{{ mytmpfile.path }}"
when: mytmpfile is defined
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment