Ask Your Question

date and time stamp with directory

asked 2013-03-21 18:14:40 -0500

redmine gravatar image

How to create a directory with date and time stamp in a puppet manifest. I am on Unix OS. I tried couple of things but couldnt able to capture the current date and time in a variable.

example: exec {"newdir": command => "mkdir -p /tmp/foo/foobardate_time"


edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2013-03-21 18:32:53 -0500

Stefan gravatar image

With Puppet you define the state of the system. If you tell puppet "I want to have a directory with the current time stamp in it" this will be impossible to achieve because your desired state actually changes from second to second.

Why do you need that directory? What is your goal?

Just for reference: You can use the generate function to execute arbitrary shell code

$timestamp = generate('/bin/date', '+%Y%d%m_%H:%M:%S')

file { "/tmp/foo_${timestamp}":
  ensure => directory,

but this will add directories on every puppet run.

edit flag offensive delete link more

answered 2013-03-26 13:48:15 -0500

redmine gravatar image

updated 2013-03-26 13:55:12 -0500

Thanks for the response. I want to create couple of file in datestamped directory. Like this: $wrkdir = "/tmp/aafoo/foobar" $timestamp = generate('/bin/date', '+%Y%d%m')

exec {"newdir" : command => "mkdir -p $wrkdir/new${timestamp}", path => ["/usr/bin/"], before => File["$wrkdir/new_${timestamp}/switch.xml"], }

file {"$wrkdir/new${timestamp}/switch.xml": ensure => present, require => Exec["newdir"], }

file {"$wrkdir/new${timestamp}/datafile.xml": ensure => present, require => Exec["newdir"], }

But I am getting this error: sudo puppet apply file_manifest.pp

Error: Could not set 'present' on ensure: No such file or directory - /tmp/aafoo/foobar/new20132603 /switch.xml ... (more)

edit flag offensive delete link more



It looks like puppet was not able to create the file because the parent directory was not there. I suspect that generate returns the date output with a nasty newline ...(more)

Stefan gravatar imageStefan ( 2013-03-26 14:36:31 -0500 )edit

It still smells like you are trying to do something with puppet that puppet really is not designed for so a bit more details about why you need the directory ...(more)

Stefan gravatar imageStefan ( 2013-03-26 14:38:14 -0500 )edit

As Stefan alluded, Puppet will not recursively create directories. You must explicitly create the directories, or specify your dirs as an array.

Ancillas gravatar imageAncillas ( 2013-03-27 01:49:26 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools


Asked: 2013-03-21 18:14:40 -0500

Seen: 4,723 times

Last updated: Mar 26 '13