Skip to content

Instantly share code, notes, and snippets.

@heiwa4126
Last active March 6, 2020 12:52
Show Gist options
  • Save heiwa4126/0868860bb059fa6ae3f2597ed5a9ff29 to your computer and use it in GitHub Desktop.
Save heiwa4126/0868860bb059fa6ae3f2597ed5a9ff29 to your computer and use it in GitHub Desktop.
Ansibleで、handlersを使ってテンポラリフォルダを消すサンプル
- name: handler test
hosts: localhost
become: no
gather_facts: false
force_handlers: true
#-------------
tasks:
- name: Create working directory.
tempfile:
state: directory
register: tmpdir
notify: rm_tmpdir
- debug: msg="{{ tmpdir.path }}"
- name: This task will fail.
copy:
src: super_secret.file
dest: "{{ tmpdir.path }}"
- debug: msg="Never say goodbye..."
#-------------
handlers:
- name: Remove working directory.
listen: rm_tmpdir
file:
path: "{{ tmpdir.path }}"
state: absent
- listen: rm_tmpdir
debug: msg="Now, I see you again!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment