# directory is exists or not

**URL:** <https://forum.ansible.com/t/directory-is-exists-or-not/26219>\
**Category:** Ansible Project\
**Created:** [December 7, 2017, 2:56pm UTC](https://forum.ansible.com/t/directory-is-exists-or-not/26219 "2017-12-07T14:56:15Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bhautik\_K](https://avatars.discourse-cdn.com/v4/letter/b/5e9695/32.png) [@Bhautik\_K](https://forum.ansible.com/u/Bhautik_K)\
**Post date:** [December 7, 2017, 2:56pm UTC](https://forum.ansible.com/t/directory-is-exists-or-not/26219/1 "2017-12-07T14:56:15Z")

</div>

Looking for solution. I have write below yml for **if directory is exists or not** but getting below error. Could you please correct me where I did mistake ?

- hosts: compute

tasks:

- name: Ansible check directory exists.

stat:

path=/etc/yum.repos.d

register: p

- debug:

msg:“Path exists and is a directory”

when: p.stat.isdir is defined and p.stat.isdir

---

<div class="post-metadata">

**Author:** ![Larry\_Smith1](https://avatars.discourse-cdn.com/v4/letter/l/d26b3c/32.png) [@Larry\_Smith1](https://forum.ansible.com/u/Larry_Smith1)\
**Post date:** [December 7, 2017, 4:23pm UTC](https://forum.ansible.com/t/directory-is-exists-or-not/26219/2 "2017-12-07T16:23:49Z")

</div>

change:

`  
msg:“Path exists and is a directory”

`

to:

`  
msg: “Path exists and is a directory”

`

Missing space…

---

<div class="post-metadata">

**Author:** ![Bhautik\_K](https://avatars.discourse-cdn.com/v4/letter/b/5e9695/32.png) [@Bhautik\_K](https://forum.ansible.com/u/Bhautik_K)\
**Post date:** [December 7, 2017, 6:30pm UTC](https://forum.ansible.com/t/directory-is-exists-or-not/26219/3 "2017-12-07T18:30:13Z")

</div>

Hi Smith,

Tried making space but still same error.

Regards,  
Bhautik

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [December 7, 2017, 6:33pm UTC](https://forum.ansible.com/t/directory-is-exists-or-not/26219/4 "2017-12-07T18:33:42Z")

</div>

You have wrong indentation, the debug task as one space to much.  
It need to be indented at the same level as the stat task.

---

<div class="post-metadata">

**Author:** ![Larry\_Smith1](https://avatars.discourse-cdn.com/v4/letter/l/d26b3c/32.png) [@Larry\_Smith1](https://forum.ansible.com/u/Larry_Smith1)\
**Post date:** [December 7, 2017, 6:46pm UTC](https://forum.ansible.com/t/directory-is-exists-or-not/26219/5 "2017-12-07T18:46:33Z")

</div>

As @kai mentioned. Your indentation is off. Here is a workable playbook for you [https://gist.github.com/mrlesmithjr/039a7bccf342e456dc6f9cbb2474c995](https://gist.github.com/mrlesmithjr/039a7bccf342e456dc6f9cbb2474c995)

---

<div class="post-metadata">

**Author:** ![Bhautik\_K](https://avatars.discourse-cdn.com/v4/letter/b/5e9695/32.png) [@Bhautik\_K](https://forum.ansible.com/u/Bhautik_K)\
**Post date:** [December 7, 2017, 7:01pm UTC](https://forum.ansible.com/t/directory-is-exists-or-not/26219/6 "2017-12-07T19:01:59Z")

</div>

Thanks Kai Stian Olstad,it’s work but how we can identify small syntax error ? Which editor is good to use for ansible ?

Regards,  
Bhautik
