Skip to content
Closed
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
13 changes: 6 additions & 7 deletions cheatsheet.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -278,11 +278,10 @@ This metadata won't be shown in the resulting HTML (it will be converted to the
bundle agent hello_world
{
meta:
"tags"
slist => { "autorun" };
"tags" slist => { "autorun" };

vars:
"github_path"
string => "/tmp/github.com";
"github_path" string => "/tmp/github.com";
}
```

Expand All @@ -302,7 +301,6 @@ If you want CFEngine syntax highlighting, use

```cf3
# CFEngine code block

bundle agent example()
{
}
Expand Down Expand Up @@ -463,8 +461,9 @@ If you want to include a code block within a list, align it just as you would wi

```cf3
# CFEngine block

bundle agent example() {}
bundle agent example()
{
}
```

2. Second
Expand Down
6 changes: 2 additions & 4 deletions content/examples/_index.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,7 @@ Example:
```cf3 {file="hello_world.cf"}
body common control
{
inputs => {
"libraries/cfengine_stdlib.cf",
};
inputs => { "libraries/cfengine_stdlib.cf", };
}
```

Expand Down Expand Up @@ -204,7 +202,7 @@ doing the following on your policy server:
```cf3
body common control
{
bundlesequence => { "hello_world" };
bundlesequence => { "hello_world" };
}
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,16 @@ body common control
bundle agent edit_name_resolution
{
files:
"/tmp/resolv.conf" # This is for testing, change to "$(sys.resolv)" to put in production
comment => "Add lines to the resolver configuration",
create => "true", # Make sure the file exists, create it if not
edit_line => resolver, # Call the resolver bundle defined below to do the editing
edit_defaults => empty; # Baseline memory model of file to empty before processing
# bundle edit_line resolver
"/tmp/resolv.conf"
# This is for testing, change to "$(sys.resolv)" to put in production
comment => "Add lines to the resolver configuration",
create => "true",
# Make sure the file exists, create it if not
edit_line => resolver,
# Call the resolver bundle defined below to do the editing
edit_defaults => empty;
# Baseline memory model of file to empty before processing
# bundle edit_line resolver
}

bundle edit_line resolver
Expand All @@ -33,9 +37,10 @@ bundle edit_line resolver
# Class/context where you use the below nameservers. Change to appropriate class
# for your system (if not any::, for example server_group::, ubuntu::, etc.)
# insert the search domain or name servers we want
"search mydomain.tld"
location => start; # Replace mydomain.tld with your domain name
# The search line will always be at the start of the file
"search mydomain.tld" location => start;

# Replace mydomain.tld with your domain name
# The search line will always be at the start of the file
"nameserver 128.39.89.8";
"nameserver 128.39.74.66";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,51 +23,46 @@ bundle agent example
{
vars:
linux::
"interface"
string => execresult("/sbin/ifconfig eth0", "noshell");
"interface" string => execresult("/sbin/ifconfig eth0", "noshell");

solaris::
"interface"
string => execresult("/usr/sbin/ifconfig bge0", "noshell");
"interface" string => execresult("/usr/sbin/ifconfig bge0", "noshell");

freebsd::
"interface"
string => execresult("/sbin/ifconfig le0", "noshell");
"interface" string => execresult("/sbin/ifconfig le0", "noshell");

darwin::
"interface"
string => execresult("/sbin/ifconfig en0", "noshell");

"interface" string => execresult("/sbin/ifconfig en0", "noshell");
# Use the CFEngine function 'regextract' to match the MAC address,
# assign it to an array called mac and set a class to indicate positive match
classes:
linux::
"ok"
expression => regextract(
".*HWaddr ([^\s]+).*(\n.*)*", # pattern to match
"$(interface)", # string to scan for pattern
"mac" # put the text that matches the pattern into this array
".*HWaddr ([^\s]+).*(\n.*)*",
# pattern to match
"$(interface)",
# string to scan for pattern
"mac"
# put the text that matches the pattern into this array
);

solaris|freebsd::
"ok"
expression => regextract(
".*ether ([^\s]+).*(\n.*)*",
"$(interface)",
"mac"
".*ether ([^\s]+).*(\n.*)*", "$(interface)", "mac"
);

darwin::
"ok"
expression => regextract(
"(?s).*ether ([^\s]+).*(\n.*)*",
"$(interface)",
"mac"
"(?s).*ether ([^\s]+).*(\n.*)*", "$(interface)", "mac"
);

# Report on the result
reports:
ok::
"MAC address is $(mac[1])"; # return first element in array "mac"

"MAC address is $(mac[1])";
# return first element in array "mac"
}
```

Expand Down Expand Up @@ -99,14 +94,17 @@ bundle agent example
vars:
linux::
"interface" string => "eth0";

solaris::
"interface" string => "bge0";

freebsd::
"interface" string => "le0";

darwin::
"interface" string => "en0";

reports:
"MAC address of $(interface) is: $(sys.hardware_mac[$(interface)])";
"MAC address of $(interface) is: $(sys.hardware_mac[$(interface)])";
}
```
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,25 @@ Install desired packages.
```cf3
body common control
{
bundlesequence => { "install_packages" };
inputs => { "libraries/cfengine_stdlib.cf" };
bundlesequence => { "install_packages" };
inputs => { "libraries/cfengine_stdlib.cf" };
}

bundle agent install_packages
bundle
agent
install_packages
{

vars:
"desired_packages"
slist => { # list of packages we want
"ntp",
"lynx"
};

packages:

"$(desired_packages)" # operate on listed packages

package_policy => "add", # What to do with packages: install them.
package_method => generic; # Infer package manager (e.g. apt, yum) from the OS.
}
"desired_packages"
slist => {
# list of packages we want"ntp", "lynx" };
packages:"$(desired_packages)"
# operate on listed packagespackage_policy =>
"add",
# What to do with packages: install them.
package_method
=> generic;
# Infer package manager (e.g. apt, yum) from the OS.
}
```

Caution: package management is a dirty business. If things don't go smoothly
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,30 @@ Mounting an NFS filesystem is straightforward using CFEngine's storage promises.
```cf3
body common control
{
bundlesequence => { "mounts" };
bundlesequence => { "mounts" };
}

bundle agent mounts
{
storage:

"/mnt" mount => nfs("fileserver","/home"); # "/mnt" is the local moint point
# "fileserver" is the remote fileserver
# "/home" is the path to the remote file system
storage:
"/mnt" mount => nfs("fileserver", "/home");
# "/mnt" is the local moint point
# "fileserver" is the remote fileserver
# "/home" is the path to the remote file system
}

body mount nfs(server,source)
body mount nfs(server, source)
{
mount_type => "nfs"; # Protocol type of remote file system
mount_source => "$(source)"; # Path of remote file system
mount_server => "$(server)"; # Name or IP of remote file system server
mount_options => { "rw" }; # List of option strings to add to the file system table ("fstab")
edit_fstab => "true"; # True/false add or remove entries to the file system table ("fstab")
mount_type => "nfs";
# Protocol type of remote file system
mount_source => "$(source)";
# Path of remote file system
mount_server => "$(server)";
# Name or IP of remote file system server
mount_options => { "rw" };
# List of option strings to add to the file system table ("fstab")
edit_fstab => "true";
# True/false add or remove entries to the file system table ("fstab")
}
```

Expand Down
Loading
Loading