Recent Changes - Search:

Softwares

.

CFEngine-manual-policy-example

Main.CFEngine-manual-policy-example History

Hide minor edits - Show changes to output

July 26, 2012, at 10:54 PM by 15.219.201.70 -
Added lines 1-84:
!!CFEngine manual policy example.

(:Google1:)
----
!!For CFEngine3, the Hello World policy would look like this:

Create a file with the following content - vi /var/cfengine/inputs/test.cf

(:table border=1 width=50% bgcolor=yellow cellspacing=0 :)
(:cellnr:)
[@
body common control
{
bundlesequence => { "test" };
}

bundle agent test
{
reports:
cfengine_3::
"Hello world!";
}
@]
(:tableend:)

(:Googletxt:)

(:table border=1 width=50% bgcolor=yellow cellspacing=0 :)
(:cellnr:)
[@
body common control
{
bundlesequence => { "test" };
}
@]
(:tableend:)

In this example, the body common control is used to control promise behavior by calling the bundle agent test, which is a collection of promise attributes:

(:table border=1 width=50% bgcolor=yellow cellspacing=0 :)
(:cellnr:)
[@
bundle agent test
{
reports:
cfengine_3::
"Hello world!";
}
@]
(:tableend:)

This bundle structure contains a special type of promise known as reports: , which will automatically output `Hello World' if all conditions of the promise are kept.
Finally, there is the cfengine_3:: class. This class is defined by CFEngine out of the box. When it's used in a promise, it checks to see that the CFEngine client is running version 3.

So, to summarize; the promise that you just wrote and executed checked that the version of CFEngine you are running is at version 3; and if it is at version 3, it sent the Hello World string to the command line.

Now that you have a better understanding of how the syntax works, we will go over the method we used to execute the policy.
The policy that you wrote, test.cf was manually executed by the cf-agent binary. Prior to running the cf-agent command, you checked the promise syntax by running the cf-promises binary:

(:table border=1 width=50% bgcolor=yellow cellspacing=0 :)
(:cellnr:)
[@
[root@mail.zimbra.lab ~]# cf-promises -f /var/cfengine/inputs/test.cf
[root@mail.zimbra.lab ~]#
@]
(:tableend:)

Normally, cf-promises is automatically executed by cf-agent as part of its run time operations, where, by default, it verifies the configuration syntax in the promises.cf file.
By adding the -f flag and specifying a file name and path, you directed cf-promises to check and verify the specified file only: test.cf.
In addition, we chose to run the policy manually, which is why we invoked cf-agent from the command line:

(:table border=1 width=50% bgcolor=yellow cellspacing=0 :)
(:cellnr:)
[@
[root@mail.zimbra.lab ~]# cf-agent -f /var/cfengine/inputs/test.cf
R: Hello world!
[root@mail.zimbra.lab ~]#
@]
(:tableend:)

As a rule, CFEngine is fully automated and the cf-agent binary is started by the cf-execd daemon at a user specified interval (defaults to 5 minutes).
Again, in this instance, the agent was manually started using the -f flag to execute the specified file.

(:Googlemm:)
Edit - History - Print - Recent Changes - Search
Page last modified on July 26, 2012, at 10:54 PM