Re: How to best NOT run a command
Michael Dahlberg <[email protected]> Fri, 9 Feb 2024 05:32:45 -0800 (PST)
| Newsgroups | gmane.comp.sysutils.cfengine.general |
|---|---|
| Message-ID | <[email protected]> |
Nick:
Thank you very much. This is exactly what I needed.
Two quick questions:
(1) We're using 3.18 and it looks as if it uses `ifelse` rather than `if`.
Is that correct?
(2) In the "Agent is In", you and Craig usually do a test run of the
bundles from the command line. Can you do that just by
$ cf-agent name-of-bundle
Thanks again,
Mike
On Thursday, February 8, 2024 at 6:58:32 PM UTC-5 [email protected]
wrote:
> 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.
> Listing 1: Example Policy
>
> 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" ) );}
>
> 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/0c317129-86a4-433c-b4db-52873d7694bdn%40googlegroups.com.