Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Training sessions modifications #8

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions source/250-101-Scalars-0018-scalar.cf
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ bundle agent main {
"greeting"
string => "Hello. My name is $(name). ";

"name"
string => "Inigo Montoya";
# "name"
# string => "Inigo Montoya";

reports:

Expand Down
6 changes: 6 additions & 0 deletions source/250-101-Scalars-0411-variable_scope_2.cf
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Simplify / break in parts

body common control {
bundlesequence => { bundle_0, "bundle_1", bundle_2, bundle_4, };
}


bundle agent bundle_0 {
vars: "fruit" string => "banana";
reports: "This is bundle_0";
Expand All @@ -17,3 +22,4 @@ bundle agent bundle_2 {
}

bundle agent bundle_4 { vars: "xyzzy" string => "magic"; }

Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,15 @@ bundle agent main {
"hamburgers",
};

"second_list"
slist => {
"some item",
@(shopping_list),
"last item",
};

reports:

"Buy $(shopping_list)";
"Buy $(second_list)";
}

2 changes: 1 addition & 1 deletion source/250-120-Lists-0290-Lists_of_integers.cf
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ bundle agent main {
"my_list"

comment => "Demonstrate a list of integers",
ilist => { "1", "2", "3" };
ilist => { 1, 2, 3 };

reports:

Expand Down
2 changes: 1 addition & 1 deletion source/250-120-Lists-0300-Lists_of_real_numbers.cf
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ bundle agent main {

handle => "rlist_demo",
comment => "Create an rlist",
rlist => { "1.5", "3.0", "4.5" };
rlist => { 1.5, 3.0, 4.5 };


reports:
Expand Down
28 changes: 24 additions & 4 deletions source/250-130-Data_Structures_Arrays-0346-array_values.cf
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,36 @@ bundle agent main {

vars:

"food_prices[Apple]"
any::
"price_map"
data => '{ "Apple": 58, "Banana": 30 }';

"price_of[Apple]"
string => "58c";

"food_prices[Banana]"
"price_of[Banana]"
string => "30c";

"food"
slist => getindices("food_prices");
slist => getindices("price_of");

"prices_only"
slist => getvalues("price_of");

"for_reporting_only"
string => format("%S", "price_map");

reports:
"Values of 'food_prices' array: $(food): $(food_prices[$(food)])";
"Values of 'price_of' array: $(food): $(price_of[$(food)])";

"Just apples: $(price_of[Apple])";

"The result of the getindices call includes: $(food)";

"For printing only: $(for_reporting_only)";

"The prices (of what we don't know) include: $(prices_only)";

"Match everything with everything: $(food), $(prices_only)";

}
17 changes: 15 additions & 2 deletions source/250-210-Methods-0010-simple_example.cf
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
body file control {
inputs => {
"$(sys.libdir)/stdlib.cf"
};
}

bundle agent main {

vars:
Expand All @@ -14,6 +20,13 @@ bundle agent remove_user(user) {
commands:

"/usr/sbin/userdel $(user)";
"/bin/rm /var/spool/cron/$(user)";
"/bin/rm /var/mail/$(user)";

files:
any::
"/var/spool/cron/$(user)"
delete => tidy;

"/var/mail/$(user)"
delete => tidy;

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,19 @@ bundle agent main {
"weekend"
expression => "Saturday|Sunday";

classes:
any:: # Valid even as far back as 3.7
"weekday"
expression => "Monday|Tuesday|Wednesday|Thursday|Friday";

Monday|Tuesday|Wednesday|Thursday|Friday::
"weekday"
expression => "any"; # 3.7 and earlier require expression attribute

Monday|Tuesday|Wednesday|Thursday|Friday::
"weekday"; # In 3.10 and later the expression attribute can be left out.
# When left out, it defaults to "any".

reports:
weekend::
"Yay! I get to rest today.";
Expand Down
4 changes: 2 additions & 2 deletions source/300-040-Classes_4-0030-Ensuring_httpd_is_running.cf
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ bundle agent main {

processes:
"httpd"
restart_class => "start_httpd";
restart_class => "httpd_is_not_running";

commands:
start_httpd::
httpd_is_not_running::
"/etc/init.d/httpd start";

}
10 changes: 5 additions & 5 deletions source/310-040-Ordering-0020-normal_ordering.cf
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@
bundle agent main {

classes:
"file_exists"
"file_exists" # 4
expression => fileexists("/tmp/newfile");

"file_absent"
"file_absent" # 1
not => fileexists("/tmp/newfile");

files:
"/tmp/newfile"
"/tmp/newfile" # 2
create => "true";

reports:
file_exists::
file_exists:: # 5
"file /tmp/newfile exists";

file_absent::
file_absent:: # 3
"file /tmp/newfile does not exist";
}
8 changes: 6 additions & 2 deletions source/310-050-Knowledge_Management-0260-depends_on.cf
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,21 @@ bundle agent main

reports:

"System Check"
handle => "systems_check";
"We launched"
depends_on => { "ignition" };

"Launch!!"
depends_on => { "fuel_check", "systems_check" },
handle => "ignition",
comment => "Demonstrate flow control with depends_on";

"Fueling..."
depends_on => { "systems_check" },
handle => "fuel_check";

"System Check"
handle => "systems_check";

}

# Try to think declaratively (not imperatively), and use depends_on
Expand Down
6 changes: 5 additions & 1 deletion source/320-150-Editing_Files-0360-delete_lines.cf
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@ bundle agent main {
files:

"/etc/motd"

handle => "motd",
comment => "Create and populate motd",
create => "true",
edit_line => my_motd;

"/tmp/motd_example"
create => "true",
edit_line => my_motd;

}


Expand Down
2 changes: 2 additions & 0 deletions source/320-270-0015.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,6 @@ my hostname is {{vars.sys.fqhost}}

The value of foo is {{vars.main.foo}}

The literal value of foo is {{{vars.main.foo}}}

Have a nice day.
2 changes: 1 addition & 1 deletion source/320-270-Mustache_Templates_with_Datastate-0010.cf
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ bundle common g {


bundle agent main {
vars: "foo" string => "bar";
vars: "foo" string => "bar/baz<bif>";

files:
"/etc/motd"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,13 @@ bundle agent main {

body perms admin_group {

linux:: groups => { "wheel" };
darwin:: groups => { "admin" };
sunos:: groups => { "sys" };
linux::
groups => { "wheel" };

darwin::
groups => { "admin" };

sunos::
groups => { "sys" };

}
4 changes: 2 additions & 2 deletions source/400-010-Body_Parts-0545-parameterized_body.cf
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ bundle agent main {
handle => "set_file_attributes_automagically",
comment => "Set appropriate file attributes everywhere",
create => "true",
perms => set_mode_700_admin_group_and_specified_user("sam");
perms => admin_700_file_owned_by("mike");

}

body perms set_mode_700_admin_group_and_specified_user(user) {
body perms admin_700_file_owned_by(user) {
mode => "0700";
owners => { "$(user)" };

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ bundle agent main {

"/root/etc_group.bak"

edit_defaults => backup_timestamp,
copy_from => local_cp("/etc/group"),
comment => "Demonstrate local file copy";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ bundle agent main
handle => "or_list",
comment => "Demonstrate list form of class expression
useful for including functions",
or => { "linux",
"solaris",
fileexists("/etc/fstab")
or => {
"linux",
"solaris",
fileexists("/etc/fstab"),
};


Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,40 @@
bundle agent main {


classes:
GMT_Hr00|GMT_Hr01::
"maintenance_window_for_storage_changes"
scope => "namespace";

GMT_Hr02|GMT_Hr03::
"maintenance_window_for_ldap_changes"
scope => "namespace";

vars:
any::
"all_maintenance_window_classes"
slist => classesmatching("maintenance_window.*");

vars:
any::
"mw_numbers"
slist => { "1", "2" };

classes:
any::
"some_mw_is_set"
expression => "maintenance_window_$(mw_numbers)";

classes:

"good_technology"
meta => { "some tag", "report" },
handle => "good_technology_class",
comment => "Set a custom class based on built-in classes",
expression => "linux|solaris";
expression => "linux|(solaris.x86_64)";

reports:
good_technology::
linux|solaris::
"I love good technology"
handle => "show_respect",
comment => "Show respect for good technology";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,35 +1,34 @@
bundle agent main {

vars:
any::
"days"
handle => "days",
comment => "Build a list of days to report day of the week",
slist => { "Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday",
"Saturday",
"Sunday",
slist => {
"Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday",
"Saturday",
"Sunday",
};




reports:
"Hello world! I love $(days)s!"
comment => "Report day of the week",
ifvarclass => "$(days)";
if => "$(days)";

# The above promise creates 7 promises:
# "Hello world! I love Mondays!"
# comment => "Report day of the week",
# ifvarclass => "Monday";
# if => "Monday";
#
# ...
#
# "Hello world! I love Sundays!"
# comment => "Report day of the week",
# ifvarclass => "Sunday";
# if => "Sunday";

}
Loading