Re: Variables
"'Nick Anderson' via help-cfengine" <[email protected]>
| Newsgroups | gmane.comp.sysutils.cfengine.general |
|---|---|
| Message-ID | <CAE46pPvHTKRYAziQXBVfBWFMDc0jnNJyogTxfHE5t32ZuQE=bQ@mail.gmail.com> |
You might like https://docs.cfengine.com/docs/3.18/reference-functions-findprocesses.html And or https://docs.cfengine.com/docs/3.18/reference-functions-processexists.html On Fri, Nov 26, 2021, 11:44 AM thierry thunot <[email protected]> wrote: > hi !! > I did this to meet my needs > > vars: > "services_testes" slist => { "sshd","apache2","cups" }; > "test_$(services_testes)" string => execresult("/usr/bin/ps > aux|grep $(services_testes)|/usr/bin/grep -v grep |/usr/bin/grep -v \@", > "useshell"); > classes: > "service_ok_$(services_testes)" expression => strcmp(""," > $(test_$(services_testes))"); > > reports: > "Service present $(services_testes)" > unless => "service_ok_$(services_testes)"; > > "Service NON present $(services_testes)" > if => "service_ok_$(services_testes)"; > > Thank's again for your Help Nick! > Le mardi 23 novembre 2021 à 21:05:37 UTC+1, Nick Anderson a écrit : > >> thierry thunot <[email protected]> writes: >> >> Hello everyone, I have a little problem with Cf. I want to use >>> parameterized variables to create classes more easily .. I tested this for >>> apache masi it is the philosophy that interests me to do this kind of test >>> >>> bundle agent configuration_test_apache { vars: "liste_module_apache" >>> slist => {"rewrite","ssl","session"}; >>> "test_module_${liste_module_apache}_apache" string => >>> execresult("/usr/sbin/apache2ctl -M|grep >>> \({liste_module_apache}","noshell"); >>> >> > > classes: > "module_\){liste_module_apache}_nok" expression => >>> >>> strcmp("\({test_module_\){liste_module_apache}_apache}",""); reports: >>> module_${liste_module_apache}_nok:: "MODULE APACHE ${liste_module_apache} >>> pas présent"; >>> >> >>> } >>> >>> Can you advise me on the best way to proceed? Thank's !!! ;) >>> >> Hi Thierry >> >> Not sure what specifically you are looking for, but on a quick scan of >> your policy: >> >> I don't believe that you can *pipe* inside an execresult() without using >> a shell. >> >> >> execresult("/usr/sbin/apache2ctl -M|grep ${liste_module_apache}","noshell"); >> >> Also, I don't think it applies to apache modules since I don't think >> there are any whose names contain invalid class characters (e.g. -), but >> if you are creating classes from arbitrary strings, you should canonify() >> when *checking*. >> >> >> "MODULE APACHE ${liste_module_apache} pas présent" >> if => canonify( ${liste_module_apache} ); >> >> And finally, you must *quote* a variable class expression, again, beware >> if any liste_module_apache entry contains any characters that are not >> valid in a class name, this won't work. >> >> >> "module_${liste_module_apache}_nok":: >> "MODULE APACHE ${liste_module_apache} pas présent"; >> >> -- > 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/fb1c2ea7-dba9-4e11-a4d7-5a029b391c85n%40googlegroups.com > <https://groups.google.com/d/msgid/help-cfengine/fb1c2ea7-dba9-4e11-a4d7-5a029b391c85n%40googlegroups.com?utm_medium=email&utm_source=footer> > . > -- 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/CAE46pPvHTKRYAziQXBVfBWFMDc0jnNJyogTxfHE5t32ZuQE%3DbQ%40mail.gmail.com.