2

I'm looking at using CFEngine on some linux servers.
My problem is that I need to be able to apply separate policys depending on the server. I looked all over their documentation, and I cannot find anywhere that says that that can or cannot be done.
Is that possible using CFEngine? Or should I look somewhere else.

2 Answers 2

2

It's been a long time ago without using CFengine, but we faced a similar problem when we were using it. Finally, we came up with a solution, using a dynamic bundlesequence. I'm rescuing and modifying an old snippet of code, so the syntax may be wrong, but I think that you'll get an idea.

bundle common g { 
    classes: 
        "some_servers" expression => "someserver01|someserver02";
        "another_servers" expression => "anotherserver01|anotherserver02";
        # Define other classes for your hosts here as needed
    vars:
        any::
            "bs_common" slist => {
                "bundle_1"
            };

        some_servers::
            "bs" slist => {
                "@(g.bs_common)",
                "bundle_2",
                "bundle_3",
            };

        another_servers::
            "bs" slist => {
                "@(g.bs_common)",
                "bundle_3",
            };
}

body control common {
    bundlesequence => {
        "@(g.bs)",
    };
}
2

You can use classes to define where the policies will be applied, and by default Cfengine creates a class with the hostname of every server it's running.

For example, in the following promisse if the server hostname is server01 Cfengine will report "Hello master" (check syslog to read the reports), if the hostname is server02 Cfengine will report "Hello slave":

body common control
{
  bundlesequence => { "hello" };
}

bundle agent hello
{
  reports:

    server01::

      "Hello master!"
        comment => "It's just a dummy report for server01";

    server02::

      "Hello slave!"
        comment => "It's just a dummy report for server02";
}

Ps. You can run this example policy from a file named hello.cf with:

cf-agent -I -f hello.cf

You can find more information about classes and operations using them in the official docs.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .