Search code examples
linuxcfengine

Host group on CFEngine


I have to write a policy for defining various Host groups, for a particular thing it should check set of parameters according to host group.

For example I have 2 different set of web cluster, On one cluster httpd.conf is kept under /usr/local/apache/httpd.conf and for another set it is kept under /etc/httpd/httpd.conf.

I have a policy to check file changes of these configuration but I want a way in which I can define for a particular host group where exactly it should check.

Any Hint, help would be very appreciable.


Solution

  • The general answer is that you define a class for each group, and assign the appropriate path onto a variable according to that. For example:

    vars:
      group1::
        "httpd_conf" string => "/usr/local/apache/httpd.conf";
      group2::
        "httpd_conf" string => "/etc/httpd/httpd.conf";
    

    Then you use $(httpd_conf) in the file operations, and it will have the correct value according to the group.

    The potentially tricker part is how to define those classes. In this case it depends on your setup and your preferences. For example, you could define the classes by explicitly listing the hosts in each group:

    classes:
      "group1" or => { "host1", "host2", "host3" };
      "group2" or => { "host4", "host5", "host6" };
    

    Or by matching against hostname patterns:

    classes:
      "group1" expression => classmatch("grp1.*");
      "group2" expression => classmatch("grp2.*");
    

    There are other possibilities. For a full treatment, please check Defining classes for groups of hosts in Chapter 6 of my book "Learning CFEngine 3".