This might be slightly controversial, in that you must specify the state if a file would need to be created to perform the action. We no longer implicitly assume that just specifying content is enough. As it turns out, I believe this is safer and more correct. The code to implement this turns out to be much more logical and simplified, and does this removes an ambiguous corner case from the reversed resource code. Some discussion in: https://github.com/purpleidea/mgmt/issues/540 This patch also does a bit of related cleanup.
20 lines
602 B
Plaintext
20 lines
602 B
Plaintext
import "datetime"
|
|
import "sys"
|
|
import "example"
|
|
|
|
$secplusone = datetime.now() + $ayear
|
|
|
|
# note the order of the assignment (year can come later in the code)
|
|
$ayear = 60 * 60 * 24 * 365 # is a year in seconds (31536000)
|
|
|
|
$tmplvalues = struct{year => $secplusone, load => $theload, vumeter => $vumeter,}
|
|
|
|
$theload = structlookup(sys.load(), "x1")
|
|
|
|
$vumeter = example.vumeter("====", 10, 0.9)
|
|
|
|
file "/tmp/mgmt/datetime" {
|
|
state => "exists",
|
|
content => template("Now + 1 year is: {{ .year }} seconds, aka: {{ datetime_print .year }}\n\nload average: {{ .load }}\n\nvu: {{ .vumeter }}\n", $tmplvalues),
|
|
}
|