Forum: CFEngine Help
Subject: Re: variables changing between passes
Author: neilhwatson
Link to topic: https://cfengine.com/forum/read.php?3,22924,22925#msg-22925

In the verbose output or cf-promises and the agent there is mention of 
reevaluating variables.  I expect that this is the problem.  Here is a small 
example to illustrate it.
neil@ettin ~/.cfagent/inputs $ cat passwd-get.cf 
body common control {

    bundlesequence => {
        "recipe",
    };

    inputs => {
        "cfengine_stdlib.cf",
    };
}

bundle agent recipe {

    vars:
        "pw" string => execresult("/usr/bin/apg -n 1 -m 15 -q","noshell"),
        policy => "constant";

    reports:
        linux::
            "Password is $(pw)";
}

neil@ettin ~/.cfagent/inputs $ cf-promises -f ./passwd-get.cf 
 !! Redefinition of a constant scalar "pw" (was ovPyarar2DracUp now 
ajDuinvalyucyeu)
Promise (version not specified) belongs to bundle 'recipe' in file 
'./passwd-get.cf' near line 15
 !! Redefinition of a constant scalar "pw" (was ajDuinvalyucyeu now 
ougTanhypwicVap)
Promise (version not specified) belongs to bundle 'recipe' in file 
'./passwd-get.cf' near line 15
 !! Redefinition of a constant scalar "pw" (was ougTanhypwicVap now 
HejivVeonHaglig)
Promise (version not specified) belongs to bundle 'recipe' in file 
'./passwd-get.cf' near line 15
 !! Redefinition of a constant scalar "pw" (was HejivVeonHaglig now 
ugFacGosAcboth')
Promise (version not specified) belongs to bundle 'recipe' in file 
'./passwd-get.cf' near line 15


I think there was some discussion about this some time ago.  It this 
reevaluation desirable?  Why is it done this way? It can certainly be expensive 
if many shell commands are involved.

There might be a way to use a module.  Oddly I tried the following but had 
unexpected results.
neil@ettin ~/.cfagent/inputs $ cat passwd-get.cf 
body common control {

    bundlesequence => {
        "recipe",
    };

    inputs => {
        "cfengine_stdlib.cf",
    };
}

bundle agent recipe {

    commands:
        "/home/neil/bin/apg.cf" module => "true";

    reports:
        linux::
            "Password is ${pw}";
}

neil@ettin ~/.cfagent/inputs $ cat /home/neil/bin/apg.cf 
#!/bin/sh

pw=$(/usr/bin/apg -n 1 -m 15 -q)

printf "=pw=${pw}\n"

neil@ettin ~/.cfagent/inputs $ cf-agent -IvKf ./passwd-get.cf 
...
community>    commands in bundle recipe (1)
community>    =========================================================
community> 
community>  -> Promiser string contains a valid executable 
(/home/neil/bin/apg.cf) - ok
community> 
community>     .........................................................
community>     Promise handle: 
community>     Promise made by: /home/neil/bin/apg.cf
community>     .........................................................
community> 
community>  -> Executing '/home/neil/bin/apg.cf' 
...(timeout=-678,owner=-1,group=-1)
community>  -> (Setting umask to 77)
community> Defined variable: pw in context apg.cf with value: RufGecnubytsaid
community> M "/home/neil/bin/apg.cf":
community>  -> Finished command related to promiser "/home/neil/bin/apg.cf" -- 
succeeded
community>  -> Completed execution of /home/neil/bin/apg.cf
community> 
community>    =========================================================
community>    reports in bundle recipe (1)
community>    =========================================================
community> 
community> 
community>     .........................................................
community>     Promise handle: 
community>     Promise made by: Password is ${pw}
community>     .........................................................
community> 
community> Reporting about this...
community> R: Password is ${pw}


The variable is set but not printed via the report.

_______________________________________________
Help-cfengine mailing list
[email protected]
https://cfengine.org/mailman/listinfo/help-cfengine

Reply via email to