Re: [ansible-project] Creating directory based on dates

3,925 views
Skip to first unread message

Michael DeHaan

unread,
May 3, 2013, 3:09:44 PM5/3/13
to ansible...@googlegroups.com
Look up "register" in the docs.


On Fri, May 3, 2013 at 7:17 AM, Nora Olsen <nora.o...@gmail.com> wrote:
Hi,

I'm trying to rsync a bunch of code to a directory that is based on date such as /deployment/releases/<YYYYMMDDHHMMSS> and symlinking it to /deployment/current.

This is similar to Capistrano deploy_to layout.

[deploy_to]
[deploy_to]/releases
[deploy_to]/releases/20080819001122
[deploy_to]/releases/...
[deploy_to]/shared
[deploy_to]/shared/log
[deploy_to]/shared/pids
[deploy_to]/shared/system
[deploy_to]/current -> [deploy_to]/releases/20100819001122

I know I can use the shell command to create the directory but how I can reuse a variable in subsequent actions?

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 



--
Michael DeHaan <mic...@ansibleworks.com>
CTO, AnsibleWorks, Inc.
http://www.ansibleworks.com/

Brian Coca

unread,
May 3, 2013, 3:23:42 PM5/3/13
to ansible...@googlegroups.com
also you can use the file module to create it, no need to shell
Brian Coca
Stultorum infinitus est numerus
0110000101110010011001010110111000100111011101000010000001111001011011110111010100100000011100110110110101100001011100100111010000100001
Pedo mellon a minno

Nora Olsen

unread,
May 4, 2013, 3:09:13 AM5/4/13
to ansible...@googlegroups.com

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?

Jan-Piet Mens

unread,
May 4, 2013, 10:35:44 AM5/4/13
to ansible...@googlegroups.com
> How would I use the file module?

I think something like this could do the trick:

tasks:
- action: shell date '+%F.%H:%M:%S'
register: mydate
- 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.

-JP

Nora Olsen

unread,
May 4, 2013, 11:00:52 AM5/4/13
to ansible...@googlegroups.com
Thanks. Will take a look.

I was also looking into the var variables that can be passed by the command line too. 
Reply all
Reply to author
Forward
0 new messages