check file after exec

39 views
Skip to first unread message

Mikael Lindqvist

unread,
Feb 10, 2014, 7:26:56 AM2/10/14
to puppet...@googlegroups.com
Hi,

Thanks for a great program!

I have one request though, and also wonder if there is some other way to do this...

when I have an exec task, such as:

exec { "task":
    command => "/bin/some/command",
    creates => "/some/file/somewhere"
}

It would be really nice if puppet could check for the existence of the file, and report an error if it does not exist after command has executed. Now the "creates" argument is only used to check if the file exists before the command is run, in order to skip the command if it exists. Possible syntax would be: 

exec { "task":
    command => "/bin/some/command",
    mustcreate => "/some/file/somewhere"
}

Or is there some other method to achieve the same?

Regards,

Mikael

jcbollinger

unread,
Feb 10, 2014, 4:41:28 PM2/10/14
to puppet...@googlegroups.com


Sure.  You can do this:

$mustcreate = '/some/file/somewhere'

exec { 'mytask':
  command => '/bin/some/command',
  creates => ${mustcreate}
}

# In the event the Exec['mytask'] needs to be synced,
# sometime after that sync ensure that the $mustcreate
# file exists:
exec { 'mytask-check':
  command => "test -e ${mustcreate}",
  subscribe => Exec['mytask'],
  refreshonly => true
}

If you want to do that a lot then you can minimize repetition of boilerplate by creating a defined type around that.


John

Mikael Lindqvist

unread,
Feb 18, 2014, 12:27:28 PM2/18/14
to puppet...@googlegroups.com
ok thanks alot!

// Mikael
Reply all
Reply to author
Forward
0 new messages