This might help... I execute a command and wrap it up with the canonify 
function.

vars:
                        "linux_machine_model"   string  =>      
canonify(execresult("/usr/sbin/dmidecode -s system-product-name","noshell"));



Canonify is a function that will “sanitize” the input to make it happy to set a 
class against.  Once I have that string in a variable, I just call a class 
against it.  Canonify is going to replace spaces / dashes with underscores, so 
its handy to print this variable out in a reports: promise when you’re testing 
what your class will end up being called.


classes:
        linux::
                "$(linux_machine_model)"                or              =>      
{"cfengine_3"};




I assume that cfengine_3 will always be set... So, the variable 
linux_machine_model gets set as a class.  Note, it looks like you’re reading 
from a file.  Look at the reference guide under “functions that return string” 
for functions that will assist reading data from files.





On 7/19/11 9:34 AM, "no-re...@cfengine.com" <no-re...@cfengine.com> wrote:

> Forum: CFEngine Help
> Subject: Variable Class Names
> Author: jordy
> Link to topic: https://cfengine.com/forum/read.php?3,22838,22838#msg-22838
>
> Hi!!
>
> I think this question can be a newbie question, but I've searched for answers
> and I can't find any.
>
> I have a variable that can have different strings depending of the server. The
> question is that I want to convert the content of this variable in a class
> name.
>
> For example:
>
>
> {bunde agent my_app {
>
> vars:
>      server_type => (read from file and it can be: db_server, app_server,
> dns_server, etc.)
>
> files:
>
>    db_server::
>           "XXXXXXX"
>
>    app_server::
>           "XXXXXXX"
>
>    dns_server::
>           "XXXXXXX"
>
>    etc..
> }
>
>
>
> Anyone knows how can I reach this behavior?
>
> Thank you
>
>
> Jorge
>
> _______________________________________________
> Help-cfengine mailing list
> Help-cfengine@cfengine.org
> https://cfengine.org/mailman/listinfo/help-cfengine
_______________________________________________
Help-cfengine mailing list
Help-cfengine@cfengine.org
https://cfengine.org/mailman/listinfo/help-cfengine

Reply via email to