Hi-
This is part feature request but I expect someone will have some
insights on another way to accomplish what I'm asking with the existing
tools in cfengine.
It's very common, from examples I have seen, to use "execresult" to
store output in a variable after which "regcmp" will active a class if
there's a match. The problem that concerns me is something like the
following:
vars:
"updatevariable" string =>
execresult("some_random_command","noshell");
classes:
"fully-updated" expression =>
regcmp(".*FullyUpdated.*","$(updatevariable)");
commands:
!fully-updated::
"/something/unintended";
If "some_random_command" fails, however, due to a NFS mount going away,
bug in the code, whatever the case, the "fully-updated" class will not
activate in doing a match against erroneous output and I can no longer
guarantee intent in the remaining promise. Wouldn't a "regzeroresult"
function along the lines of:
class-name expression => regzeroresult("EXAMPLE.*","$(command)",
"true");
be useful? The third option would cause the class to either be
activated or deactivated if the command finishes with a non-zero exit
status. Not only would such a function give the operator a means to
readily account for failed command execution but it would result in more
compact, readable promises (no stringing together regcmp, returnszero,
execresult).
I can think of two work-arounds, one being using "returnszero" against
the same command and logically ANDing the result with the class set by
regcmp. This seems like a bit of a kludge and does not guarantee true
consistency since the act of executing the command once may influence
subsequent execution.
The second workaround I can think of is to use a shell script in command
module mode such that there is logic surrounding the exit status of the
target executable. While this would work it violates the cfengine
design principle of keeping logic exposed and not tucked away in shell
scripts.
Any thoughts?
Thanks,
Frans
_______________________________________________
Help-cfengine mailing list
[email protected]
https://cfengine.org/mailman/listinfo/help-cfengine