# Module to get directory from path?

**URL:** <https://forum.ansible.com/t/module-to-get-directory-from-path/15880>\
**Category:** Ansible Project\
**Created:** [August 7, 2014, 12:28am UTC](https://forum.ansible.com/t/module-to-get-directory-from-path/15880 "2014-08-07T00:28:25Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Steven\_Ringo](https://avatars.discourse-cdn.com/v4/letter/s/bc79bd/32.png) [@Steven\_Ringo](https://forum.ansible.com/u/Steven_Ringo)\
**Post date:** [August 7, 2014, 12:28am UTC](https://forum.ansible.com/t/module-to-get-directory-from-path/15880/1 "2014-08-07T00:28:25Z")

</div>

Hi,

I wish to pass in a parameter for a file, e.g: **/var/log/atlas/service.log**

The directory at **/var/log/atlas/** must also be created before the application writes to this file.

Is there a way to get the directory from the path, perhaps with a jinja2 filter? Or if anyone knows of a filter than can do this, that would be awesome.

Thanks,

Steve

---

<div class="post-metadata">

**Author:** ![sivel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sivel/32/1198_2.png) [@sivel](https://forum.ansible.com/u/sivel)\
**Post date:** [August 7, 2014, 1:31am UTC](https://forum.ansible.com/t/module-to-get-directory-from-path/15880/2 "2014-08-07T01:31:07Z")

</div>

Ansible includes a |dirname filter that will do this for you.

---

<div class="post-metadata">

**Author:** ![Steven\_Ringo](https://avatars.discourse-cdn.com/v4/letter/s/bc79bd/32.png) [@Steven\_Ringo](https://forum.ansible.com/u/Steven_Ringo)\
**Post date:** [August 7, 2014, 1:34am UTC](https://forum.ansible.com/t/module-to-get-directory-from-path/15880/3 "2014-08-07T01:34:02Z")

</div>

Hi,

Great, thanks. Clearly I didn’t look hard enough in the documentation: [http://docs.ansible.com/playbooks\_variables.html#other-useful-filters](http://docs.ansible.com/playbooks_variables.html#other-useful-filters)

Steve
