# when condition

**URL:** <https://forum.ansible.com/t/when-condition/15706>\
**Category:** Ansible Project\
**Created:** [July 18, 2014, 4:31pm UTC](https://forum.ansible.com/t/when-condition/15706 "2014-07-18T16:31:44Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Diogene\_Laerce](https://avatars.discourse-cdn.com/v4/letter/d/958977/32.png) [@Diogene\_Laerce](https://forum.ansible.com/u/Diogene_Laerce)\
**Post date:** [July 18, 2014, 4:31pm UTC](https://forum.ansible.com/t/when-condition/15706/1 "2014-07-18T16:31:44Z")

</div>

Hi,

I would like to evaluate the following condition :

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [July 18, 2014, 6:15pm UTC](https://forum.ansible.com/t/when-condition/15706/2 "2014-07-18T18:15:21Z")

</div>

You don’t use Jinja2 inside when statements. Further, not all python functions, including the OS module, are exposed, and what you are saying would be an implicit local operation anyway.

You would need to run the stat module, register the result, and use that

- stat: path=/path/to/file  
register: foo

- deubg: var=foo # see what’s available in foo, just as an FYI

- shell: example  
when: foo.stat.isdir

---

<div class="post-metadata">

**Author:** ![Diogene\_Laerce](https://avatars.discourse-cdn.com/v4/letter/d/958977/32.png) [@Diogene\_Laerce](https://forum.ansible.com/u/Diogene_Laerce)\
**Post date:** [July 20, 2014, 10:38am UTC](https://forum.ansible.com/t/when-condition/15706/3 "2014-07-20T10:38:20Z")

</div>

Hi Michael,

Thanks ! And "second hit bird" : I know now what my Debian shell means  
by : "cannot stat".. Re-thanks. 😉
