Re: variable if class

"'Nick Anderson' via help-cfengine" <[email protected]>
Newsgroups gmane.comp.sysutils.cfengine.general
Message-ID <[email protected]>
Xander Cage <[email protected]> writes:

Hi Xander,

You were missing the `$(user)' variable in your condition guarding your
/reports/ type promise. Also, you were populating `ssh_key' with the
value of the iterated `$(user)', so it will only ever hold the last
iterated value. Instead, you can define a variable for each user ...

,----
| bundle agent var_if_test {
| 
|   vars:
|       "user" slist => {"schast", "wimm", "schama" };
| 
|       #"ssh_key_dir" string => "/root/cfe_testbed/user_ssh_keys";
|       "ssh_key_dir" string => "/tmp";
| 
|       "ssh_key_$(user)"      string => readfile("$(ssh_key_dir)/$(user).cf"),
|         if => "exists_ssh_key_$(user)";
| 
|   classes:
| 
|       "exists_ssh_key_$(user)"
|         expression => fileexists("$(ssh_key_dir)/$(user).cf");
| 
|   reports:
| 
|       "CFEngine $(sys.cf_version)";
| 
|       "$(user) -> $(ssh_key_$(user))"
|         if => "exists_ssh_key_$(user)";
| 
|       "ABSENT: $(user)"
|         unless => "exists_ssh_key_$(user)";
| 
| }
| 
| bundle agent __main__
| {
|   methods:
|       "var_if_test";
| }
`----
Listing 1: Example Policy

,----
| R: CFEngine 3.19.0a.da01eaa81
| R: wimm -> hello
| R: ABSENT: schast
| R: ABSENT: schama
`----

-- 
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/87zgqdnuwq.fsf%40northern.tech.

-- 
Nick Anderson | Doer of Things | (+1) 785-550-1767 | https://northern.tech

-- 
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/87zgqdnuwq.fsf%40northern.tech.
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.