Skip to content

Instantly share code, notes, and snippets.

@mechastorm
Last active December 17, 2015 23:58
Show Gist options
  • Save mechastorm/5692657 to your computer and use it in GitHub Desktop.
Save mechastorm/5692657 to your computer and use it in GitHub Desktop.
---
# 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"
@pbuyle
Copy link

pbuyle commented Jun 19, 2014

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