Last active
December 17, 2015 23:58
-
-
Save mechastorm/5692657 to your computer and use it in GitHub Desktop.
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
--- | |
# Attempt to check if the folder exist. | |
# If it exist echo out a string. You have to echo something | |
# if the directory does exist or else the task is considered failed | |
# Output is set to $is_default_created. Note that this variable is | |
# object and not an atomic value. | |
- name: Attempt to check if a directory exist | |
action: shell test -d /my/folder && echo "exist" || echo "" | |
register: is_folder_created | |
# Do an operation of somekind if the folder does not exist | |
- name: Do an operation if folder does not exist | |
action: command echo "Operation Yashima" | |
when_string: ${is_folder_created.stdout} != "exist" |
You can now uses the stat module to check if a file exists and is a directory.
See http://docs.ansible.com/stat_module.html
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I recently needed to copy a folder to a server only if it does not exist.
Ansible makes this partly easier with the "when" property but I had not found a magic module that does a check if the directory exist.
This was the solution I came up with was