Syntax question

23 views
Skip to first unread message

Rodrigo Severo

unread,
Dec 20, 2014, 12:23:41 PM12/20/14
to help-c...@googlegroups.com
Hi,


I have the following class definitions on a bundle:

bundle agent basic_classes
{
....
classes:
...
"server" or => { "@(server_types)" };
"workstation" expression => "!server";
}

How could I define workstation from server_types without creating an
intermediate server class?


Regards,

Rodrigo Severo

Nick Anderson

unread,
Dec 20, 2014, 1:50:02 PM12/20/14
to help-c...@googlegroups.com, Rodrigo Severo
Maybe

"workstation" expression => none(".*",  server_types);

https://docs.cfengine.com/latest/reference-functions-none.html



Sent from my mobile device.
--
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 help-cfengin...@googlegroups.com.
To post to this group, send email to help-c...@googlegroups.com.
Visit this group at http://groups.google.com/group/help-cfengine.
For more options, visit https://groups.google.com/d/optout.

Brian Bennett

unread,
Dec 21, 2014, 3:31:14 AM12/21/14
to Nick Anderson, help-c...@googlegroups.com, Rodrigo Severo
This would work, but your original example is appropriate on its own. On a host where none of the server types match, the class server doesn't actually get defined. So `expression => "!server"` or `not => "server"` doesn't actually depend on an intermediary class.

-- 
Brian Bennett
Looking for CFEngine training?

Rodrigo Severo

unread,
Dec 21, 2014, 5:52:57 AM12/21/14
to Nick Anderson, help-c...@googlegroups.com
On Sat, Dec 20, 2014 at 4:49 PM, Nick Anderson
<nick.a...@cfengine.com> wrote:
> Maybe
>
> "workstation" expression => none(".*", server_types);
>
> https://docs.cfengine.com/latest/reference-functions-none.html

Great. Thanks.


Rodrigo

Rodrigo Severo

unread,
Dec 21, 2014, 5:54:01 AM12/21/14
to Brian Bennett, Nick Anderson, help-c...@googlegroups.com
On Sun, Dec 21, 2014 at 6:31 AM, Brian Bennett
<brian....@verticalsysadmin.com> wrote:
> This would work, but your original example is appropriate on its own. On a
> host where none of the server types match, the class server doesn't actually
> get defined. So `expression => "!server"` or `not => "server"` doesn't
> actually depend on an intermediary class.

Good to know. I really need to learn to think the cfengine way.


Thanks,

Rodrigo

Alex Georgopoulos

unread,
Dec 23, 2014, 3:29:23 PM12/23/14
to help-c...@googlegroups.com, brian....@verticalsysadmin.com, nick.a...@cfengine.com
While I will agree with Brian's assessment I just want to chime in and say that I feel Nicks solutions is "safer".  I find using a "!class" can sometimes get you into a negative knowledge situation.  A !class is always true unless class is defined.  If those server classes are not defined by the time you call this bundle you could end up defining both classes.  I have been bitten by doing something very similar to what you have in your code snippet.  Coming from a positive point of view seems to have more deterministic results.  YMMV of course.

Nick Anderson

unread,
Dec 23, 2014, 4:10:40 PM12/23/14
to help-c...@googlegroups.com, Alex Georgopoulos, brian....@verticalsysadmin.com
Yes, not knowing, and not knowing yet are slightly different things. Not knowing for sure is slightly better than not knowing indirectly. It's one of those differences that doesn't matter until it does.

Sent from my mobile device.

-----Original Message-----

Brian Bennett

unread,
Dec 23, 2014, 4:11:32 PM12/23/14
to Alex Georgopoulos, help-c...@googlegroups.com, Nick Anderson
On Dec 23, 2014, at 12:29 PM, Alex Georgopoulos <ageo...@gmail.com> wrote:
While I will agree with Brian's assessment I just want to chime in and say that I feel Nicks solutions is "safer".  I find using a "!class" can sometimes get you into a negative knowledge situation.  A !class is always true unless class is defined.  If those server classes are not defined by the time you call this bundle you could end up defining both classes.  I have been bitten by doing something very similar to what you have in your code snippet.  Coming from a positive point of view seems to have more deterministic results.  YMMV of course.

But if server_types is not defined (or empty) then `none(".*",  server_types)` will still yield a positive result.

The following workstation class definitions are identical. They will always be defined (or not) together since they are all a negative assertion, directly or indirectly, of any element in the list server_types.

"server" or => { "@{server_types}" };
"workstation1" expression => "!server";
"workstation2" not => "server";
"workstation3" expression => none(".*", server_types);

In order to have a positive assertion for workstation classes there needs to be a positive identifier for workstations, I agree, but none() won't give that to you.

-- 
Brian Bennett
Looking for CFEngine training?
Seats available for 4-day class beginning Feb 2, 2015
http://www.verticalsysadmin.com/

Nick Anderson

unread,
Dec 23, 2014, 4:18:01 PM12/23/14
to Alex Georgopoulos, Brian Bennett, help-c...@googlegroups.com
Well the regex could be changed to something sensible.


Sent from my mobile device.

-----Original Message-----
From: Brian Bennett <brian....@verticalsysadmin.com>
To: Alex Georgopoulos <ageo...@gmail.com>
Cc: help-c...@googlegroups.com, Nick Anderson <nick.a...@cfengine.com>
Sent: Tue, 23 Dec 2014 3:11 PM
Subject: Re: [help-cfengine] Syntax question

Alex Georgopoulos

unread,
Dec 23, 2014, 4:27:30 PM12/23/14
to help-c...@googlegroups.com, ageo...@gmail.com, nick.a...@cfengine.com, brian....@verticalsysadmin.com
Correct me if I am wrong but I thought If the RHS doesn't expand  it won't evaluate the left hand side.  Either way you're point is taken if we have an empty list.  

If this was my policy I would have and get rid of the not or the regex thingy or using !class and just do this.
"workstation" or => { "@{workstation_types}" };

Alex Georgopoulos

unread,
Dec 23, 2014, 4:50:52 PM12/23/14
to help-c...@googlegroups.com, ageo...@gmail.com, nick.a...@cfengine.com, brian....@verticalsysadmin.com
This little snippet demonstrates how this all can go wrong and not quite give the results you expect.

  body common control
{
 bundlesequence => {
                 "basic_classes_a",
                 "basic_classes_b",
                };
}

bundle agent basic_classes_a
{

        vars:
                "server_types" slist => { "fast_server", "slow_server" };
        classes:
                "server" or => { "@(server_types)" };
                "workstation" expression => "!server";
                "$(server_types)" expression => "any";

        reports:
                server.!workstation::
                "$(this.bundle) AM a server";
                workstation.!server::
                "$(this.bundle) NOT a server";
                server.workstation::
                "$(this.bundle) BOTH server and workstation";

}

bundle agent basic_classes_b
{

        vars:
                "server_types" slist => { "fast_server", "slow_server" };
        classes:
                "$(server_types)" expression => "any";
                "server" or => { "@(server_types)" };
                "workstation" expression => "!server";

        reports:
                server.!workstation::
                "$(this.bundle) AM a server";
                workstation.!server::
                "$(this.bundle) NOT a server";
                server.workstation::
                "$(this.bundle) BOTH server and workstation";
}


cf-agent -K -f /tmp/basic_classes.cf 
2014-12-23T16:49:59-0500   notice: R: basic_classes_a NOT a server
2014-12-23T16:49:59-0500   notice: R: basic_classes_a BOTH server and workstation
2014-12-23T16:49:59-0500   notice: R: basic_classes_b AM a server

Reply all
Reply to author
Forward
0 new messages