Today I stumbled upon an unexpected behaviour change in CFEngine templates when upgrading from version 3.4 to 3.6. The change is not documented anywhere in the Changelog, so I am really not sure if it’s a bug or a feature. In any case, it is something to be aware of.
Take this template:
Normally, each line expands to an insert lines promise, which means that
duplicated lines may not be printed more than once. That behavior has
changed with CFEngine versions.
[%CFEngine cfengine_3_4:: %]
In this version of CFEngine, $(sys.cf_version), duplicates are printed once
In this version of CFEngine, $(sys.cf_version), duplicates are printed once
In this version of CFEngine, $(sys.cf_version), duplicates are printed once
that holds for blank lines, too
[%CFEngine cfengine_3_6:: %]
In this version of CFEngine, $(sys.cf_version), duplicates are preserved
In this version of CFEngine, $(sys.cf_version), duplicates are preserved
In this version of CFEngine, $(sys.cf_version), duplicates are preserved
[%CFEngine any:: %]
End of the story!
and this policy:
bundle agent test_example_cf3_template
{
vars:
cfengine_3_4::
"templatedir" string => execresult("/bin/pwd","noshell") ;
"testfile" string => "/tmp/cf_34.txt" ;
cfengine_3_6::
"templatedir" string => "$(this.promise_dirname)" ;
"testfile" string => "/tmp/cf_36.txt" ;
files:
"$(testfile)"
create => "yes",
edit_template => "$(templatedir)/example_cf3_template.tmpl";
reports:
cfengine_3::
"Check output in $(testfile)" ;
}
Now run the policy in both CFEngine 3.4 and 3.6. You’d expect to get two identical files: /tmp/cf_34.txt
and /tmp/cf_36.txt
. But they’re not.
Continue reading →