Forum: Cfengine Help
Subject: Re: execresult will look for binaries even though bundle is not
included
Author: zzamboni
Link to topic: https://cfengine.com/forum/read.php?3,18117,18119#msg-18119
I can duplicate this behavior, using 3.0.5p1 community on Win7 under cygwin. I
also agree that ideally the variables in a bundle should only be evaluated when
the bundle is executed. I think (without being a cfengine developer) that the
current behavior may be in place because a bundle's variables might be accessed
from outside even without running the bundle (e.g. you could try to access
$(test_bundle_that_uses_xyz123.xyz123_output) from some other bundle).
An alternative to achieve what you want could be to control the actual variable
assignments using classes, and not only the method executions. The following
example does what you want:
body common control {
bundlesequence => {
"common_config",
"all_test_bundles"
};
}
bundle common common_config {
classes:
"host_has_command_xyz123" or => { "foobar" };
}
bundle agent all_test_bundles {
methods:
"any" usebundle => test_bundle;
}
bundle agent test_bundle {
vars:
host_has_command_xyz123::
"xyz123_output" string => execresult("/usr/bin/xyz123", "noshell");
reports:
host_has_command_xyz123::
"xyz123 was run, output = $(xyz123_output)";
cfengine_3::
"generic test bundle was run";
}
In this case, the variable assignment is only evaluated when the
host_has_command_xyz123 class is defined, and does not produce an error if the
command does not exist.
Best regards,
--
Diego Zamboni
http://blog.zzamboni.org/
@zzamboni
_______________________________________________
Help-cfengine mailing list
[email protected]
https://cfengine.org/mailman/listinfo/help-cfengine