Skip to content
This repository has been archived by the owner on Feb 17, 2023. It is now read-only.

Commit

Permalink
Merge branch 'master' of github.com:cfengine/design-center
Browse files Browse the repository at this point in the history
  • Loading branch information
zzamboni committed Aug 28, 2012
2 parents 9a8584f + 003075f commit c6e6346
Show file tree
Hide file tree
Showing 179 changed files with 2,625 additions and 313 deletions.
6 changes: 6 additions & 0 deletions examples/verticalsysadmin_training_examples/.vimrc
@@ -0,0 +1,6 @@
filetype plugin indent on

autocmd BufRead,BufNewFile *.cf set ft=cf3
autocmd BufRead,BufNewFile *.asciidoc set ft=asciidoc

set exrc
74 changes: 15 additions & 59 deletions examples/verticalsysadmin_training_examples/0003-Exercises.txt 100755 → 100644
@@ -1,9 +1,10 @@
EXERCISES


(If you finish early, please study the Reference
Manual, chapters 1 - 4.)

1. Write a policy to signal TERM and then KILL to anyklasdjf
1. Write a policy to signal TERM and then KILL to any
process matching "trn".

Testing it:
Expand All @@ -18,14 +19,16 @@ into an slist variable. Write a promise to signal
'term' and then 'kill' to any process in that
list.

==================================================


EXERCISE 2

Write a policy to create /tmp/myname.txt and put
your name in it.




EXERCISE 3

Manually create a template:
Expand Down Expand Up @@ -80,6 +83,10 @@ observe how CFEngine dynamically configures your server.







EXERCISE 5. File Editing

Write a policy to create /etc/motd as follows:
Expand Down Expand Up @@ -201,28 +208,6 @@ a policy that logs to /var/log/repairs.txt if a promise
is repaired by CFEngine.

===============================================================
EXERCISE 9. Methods

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".


EXERCISE 10. Methods (continued).

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



============================================================

EXERCISE 11 - Precision File Editing

Expand All @@ -237,36 +222,6 @@ if [ -x /bin/custom ]
then /bin/custom
fi

EXERCISE 12 - Methods

Let's say we want our /etc/profile file to contain a line
ORGANIZATION=MyOrg to set the ORGANIZATION environment
variable when users log in.

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

Demonstrate its use by calling it from another bundle:

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


EXERCISE 13 - 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", "ORGANIZATION=MyOrg");
"any" usebundle => file_contains("/etc/motd", "Unauth. use forbidden");




Expand All @@ -293,20 +248,21 @@ Given a file /tmp/file.txt:
apples
oranges

and given that we want the file to converge to:
Use the COPBL to comment out "oranges" and append "bananas", resulting in:

apples
# oranges
bananas

use the COPBL to ensure the file contains the line
bananas (bundle edit_line insert_lines) and to ensure
the line matching "oranges" is commented out (bundle edit_line comment_lines_matching).
Hint: use "bundle edit_line insert_lines" and "bundle edit_line comment_lines_matching".


EXERCISE 17 - COPBL - contain a command

Run the command /usr/bin/id as user "nobody".

Hint: use "body contain setuid".

Run the command /usr/bin/id as user classroom.


EXERCISE 18 - COPBL - linking promises together
Expand Down
Expand Up @@ -3,7 +3,11 @@ The Most Basic Form of a Promise

promise_type:

class::

"promiser"

promise_body;
attribute1 => value1,
attribute2 => value2;


Empty file.
21 changes: 21 additions & 0 deletions examples/verticalsysadmin_training_examples/0032_do_exercise_1.txt
@@ -0,0 +1,21 @@
EXERCISE

---
A note on how to write cfengine policies:
1. sysadmin problem
2. envision the desired end state
3. translate the desired end state into CFEngine Policy Language
---

1. Write a policy to signal TERM and then KILL to any
process matching "trn".

Testing it:

cp /bin/sleep ~/trn
~/trn 1000 &
cf-agent -f ...

If you finish before everybody else, please study the
Reference Manual, chapters 1 - 4.

@@ -1,6 +1,3 @@
# commands
# A promise to execute a command.

bundle agent example
{

Expand Down
Empty file modified examples/verticalsysadmin_training_examples/0149 100755 → 100644
Empty file.
Empty file.
Expand Up @@ -11,5 +11,6 @@ bundle agent example {

depends_on => { "another_promise" } ,

create => "true";
create => "true",
comment => "Demonstrate CFEngine knowledge management features.";
}
Empty file modified examples/verticalsysadmin_training_examples/0156 100755 → 100644
Empty file.
Expand Up @@ -12,6 +12,8 @@ bundle agent example {

bundle edit_line file_contains_proper_greetings {

insert_lines: "Good morning!";
insert_lines:

"Good morning!";

}
Expand Up @@ -18,8 +18,7 @@ bundle edit_line proper_greetings {

insert_lines:

"Good morning, how are you today?";

"Good morning!";

}

4 changes: 4 additions & 0 deletions examples/verticalsysadmin_training_examples/0166_exercise.txt
@@ -0,0 +1,4 @@
EXERCISE

Write a policy to create /tmp/myname.txt and put
your name in it.
@@ -0,0 +1,17 @@
bundle agent example {

files:

"/etc/motd"

edit_line => ExpandMeFrom("/tmpl/motd.tmpl");
}

bundle edit_line ExpandMeFrom(source) {

insert_lines:

"$(source)"

insert_type => "file";
}
@@ -0,0 +1,22 @@
bundle agent example {

files:

"/etc/motd"

edit_line => ExpandMeFrom("/tmpl/motd.tmpl");
}

bundle edit_line ExpandMeFrom(source) {

delete_lines:

".*";

insert_lines:

"$(source)"

insert_type => "file",
expand_scalars => "true";
}
@@ -0,0 +1,10 @@
Note: a fully qualified variable consists of the bundle
name wherein the variable is defined plus the variable
name. Example:

bundle agent mybundle { vars: "myvar" string => "myvalue"; }

$(myvar) <--- unqualified

$(mybundle.myvar) <--- fully qualified (complete with scope)

29 changes: 29 additions & 0 deletions examples/verticalsysadmin_training_examples/0168b_exercise.txt
@@ -0,0 +1,29 @@
EXERCISE


(If you finish early, please study the Reference
Manual, chapters 1 - 4; then the special topic guide
on the Editing File Content)


Manually create a template. Embed a variable into the template:

echo 'Hello, $(mybundle.myname). The time is $(sys.date).' > /tmp/file.tmpl

Now write a policy to populate contents of /tmp/file.txt
using this template file, /tmp/file.tmpl.

Make sure your bundle defines the variable embedded in the
template, and that your bundle name matches the bundle name
embedded in the template.

Your policy should use an edit_lines bundle containing an
insert_lines promise with the following attributes:

insert_type => "file",
expand_scalars => "true";

If you finish before rest of the group, finish studying
the CFEngine Reference Manual chapters 1 -4, and if you
finish that, then study the Special Topic guide on Editing
File Content.
1 change: 1 addition & 0 deletions examples/verticalsysadmin_training_examples/0181 100755 → 100644
@@ -0,0 +1 @@
Classes
@@ -0,0 +1,10 @@

. and

& and (synonym for .)

| or


( ) groupers

@@ -1,11 +1,11 @@
bundle agent example {

reports: Monday:: "Hello world! I love Mondays!";
reports: Tuesday:: "Hello world! I love Tuesdays!";
reports: Wednesday:: "Hello world! I love Wednesdays!";
reports: Thursday:: "Hello world! I love Thursdays!";
reports: Friday:: "Hello world! I love Fridays!";
reports: Saturday:: "Hello world! I love weekends!";
reports: Sunday:: "Hello world! I love weekends!";
}
reports: Monday:: "Hello world! I love Mondays!";
reports: Tuesday:: "Hello world! I love Tuesdays!";
reports: Wednesday:: "Hello world! I love Wednesdays!";
reports: Thursday:: "Hello world! I love Thursdays!";
reports: Friday:: "Hello world! I love Fridays!";

reports: Saturday:: "Hello world! I love weekends!";
reports: Sunday:: "Hello world! I love weekends!";
}
Expand Up @@ -4,7 +4,7 @@ bundle agent example {

linux.Hr12:: "Linux system AND we are in the 12th hour.";

linux.Hr15:: "Linux system AND we are in the 15th hour.";
linux.Hr13:: "Linux system AND we are in the 13th hour.";


linux&Hr22:: "Linux system AND we are in the 22nd hour.";
Expand Down
Expand Up @@ -2,15 +2,15 @@ bundle agent example {

processes:

"^cupsd"
"cupsd"

restart_class => "restart_cups",
comment => "We DO want print services";
restart_class => "cups_needs_to_be_started",
comment => "We DO want print services";


commands:

restart_cups::
cups_needs_to_be_started::

"/etc/init.d/cups"

Expand Down
21 changes: 21 additions & 0 deletions examples/verticalsysadmin_training_examples/0252_logical_not.cf
@@ -0,0 +1,21 @@
bundle agent example {

reports:

linux::

"Yay Linux!";


reports:

!linux::

"I miss my Linux...";

reports:

!windows::

"Thank goodness it ain't Windows.";
}

0 comments on commit c6e6346

Please sign in to comment.