Re: variable if class

Bas van der Vlies <[email protected]>
Newsgroups gmane.comp.sysutils.cfengine.general
Message-ID <[email protected]>
Hi Xander,

your syntax is not correct: if => ( "exists_ssh_key" );
must be: if => "exists_ssh_key";

regards

On 09/11/2021 13:18, Xander Cage wrote:
> 
> hi,
> 
> i read this -> 
> https://cmdln.org/2018/05/24/what-is-evaluated-first-in-cfengine-3-vars-or-classes/  
> and i tried to use this higher kind of wisdom, but ...noooo
> 
> just want to read in a file in a string var if a specific class is 
> defined eg. "the file exists".
> 
> body file control
> {
>    inputs => { "$(sys.libdir)/stdlib.cf", };
>               }
> 
> 
> 
> bundle agent var_if_test {
> 
>      vars:
>       "user" string => "schast";
> 
>       "ssh_key_dir" string => "/root/cfe_testbed/user_ssh_keys";
> 
>       "ssh_key" string => readfile("$(ssh_key_dir)/$(user).cf"),
>                 if => ( "exists_ssh_key" );
> 
> 
>      classes:
> 
> 
>              "exists_ssh_key"          expression => 
> fileexists("$(ssh_key_dir)/$(user).cf");
> 
>      reports:
> 
>          "CFEngine $(sys.cf_version)";
> 
>        "$(ssh_key)"
>          if => "exists_ssh_key";
> 
> 
> }
> 
> 
> 
> bundle agent __main__
> {
>    methods:
>        "var_if_test";
> }
> 
> error:
> 
> root@aixtest01: /root/cfe_testbed # /var/cfengine/bin/cf-agent -KI  -f 
> ./var_if_test.cf
> ./var_if_test.cf:17:23: error: syntax error
>                 if => ( "exists_ssh_key" );
>                        ^
> ./var_if_test.cf:17:23: error: Invalid r-value type '('
>                 if => ( "exists_ssh_key" );
>                        ^
> ./var_if_test.cf:17:40: error: Check previous line, Expected ';', got 
> '"exists_ssh_key"'
>                 if => ( "exists_ssh_key" );
>                                         ^
> ./var_if_test.cf:17:42: error: Expected promiser string, got ')'
>                 if => ( "exists_ssh_key" );
>                                           ^
>     error: There are syntax errors in policy files
>     error: Policy failed validation with command 
> '"/var/cfengine/bin/cf-promises" -c "./var_if_test.cf"'
>     error: Failsafe condition triggered. Interactive session detected, 
> skipping failsafe.cf execution.
>     error: Error reading CFEngine policy. Exiting...
> 
> -- 
> 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] 
> <mailto:[email protected]>.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/help-cfengine/684af289-094e-420e-85ab-af4030b20decn%40googlegroups.com 
> <https://groups.google.com/d/msgid/help-cfengine/684af289-094e-420e-85ab-af4030b20decn%40googlegroups.com?utm_medium=email&utm_source=footer>.

-- 
Bas van der Vlies
| HPCV Supercomputing | Internal Services  | SURF | 
https://userinfo.surfsara.nl |
| Science Park 140 | 1098 XG Amsterdam | Phone: +31208001300 |
|  [email protected]

-- 
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/ea801193-fae3-542c-710a-f71c7c2957c0%40surf.nl.
smime.p7s (application/pkcs7-signature, 2.3 KB) - not displayed
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.