Skip to content

Instantly share code, notes, and snippets.

@snandam
Created November 4, 2014 16:28
Show Gist options
  • Save snandam/b42e34f39797a1b13bca to your computer and use it in GitHub Desktop.
Save snandam/b42e34f39797a1b13bca to your computer and use it in GitHub Desktop.
Ansible playbook to check for a directory/file in ansible
---
-
hosts: dev
gather_facts: yes
vars:
app_name: creditcompliance
path_to_verify: /var/www/edge-app/{{app_name}}/web/config/app.conf.json
tasks:
-
name: "Check if path exists for {{ path_to_verify }}"
register: check_path
stat: path={{ path_to_verify }}
-
debug: "msg='Valid path found on {{ ansible_fqdn }}!'"
name: "It exists"
when: check_path.stat.exists
-
debug: "msg=\"Please verify if the file exists on {{ ansible_fqdn }}...\""
name: "It doesn't exist"
when: "check_path.stat.exists == false"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment