How to best NOT run a command
"'Nick Anderson' via help-cfengine" <[email protected]> Thu, 08 Feb 2024 17:58:28 -0600
| Newsgroups | gmane.comp.sysutils.cfengine.general |
|---|---|
| Message-ID | <[email protected]> |
I have a bundle that I need to troubleshoot and I'm hoping
there is a better way of writing this.
What I have:
classes: "has_sssd_authselect" expression =>
returrnszero("/usr/bin/authselect current -r | grep
sssd > /dev/null 2>&1","useshell");
commands: has_sssd_authselect:: "/usr/bin/authselect
select sssd --force"
Basically, I want to run authselect current -r every time
the agent runs but only run authselect select sssd
--force when SSSD is NOT present.
Hi Mike,
If this is the only place that you are using that constraint then I
think that it might be slightly better to constrain the commands
promise using `if' rather than define a class via a classes promise
that uses `returnszero()'. It's less to read and it would bypass the
extra executions of functions in classes and vars promises that occurs
during pre evaluation.
,----
| bundle agent __main__
| {
| commands:
| "/usr/bin/authselect select sssd --force"
| if => not( returnzero( "/usr/bin/authselect current -r | grep sssd > /dev/null 2>&1", "useshell" ) );
| }
`----
Listing 1: Example Policy
But, if you are using that constraint for multiple promises then I
think it reads better to define a class and then use that class to
guard multiple promises like in your snippet.
Maybe that `authselect current' info is otherwise useful. If that's
the case, then it might make more sense to inventory the output from
authselect parsing it into variables that you could reference from
other places in policy or for some kind of reporting.
--
You received this message because you are subscribed to the Google Groups "help-cfengine" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/help-cfengine/87fry27bkr.fsf%40northern.tech.