Last active
March 6, 2020 12:52
-
-
Save heiwa4126/0868860bb059fa6ae3f2597ed5a9ff29 to your computer and use it in GitHub Desktop.
Ansibleで、handlersを使ってテンポラリフォルダを消すサンプル
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- 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