puppet adding timestamp in file content
Puppet Version < 4.8.0
If you are using version older then 4.8.0 you can use function strftime()
in stdlib module (http://www.puppetmodule.info/github/simp/puppetlabs-stdlib/puppet_functions_ruby3x/strftime)
Puppet Version > 4.8.0
If you are using newer version of puppet you should use Timestamp.new().strftime()
(https://puppet.com/docs/puppet/latest/function.html#strftime)
Example (You only need to use one of the assignments):
#ISO 8601
$timestamp = Timestamp.new().strftime('%Y-%m-%dT%H:%M:%S%:z')
notice ($timestamp)
#RFC 822, 1036, 1124, 2822
$timestamp = Timestamp.new().strftime('%a, %d %b %Y %H:%M:%S %z')
notice ($timestamp)
file {'/tmp/timestamped':
content => "$timestamp"
}
This should work. Use generate to create and assign to a variable. Then assign the variable to be the file's content.
$timestamp = generate('/bin/date', '%Y-%m-%dT%H:%M:%S')
file {'/tmp/timestamped':
content => "$timestamp"
}