EXERCISE 1

Practice using "methods" type promises

Write a policy that has two bundles.

The first bundle does something visible (such as a
reports type promise that says "bundle1") AND calls
the second bundle.

The second bundle reports "bundle2".

What output will you see and in what order?  Why?
Now run your policy and check.



EXERCISE 2

Now parameterize the 2nd bundle -- have the
first bundle feed it an argument, and have the
2nd bundle display that argument.


EXERCISE 3
bundle2("State Farm", "IL")


bundle2("$(org)")


Sysadmin Problem:

/etc/profile should set the ORGANIZATION environment
variable when users log in:

   export ORGANIZATION=MyOrg

Policy Writing Exercise:

Write a bundle "etc_profile_contains" that would take an argument
and ensure /etc/profile contains the text string specified
in the argument.

Demonstrate its use by calling it from another bundle:

    bundle agent example { 
       methods:  
         "any"
             usebundle => etc_profile_contains("export ORGANIZATION=MyOrg");
    }


EXERCISE  Methods (re-usable bundles)

Make a bundle called file_contains that takes two arguments:
a filename, and a text string.  The bundle should ensure that
the file specified in the first argument contains the text string
specified in the second argument.  Example:

    methods:
     "any" usebundle => file_contains("/etc/profile", "export ORGANIZATION=MyOrg");
     "any" usebundle => file_contains("/etc/motd", "Unauth. use forbidden");


EXERCISE  Methods

Configuring a web server.

Write a bundle "webserver" that will ensure an Apache httpd package is
installed and process is running if its argument is "on":

     methods:

        "any"

             usebundle => webserver("on");

Then, make sure httpd is not running if its argument is "off".

Hints:
- The CFEngine function strcmp() can compare two strings.

Reference:
039-0085_Basic_Examples:_Classes_and_Reports.__soft-class.cf
















