Is there implicit "canonify"-cation happening in in "classes:" promise type?
Yes the agent will automatically canonify classes that you define for your
convenience.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
bundle agent main
# @brief show how classes are automatically canonified during definition
{
vars:
"invalid_class_string" string => "my-invalid-class";
classes:
@if minimum_version(3.10)
# Shorthand for "myclass" expression => "any";
# Available since 3.10.0
"$(invalid_class_string)-1";
@endif
"$(invalid_class_string)-2" expression => "any";
commands:
"/bin/true"
classes => results("bundle", "my-invalid-class-from-promise-result");
vars:
"c" slist => classesmatching("my.*");
reports:
"CFEngine $(sys.cf_version)";
"Found defined class $(c)";
}
|
R: CFEngine 3.11.0
R: Found defined class my_invalid_class_2
R: Found defined class my_invalid_class_1
R: Found defined class my_invalid_class_from_promise_result_repaired
R: Found defined class my_invalid_class_from_promise_result_reached
However, it will NOT automatically canonify strings that are being checked as
you can see in this example. You must explicitly canonify when checking.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
bundle agent main
{
vars:
"my_invalid_class" string => "my-invalid-class";
classes:
"$(my_invalid_class)" expression => "any";
reports:
"The string $(my_invalid_class) is a valid class"
if => $(my_invalid_class);
"The string $(my_invalid_class) is NOT a valid class"
if => not( $(my_invalid_class) );
"The string $(my_invalid_class) when canonified is a valid class"
if => classify( $(my_invalid_class) );
}
|
R: The string my-invalid-class is NOT a valid class
R: The string my-invalid-class when canonified is a valid class