木偶的超级新手。找不到如何在文件中添加时间戳的好例子puppet.pp
node '123' {
file { '/tmp/hello':
content => "hello world",
}
file { '/tmp/timestamped':
content => 'date',
}
Run Code Online (Sandbox Code Playgroud)
只是想在将此清单应用于带时间戳的文件时打印当前日期
版本是:4.10
如果您使用的是4.8.0 之前的版本,则可以strftime()在 stdlib 模块中使用函数(http://www.puppetmodule.info/github/simp/puppetlabs-stdlib/puppet_functions_ruby3x/strftime)
如果您使用的是较新版本的 puppet,则应使用Timestamp.new().strftime()( https://puppet.com/docs/puppet/latest/function.html#strftime )
示例(您只需要使用其中一项作业):
#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"
}
Run Code Online (Sandbox Code Playgroud)
这应该有效。使用generate 创建并分配给变量。然后将变量分配为文件的内容。
$timestamp = generate('/bin/date', '%Y-%m-%dT%H:%M:%S')
file {'/tmp/timestamped':
content => "$timestamp"
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2479 次 |
| 最近记录: |