# Creating directory based on dates

**URL:** <https://forum.ansible.com/t/creating-directory-based-on-dates/12767>\
**Category:** Ansible Project\
**Tags:** ansible-project\
**Created:** [May 3, 2013, 7:09pm UTC](https://forum.ansible.com/t/creating-directory-based-on-dates/12767 "2013-05-03T19:09:44Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [May 3, 2013, 7:09pm UTC](https://forum.ansible.com/t/creating-directory-based-on-dates/12767/1 "2013-05-03T19:09:44Z")

</div>

Look up “register” in the docs.

---

<div class="post-metadata">

**Author:** ![Brian\_Coca1](https://avatars.discourse-cdn.com/v4/letter/b/278dde/32.png) [@Brian\_Coca1](https://forum.ansible.com/u/Brian_Coca1)\
**Post date:** [May 3, 2013, 7:23pm UTC](https://forum.ansible.com/t/creating-directory-based-on-dates/12767/2 "2013-05-03T19:23:42Z")

</div>

also you can use the file module to create it, no need to shell

---

<div class="post-metadata">

**Author:** ![Nora\_Olsen](https://avatars.discourse-cdn.com/v4/letter/n/57b2e6/32.png) [@Nora\_Olsen](https://forum.ansible.com/u/Nora_Olsen)\
**Post date:** [May 4, 2013, 7:09am UTC](https://forum.ansible.com/t/creating-directory-based-on-dates/12767/3 "2013-05-04T07:09:13Z")

</div>

I thought is not possible to use the file module because I’m creating the directory based on the current timestamp.

I’m currently creating it like this:

> action: shell mkdir -p /to/path/`date +%F.%H:%M:%S`

How would I use the file module?

---

<div class="post-metadata">

**Author:** ![jpmens1](https://avatars.discourse-cdn.com/v4/letter/j/e9c0ed/32.png) [@jpmens1](https://forum.ansible.com/u/jpmens1)\
**Post date:** [May 4, 2013, 2:35pm UTC](https://forum.ansible.com/t/creating-directory-based-on-dates/12767/4 "2013-05-04T14:35:44Z")

</div>

> How would I use the file module?

I think something like this could do the trick:

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tasks:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- action: shell date '+%F.%H:%M:%S'  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;register: mydate  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- action: file dest=/tmp/{{ mydate.stdout }} state=directory

Note how the 'register' keyword as mentioned by Michael "picks" up the  
stdout of the command. Later, the `file' action creates the directory  
proper, as Brian pointed out.

BTW, the facts obtained by Ansible via `setup' contain the current  
date/time in a variety of formats; you may want to look at those.

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-JP

---

<div class="post-metadata">

**Author:** ![Nora\_Olsen](https://avatars.discourse-cdn.com/v4/letter/n/57b2e6/32.png) [@Nora\_Olsen](https://forum.ansible.com/u/Nora_Olsen)\
**Post date:** [May 4, 2013, 3:00pm UTC](https://forum.ansible.com/t/creating-directory-based-on-dates/12767/5 "2013-05-04T15:00:52Z")

</div>

Thanks. Will take a look.

I was also looking into the var variables that can be passed by the command line too.
