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.
27 lines
499 B
Plaintext
27 lines
499 B
Plaintext
import "datetime"
|
|
import "math"
|
|
|
|
$now = datetime.now()
|
|
|
|
# alternate every four seconds
|
|
$mod0 = math.mod($now, 8) == 0
|
|
$mod1 = math.mod($now, 8) == 1
|
|
$mod2 = math.mod($now, 8) == 2
|
|
$mod3 = math.mod($now, 8) == 3
|
|
$mod = $mod0 || $mod1 || $mod2 || $mod3
|
|
|
|
file "/tmp/mgmt/" {
|
|
state => "exists",
|
|
}
|
|
|
|
# file should change the mode every four seconds
|
|
# editing the file contents at anytime is allowed
|
|
if $mod {
|
|
file "/tmp/mgmt/hello" {
|
|
state => "exists",
|
|
mode => "0777",
|
|
|
|
Meta:reverse => true,
|
|
}
|
|
}
|