diff --git a/cheatsheet.markdown b/cheatsheet.markdown index 4a6d99ebb..e6b987a29 100644 --- a/cheatsheet.markdown +++ b/cheatsheet.markdown @@ -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"; } ``` @@ -302,7 +301,6 @@ If you want CFEngine syntax highlighting, use ```cf3 # CFEngine code block - bundle agent example() { } @@ -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 diff --git a/content/examples/_index.markdown b/content/examples/_index.markdown index 68c1f4e5c..3e5f0bb48 100644 --- a/content/examples/_index.markdown +++ b/content/examples/_index.markdown @@ -140,9 +140,7 @@ Example: ```cf3 {file="hello_world.cf"} body common control { - inputs => { - "libraries/cfengine_stdlib.cf", - }; + inputs => { "libraries/cfengine_stdlib.cf" }; } ``` @@ -204,7 +202,7 @@ doing the following on your policy server: ```cf3 body common control { - bundlesequence => { "hello_world" }; + bundlesequence => { "hello_world" }; } ``` diff --git a/content/examples/example-snippets/promise-patterns/example_edit_name_resolution.markdown b/content/examples/example-snippets/promise-patterns/example_edit_name_resolution.markdown index e033d323c..724d6d843 100644 --- a/content/examples/example-snippets/promise-patterns/example_edit_name_resolution.markdown +++ b/content/examples/example-snippets/promise-patterns/example_edit_name_resolution.markdown @@ -18,12 +18,12 @@ 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 @@ -33,9 +33,8 @@ 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"; } diff --git a/content/examples/example-snippets/promise-patterns/example_find_mac_addr.markdown b/content/examples/example-snippets/promise-patterns/example_find_mac_addr.markdown index 9376bb4f4..23fa024f7 100644 --- a/content/examples/example-snippets/promise-patterns/example_find_mac_addr.markdown +++ b/content/examples/example-snippets/promise-patterns/example_find_mac_addr.markdown @@ -23,20 +23,16 @@ 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 @@ -44,30 +40,27 @@ bundle agent example 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" } ``` @@ -99,14 +92,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)])"; } ``` diff --git a/content/examples/example-snippets/promise-patterns/example_install_package.markdown b/content/examples/example-snippets/promise-patterns/example_install_package.markdown index 21e7bcc5a..b0b51befd 100644 --- a/content/examples/example-snippets/promise-patterns/example_install_package.markdown +++ b/content/examples/example-snippets/promise-patterns/example_install_package.markdown @@ -12,26 +12,24 @@ 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 { - -vars: + 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. + 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. } ``` diff --git a/content/examples/example-snippets/promise-patterns/example_mount_nfs.markdown b/content/examples/example-snippets/promise-patterns/example_mount_nfs.markdown index 119abb770..6e64d8f3d 100644 --- a/content/examples/example-snippets/promise-patterns/example_mount_nfs.markdown +++ b/content/examples/example-snippets/promise-patterns/example_mount_nfs.markdown @@ -12,25 +12,24 @@ 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") } ``` diff --git a/content/examples/example-snippets/promise-patterns/example_ntp.markdown b/content/examples/example-snippets/promise-patterns/example_ntp.markdown index 46ddab070..fc53a3f1e 100644 --- a/content/examples/example-snippets/promise-patterns/example_ntp.markdown +++ b/content/examples/example-snippets/promise-patterns/example_ntp.markdown @@ -19,26 +19,18 @@ bundle agent system_time_ntp { vars: linux:: - "cache_dir" - string => "$(sys.workdir)/cache"; # Cache directory for NTP config files - "ntp_conf" - string => "/etc/ntp.conf"; # Target file for NTP configuration - "ntp_server" - string => "172.16.12.161"; - "ntp_network" - string => "172.16.12.0"; # IP address and netmask of your local NTP server - "ntp_mask" - string => "255.255.255.0"; - "ntp_pkgs" - slist => { "ntp" }; # NTP packages to be installed to ensure service - -# Define a class for the NTP server + "cache_dir" string => "$(sys.workdir)/cache"; # Cache directory for NTP config files + "ntp_conf" string => "/etc/ntp.conf"; # Target file for NTP configuration + "ntp_server" string => "172.16.12.161"; + "ntp_network" string => "172.16.12.0"; # IP address and netmask of your local NTP server + "ntp_mask" string => "255.255.255.0"; + "ntp_pkgs" slist => { "ntp" }; # NTP packages to be installed to ensure service + # Define a class for the NTP server classes: any:: - "ntp_hosts" - or => { classmatch(canonify("ipv4_$(ntp_server)")) }; + "ntp_hosts" or => { classmatch(canonify("ipv4_$(ntp_server)")) }; -# Ensure that the NTP packages are installed + # Ensure that the NTP packages are installed packages: ubuntu:: "$(ntp_pkgs)" @@ -46,34 +38,39 @@ bundle agent system_time_ntp package_policy => "add", package_method => generic; -# Ensure existence of file and directory for NTP drift learning statistics + # Ensure existence of file and directory for NTP drift learning statistics files: linux:: "/var/lib/ntp/ntp.drift" comment => "Enable ntp service", create => "true"; + "/var/log/ntpstats/." comment => "Create a statistic directory", - perms => mog("644","ntp","ntp"), + perms => mog("644", "ntp", "ntp"), create => "true"; + ntp_hosts:: # Build the cache configuration file for the NTP server "/var/cfengine/cache/ntp.conf" comment => "Build $(this.promiser) cache file for NTP server", create => "true", edit_defaults => empty, - edit_line => restore_ntp_master("$(ntp_network)","$(ntp_mask)"); + edit_line => restore_ntp_master("$(ntp_network)", "$(ntp_mask)"); + centos.ntp_hosts:: # Copy the cached configuration file to its target destination "$(ntp_conf)" comment => "Ensure $(this.promiser) in a perfect condition", copy_from => local_cp("$(cache_dir)/ntp.conf"), classes => if_repaired("refresh_ntpd_centos"); + ubuntu.ntp_hosts:: "$(ntp_conf)" - comment => "Ensure $(this.promiser) in a perfect condition", - copy_from => local_cp("$(cache_dir)/ntp.conf"), - classes => if_repaired("refresh_ntpd_ubuntu"); + comment => "Ensure $(this.promiser) in a perfect condition", + copy_from => local_cp("$(cache_dir)/ntp.conf"), + classes => if_repaired("refresh_ntpd_ubuntu"); + !ntp_hosts:: # Build the cache configuration file for the NTP client "$(cache_dir)/ntp.conf" @@ -81,39 +78,39 @@ bundle agent system_time_ntp create => "true", edit_defaults => empty, edit_line => restore_ntp_client("$(ntp_server)"); + centos.!ntp_hosts:: # Copy the cached configuration file to its target destination "$(ntp_conf)" comment => "Ensure $(this.promiser) in a perfect condition", copy_from => local_cp("$(cache_dir)/ntp.conf"), classes => if_repaired("refresh_ntpd_centos"); + ubuntu.!ntp_hosts:: "$(ntp_conf)" comment => "Ensure $(this.promiser) in a perfect condition", copy_from => local_cp("$(cache_dir)/ntp.conf"), classes => if_repaired("refresh_ntpd_ubuntu"); -# Set classes (conditions) for to restart the NTP daemon if there have been any changes to configuration + # Set classes (conditions) for to restart the NTP daemon if there have been any changes to configuration processes: centos:: - "ntpd.*" - restart_class => "refresh_ntpd_centos"; + "ntpd.*" restart_class => "refresh_ntpd_centos"; + ubuntu:: - "ntpd.*" - restart_class => "refresh_ntpd_ubuntu"; + "ntpd.*" restart_class => "refresh_ntpd_ubuntu"; -# Restart the NTP daemon if the configuration has changed + # Restart the NTP daemon if the configuration has changed commands: refresh_ntpd_centos:: "/etc/init.d/ntpd restart"; + refresh_ntpd_ubuntu:: "/etc/init.d/ntp restart"; - } ####################################################### - -bundle edit_line restore_ntp_master(network,mask) +bundle edit_line restore_ntp_master(network, mask) { vars: "list" @@ -155,7 +152,6 @@ restrict $(network) mask $(mask) nomodify notrap"; } ####################################################### - bundle edit_line restore_ntp_client(serverip) { vars: @@ -200,12 +196,11 @@ bundle agent time_management { vars: any:: - "ntp_server" - string => "no.pool.ntp.org"; + "ntp_server" string => "no.pool.ntp.org"; + commands: any:: - "/usr/sbin/ntpdate $(ntp_server)" - contain => silent; + "/usr/sbin/ntpdate $(ntp_server)" contain => silent; } ``` diff --git a/content/examples/example-snippets/promise-patterns/example_process_kill.markdown b/content/examples/example-snippets/promise-patterns/example_process_kill.markdown index 0db429fca..31ac7f50a 100644 --- a/content/examples/example-snippets/promise-patterns/example_process_kill.markdown +++ b/content/examples/example-snippets/promise-patterns/example_process_kill.markdown @@ -13,18 +13,14 @@ it to make sure that any undesired process is not running. ```cf3 body common control { -bundlesequence => { "process_kill" }; + bundlesequence => { "process_kill" }; } bundle agent process_kill { -processes: - - "sleep" - - signals => { "term", "kill" }; #Signals are presented as an ordered list to the process. - #On Windows, only the kill signal is supported, which terminates the process. - + processes: + "sleep" signals => { "term", "kill" }; #Signals are presented as an ordered list to the process. + #On Windows, only the kill signal is supported, which terminates the process. } ``` diff --git a/content/examples/example-snippets/promise-patterns/example_process_restart.markdown b/content/examples/example-snippets/promise-patterns/example_process_restart.markdown index 8afe9b08f..97c07bc88 100644 --- a/content/examples/example-snippets/promise-patterns/example_process_restart.markdown +++ b/content/examples/example-snippets/promise-patterns/example_process_restart.markdown @@ -12,30 +12,27 @@ This is a standalone policy that will restart three CFEngine processes if they a ```cf3 body common control { -bundlesequence => { "process_restart" }; + bundlesequence => { "process_restart" }; } bundle agent process_restart { -vars: - - "component" slist => { # List of processes to monitor - "cf-monitord", - "cf-serverd", - "cf-execd" - }; - -processes: - - "$(component)" + vars: + "component" + slist => { + # List of processes to monitor + "cf-monitord", + "cf-serverd", + "cf-execd", + }; + + processes: + "$(component)" # Set the class "_not_running" if it is not running: restart_class => canonify("$(component)_not_running"); -commands: - - "/var/cfengine/bin/$(component)" - if => canonify("$(component)_not_running"); - + commands: + "/var/cfengine/bin/$(component)" if => canonify("$(component)_not_running"); } ``` diff --git a/content/examples/example-snippets/promise-patterns/example_sudoers.markdown b/content/examples/example-snippets/promise-patterns/example_sudoers.markdown index a7c5e775d..4261cdf43 100644 --- a/content/examples/example-snippets/promise-patterns/example_sudoers.markdown +++ b/content/examples/example-snippets/promise-patterns/example_sudoers.markdown @@ -12,27 +12,22 @@ Setting up sudo is straightforward, we recommend managing it by copying trusted ```cf3 body common control { -bundlesequence => { "sudoers" }; -inputs => { "libraries/cfengine_stdlib.cf" }; + bundlesequence => { "sudoers" }; + inputs => { "libraries/cfengine_stdlib.cf" }; } bundle agent sudoers { - -# Define the master location of the sudoers file -vars: - - "master_location" string => "/var/cfengine/masterfiles"; - -# Copy the master sudoers file to /etc/sudoers -files: - - "/tmp/sudoers" # change to /etc/sudoers to use in production - - comment => "Make sure the sudo configuration is secure and up to date", - perms => mog("440","root","root"), - copy_from => secure_cp("$(master_location)/sudoers","$(sys.policy_hub)"); - + # Define the master location of the sudoers file + vars: + "master_location" string => "/var/cfengine/masterfiles"; + + # Copy the master sudoers file to /etc/sudoers + files: + "/tmp/sudoers" # change to /etc/sudoers to use in production + comment => "Make sure the sudo configuration is secure and up to date", + perms => mog("440", "root", "root"), + copy_from => secure_cp("$(master_location)/sudoers", "$(sys.policy_hub)"); } ``` diff --git a/content/examples/example-snippets/promise-patterns/example_updating_from_central_hub.markdown b/content/examples/example-snippets/promise-patterns/example_updating_from_central_hub.markdown index 5536198ce..76b1f3ad9 100644 --- a/content/examples/example-snippets/promise-patterns/example_updating_from_central_hub.markdown +++ b/content/examples/example-snippets/promise-patterns/example_updating_from_central_hub.markdown @@ -17,26 +17,22 @@ the central policy server is 10.20.30.123. ```cf3 bundle agent update { -vars: - - "master_location" string => "/var/cfengine/masterfiles"; - - "policy_server" string => "10.20.30.123", - comment => "IP address to locate your policy host."; - -files: - - "$(sys.workdir)/inputs" - - perms => system("600"), - copy_from => remote_cp("$(master_location)",$(policy_server)), - depth_search => recurse("inf"); # This ensures recursive copying of all subdirectories - - "$(sys.workdir)/bin" - - perms => system("700"), - copy_from => remote_cp("/usr/local/sbin","localhost"), - depth_search => recurse("inf"); # This ensures recursive copying of all subdirectories + vars: + "master_location" string => "/var/cfengine/masterfiles"; + + "policy_server" + string => "10.20.30.123", + comment => "IP address to locate your policy host."; + + files: + "$(sys.workdir)/inputs" + perms => system("600"), + copy_from => remote_cp("$(master_location)", $(policy_server)), + depth_search => recurse("inf"); # This ensures recursive copying of all subdirectories + "$(sys.workdir)/bin" + perms => system("700"), + copy_from => remote_cp("/usr/local/sbin", "localhost"), + depth_search => recurse("inf"); # This ensures recursive copying of all subdirectories } ``` @@ -44,11 +40,10 @@ In addition the server needs to grant access to the clients, this is done in the ```cf3 body server control - { -allowconnects => { "127.0.0.1" , "10.20.30.0/24" }; -allowallconnects => { "127.0.0.1" , "10.20.30.0/24" }; -trustkeysfrom => { "127.0.0.1" , "10.20.30.0/24" }; + allowconnects => { "127.0.0.1", "10.20.30.0/24" }; + allowallconnects => { "127.0.0.1", "10.20.30.0/24" }; + trustkeysfrom => { "127.0.0.1", "10.20.30.0/24" }; } ``` @@ -59,12 +54,8 @@ Granting access to files and folders needs to be done using `access` type promis ```cf3 bundle server my_access_rules() { -access: - - 10_20_30_123:: - - "/var/cfengine/masterfiles" - - admit => { "127.0.0.1", "10.20.30.0/24" }; + access: + 10_20_30_123:: + "/var/cfengine/masterfiles" admit => { "127.0.0.1", "10.20.30.0/24" }; } ``` diff --git a/content/examples/tutorials/custom_inventory.markdown b/content/examples/tutorials/custom_inventory.markdown index 7f9a7a70f..388b4b423 100644 --- a/content/examples/tutorials/custom_inventory.markdown +++ b/content/examples/tutorials/custom_inventory.markdown @@ -54,25 +54,28 @@ bundle agent tutorials_inventory_owner { vars: "data_source" string => "/vagrant/inventory_owner.csv"; + "owners" - data => data_readstringarray( $(data_source), "", ", ", 100, 512 ), - if => fileexists( $(data_source) ); + data => data_readstringarray($(data_source), "", ", ", 100, 512), + if => fileexists($(data_source)); "my_owner" - string => "$(owners[$(sys.uqhost)][0])", - meta => { "inventory", "attribute_name=Owner" }, + string => "$(owners[$(sys.uqhost)][0])", + meta => { "inventory", "attribute_name=Owner" }, comment => "We need to tag the owner information so that it is correctly reported via the UI."; reports: inform_mode:: "$(this.bundle): Discovered Owner='$(my_owner)'" - if => isvaribale( "my_owner" ); + if => isvaribale("my_owner"); } + bundle agent __main__ # @brief Run tutorials_inventory_owner if this policy file is the entry { - methods: "tutorials_inventory_owner"; + methods: + "tutorials_inventory_owner"; } ``` diff --git a/content/examples/tutorials/distribute-files-from-a-central-location.markdown b/content/examples/tutorials/distribute-files-from-a-central-location.markdown index 4b631bdf6..ae66748ba 100644 --- a/content/examples/tutorials/distribute-files-from-a-central-location.markdown +++ b/content/examples/tutorials/distribute-files-from-a-central-location.markdown @@ -103,10 +103,10 @@ bundle agent sync_from_policyserver(source_path, dest_path) { files: "$(dest_path)/." - handle => "sync_from_policy_server_files_dest_path_copy_from_source_path_sys_policy_hub", - copy_from => sync_cp("$(source_path)", "$(sys.policy_hub)"), + handle => "sync_from_policy_server_files_dest_path_copy_from_source_path_sys_policy_hub", + copy_from => sync_cp("$(source_path)", "$(sys.policy_hub)"), depth_search => recurse("inf"), - comment => "Ensure files from $(sys.policy_hub):$(source_path) exist in $(dest_path)"; + comment => "Ensure files from $(sys.policy_hub):$(source_path) exist in $(dest_path)"; } ``` @@ -122,20 +122,17 @@ Create `services/patching.cf` with the following content: ```cf3 {file="patching.cf"} # Patching Policy - bundle agent patching # @brief Ensure various aspects of patching are handeled - # We can break down the various parts of patching into separate bundles. This # allows us to become less overwhelmed by details if numerous specifics # exist in one or more aspect for different host classifications. { methods: - "Patch Distribution" - handle => "patching_methods_patch_distribution", + handle => "patching_methods_patch_distribution", usebundle => "patch_distribution", - comment => "Ensure patches are properly distributed"; + comment => "Ensure patches are properly distributed"; } bundle agent patch_distribution @@ -143,17 +140,18 @@ bundle agent patch_distribution { files: "$(def.dir_patch_deploy)/." - handle => "patch_distribution_files_def_dir_patch_deploy_exists", - create => "true", + handle => "patch_distribution_files_def_dir_patch_deploy_exists", + create => "true", comment => "If the destination directory does not exist, we have no place to which to copy the patches."; methods: - "Patches" - handle => "patch_distribution_methods_patches_from_policyserver_def_dir_patch_store_to_def_dir_patch_deploy", - usebundle => sync_from_policyserver("$(def.dir_patch_store)", "$(def.dir_patch_deploy)"), - comment => "Patches need to be present on host systems so that we can use + handle => "patch_distribution_methods_patches_from_policyserver_def_dir_patch_store_to_def_dir_patch_deploy", + usebundle => sync_from_policyserver( + "$(def.dir_patch_store)", "$(def.dir_patch_deploy)" + ), + comment => "Patches need to be present on host systems so that we can use them. By convention we use the policy server as the central distribution point."; } diff --git a/content/examples/tutorials/file_comparison.markdown b/content/examples/tutorials/file_comparison.markdown index b1a312ed9..56aec2fab 100644 --- a/content/examples/tutorials/file_comparison.markdown +++ b/content/examples/tutorials/file_comparison.markdown @@ -50,24 +50,18 @@ Sets up some global variables that are used frequently by other bundles. bundle common global_vars { vars: - - "gccexec" string => getenv("GCC_BIN",255); - "rmexec" string => getenv("RM_BIN",255); - - "aoutbin" string => getenv("AOUT_BIN",255); - "workdir" string => getenv("WORK_DIR",255); - + "gccexec" string => getenv("GCC_BIN", 255); + "rmexec" string => getenv("RM_BIN", 255); + "aoutbin" string => getenv("AOUT_BIN", 255); + "workdir" string => getenv("WORK_DIR", 255); "aoutexec" string => "$(workdir)/$(aoutbin)"; - - "file1name" string => getenv("CFE_FILE1",255); - "file2name" string => getenv("CFE_FILE2",255); - + "file1name" string => getenv("CFE_FILE1", 255); + "file2name" string => getenv("CFE_FILE2", 255); "file1" string => "$(workdir)/$(file1name)"; "file2" string => "$(workdir)/$(file2name)"; classes: "gclass" expression => "any"; - } ``` @@ -79,14 +73,13 @@ Ensures that the gcc package is installed, for later use by the create_aout bund bundle agent packages { vars: - "match_package" - slist => { - "gcc" - }; + "match_package" slist => { "gcc" }; + packages: "$(match_package)" package_policy => "add", package_method => yum; + reports: gclass:: "Package gcc installed"; @@ -103,12 +96,9 @@ bundle agent create_aout_source_file { # This bundle creates the source file that will be compiled in bundle agent create_aout. # See that bunlde's comments for more information. - vars: - # An slist is used here instead of a straight forward string because it doesn't seem possible to create # line endings using \n when using a string to insert text into a file. - "c" slist => { "#include ", @@ -116,18 +106,18 @@ bundle agent create_aout_source_file "#include ", "#include ", "void main()", - "{char file1[255];strcpy(file1,\"$(global_vars.file1)\");char file2[255];strcpy(file2,\"$(global_vars.file2)\");struct stat time1;int i = lstat(file1, &time1);struct stat time2;int j = lstat(file2, &time2);if (time1.st_mtime < time2.st_mtime){printf(\"Newer\");}else{if(time1.st_mtim.tv_nsec < time2.st_mtim.tv_nsec){printf(\"Newer\");}else{printf(\"Not newer\");}}}" + "{char file1[255];strcpy(file1,\"$(global_vars.file1)\");char file2[255];strcpy(file2,\"$(global_vars.file2)\");struct stat time1;int i = lstat(file1, &time1);struct stat time2;int j = lstat(file2, &time2);if (time1.st_mtime < time2.st_mtime){printf(\"Newer\");}else{if(time1.st_mtim.tv_nsec < time2.st_mtim.tv_nsec){printf(\"Newer\");}else{printf(\"Not newer\");}}}", }; + files: - "$(global_vars.workdir)/a.c" - perms => system, - create => "true", - edit_line => Insert("@(c)"); + "$(global_vars.workdir)/a.c" + perms => system, + create => "true", + edit_line => Insert("@(c)"); reports: "The source file $(global_vars.workdir)/a.c has been created. It will be used to compile the binary a.out, which will provide more accurate file stats to compare two files than the built in CFEngine functionality for comparing file stats, including modification time. This information will be used to determine of the second of the two files being compared is newer or not."; "*********************************"; - } ``` @@ -140,31 +130,34 @@ The difference between this application and using CFEngine's built in support fo ```cf3 bundle agent create_aout { - - classes: - + classes: "doesfileacexist" expression => fileexists("$(global_vars.workdir)/a.c"); "doesaoutexist" expression => fileexists("$(global_vars.aoutbin)"); vars: - # Removes any previous binary - "rmaout" string => execresult("$(global_vars.rmexec) $(global_vars.aoutexec)","noshell"); + "rmaout" + string => execresult( + "$(global_vars.rmexec) $(global_vars.aoutexec)", "noshell" + ); doesfileacexist:: - "compilestr" string => "$(global_vars.gccexec) $(global_vars.workdir)/a.c -o $(global_vars.aoutexec)"; - "gccaout" string => execresult("$(compilestr)","noshell"); + "compilestr" + string => "$(global_vars.gccexec) $(global_vars.workdir)/a.c -o $(global_vars.aoutexec)"; + + "gccaout" string => execresult("$(compilestr)", "noshell"); reports: doesfileacexist:: "gcc output: $(gccaout)"; "Creating aout using $(compilestr)"; + !doesfileacexist:: "Cannot compile a.out, $(global_vars.workdir)/a.c does not exist."; + doesaoutexist:: "The binary application aout has been compiled from the source in the create_aout_source_file bundle. It uses the stat library to compare two files, determine if the modified times are different, and whether the second file is newer than the first. The difference between this application and using CFEngine's built in support for getting file stats (e.g. filestat, isnewerthan), which provides file modification time accurate to a second. However, in order to better compare two files might sometimes require parts of a second as well. The stat library provides the extra support for retrieving the additional information required to get better accuracy (down to parts of a second), and is utilized by the binary application a.out that is compiled within the create_aout bundle."; "*********************************"; - } ``` @@ -176,8 +169,7 @@ Deletes any previous copy of the test files used in the example. bundle agent test_delete { files: - "$(global_vars.file1)" - delete => tidy; + "$(global_vars.file1)" delete => tidy; } ``` @@ -189,27 +181,28 @@ Verifies whether the test files exist or not. bundle agent do_files_exist_1 { classes: - "doesfile1exist" - expression => fileexists("$(global_vars.file1)"); - "doesfile2exist" - expression => fileexists("$(global_vars.file2)"); + "doesfile1exist" expression => fileexists("$(global_vars.file1)"); + "doesfile2exist" expression => fileexists("$(global_vars.file2)"); methods: doesfile1exist:: "any" usebundle => delete_file("$(global_vars.file1)"); + doesfile2exist:: "any" usebundle => delete_file("$(global_vars.file2)"); reports: !doesfile1exist:: "$(global_vars.file1) does not exist."; + doesfile1exist:: "$(global_vars.file1) did exist. Call to delete it was made."; + !doesfile2exist:: "$(global_vars.file2) does not exist."; + doesfile2exist:: "$(global_vars.file2) did exist. Call to delete it was made."; - } ``` @@ -220,7 +213,6 @@ Creates the first test file, as an empty file. ```cf3 bundle agent create_file_1 { - files: "$(global_vars.file1)" perms => system, @@ -253,11 +245,10 @@ Makes a copy of the test file. bundle agent copy_a_file { files: - "$(global_vars.file2)" - copy_from => local_cp("$(global_vars.file1)"); + "$(global_vars.file2)" copy_from => local_cp("$(global_vars.file1)"); reports: - "$(global_vars.file1) has been copied to $(global_vars.file2)"; + "$(global_vars.file1) has been copied to $(global_vars.file2)"; } ``` @@ -268,9 +259,9 @@ Verifies that both test files exist. ```cf3 bundle agent do_files_exist_2 { - methods: - "any" usebundle => does_file_exist($(global_vars.file1)); - "any" usebundle => does_file_exist($(global_vars.file2)); + methods: + "any" usebundle => does_file_exist($(global_vars.file1)); + "any" usebundle => does_file_exist($(global_vars.file2)); } ``` @@ -284,9 +275,9 @@ bundle agent list_file_1 methods: "any" usebundle => file_content($(global_vars.file1)); "any" usebundle => file_content($(global_vars.file2)); + reports: "*********************************"; - } ``` @@ -296,19 +287,18 @@ bundle agent list_file_1 bundle agent exec_aout { classes: - "doesaoutexist" - expression => fileexists("$(global_vars.aoutbin)"); + "doesaoutexist" expression => fileexists("$(global_vars.aoutbin)"); vars: doesaoutexist:: - "aout" - string => execresult("$(global_vars.aoutexec)","noshell"); + "aout" string => execresult("$(global_vars.aoutexec)", "noshell"); reports: doesaoutexist:: "*********************************"; "$(global_vars.aoutbin) determined that $(global_vars.file2) is $(aout) than $(global_vars.file1)"; "*********************************"; + !doesaoutexist:: "Executable $(global_vars.aoutbin) does not exist."; } @@ -322,31 +312,32 @@ Compares the modified time of each test file using the binary application compil bundle agent stat { classes: - "doesfile1exist" - expression => fileexists("$(global_vars.file1)"); - "doesfile2exist" - expression => fileexists("$(global_vars.file2)"); + "doesfile1exist" expression => fileexists("$(global_vars.file1)"); + "doesfile2exist" expression => fileexists("$(global_vars.file2)"); vars: doesfile1exist:: - "file1" string => "$(global_vars.file1)"; "file2" string => "$(global_vars.file2)"; - "file1_stat" string => execresult("/usr/bin/stat -c \"%y\" $(file1)","noshell"); - "file1_split1" slist => string_split($(file1_stat)," ",3); - "file1_split2" string => nth("file1_split1",1); - "file1_split3" slist => string_split($(file1_split2),"\.",3); - "file1_split4" string => nth("file1_split3",1); + "file1_stat" + string => execresult("/usr/bin/stat -c \"%y\" $(file1)", "noshell"); + + "file1_split1" slist => string_split($(file1_stat), " ", 3); + "file1_split2" string => nth("file1_split1", 1); + "file1_split3" slist => string_split($(file1_split2), "\.", 3); + "file1_split4" string => nth("file1_split3", 1); - "file2_stat" string => execresult("/usr/bin/stat -c \"%y\" $(file2)","noshell"); - "file2_split1" slist => string_split($(file2_stat)," ",3); - "file2_split2" string => nth("file2_split1",1); - "file2_split3" slist => string_split($(file2_split2),"\.",3); - "file2_split4" string => nth("file2_split3",1); + "file2_stat" + string => execresult("/usr/bin/stat -c \"%y\" $(file2)", "noshell"); + + "file2_split1" slist => string_split($(file2_stat), " ", 3); + "file2_split2" string => nth("file2_split1", 1); + "file2_split3" slist => string_split($(file2_split2), "\.", 3); + "file2_split4" string => nth("file2_split3", 1); methods: - "any" usebundle => exec_aout(); + "any" usebundle => exec_aout(); reports: doesfile1exist:: @@ -354,9 +345,9 @@ bundle agent stat "Parts of a second extracted extracted from stat for $(file2): $(file2_split4). Full stat output for $(file2): $(file2_stat)"; "Using the binary Linux application stat to compare two files can help determine if the modified times between two files are different. The difference between the stat application using its additional flags and using CFEngine's built in support for getting and comparing file stats (e.g. filestat, isnewerthan) is that normally the accuracy is only to the second of the file's modified time. In order to better compare two files requires parts of a second as well, which the stat command can provide with some additional flags. Unfortunately the information must be extracted from the middle of a string, which is what the stat bundle accomplishes using the string_split and nth functions."; "*********************************"; + !doesfile1exist:: "stat: $(global_vars.file1) and probably $(global_vars.file2) do not exist."; - } ``` @@ -386,17 +377,27 @@ bundle agent list_file_2 "any" usebundle => file_content($(global_vars.file2)); classes: - "ok" expression => isgreaterthan(filestat("$(global_vars.file2)","mtime"),filestat("$(global_vars.file1)","mtime")); - "newer" expression => isnewerthan("$(global_vars.file2)","$(global_vars.file1)"); + "ok" + expression => isgreaterthan( + filestat("$(global_vars.file2)", "mtime"), + filestat("$(global_vars.file1)", "mtime") + ); + + "newer" + expression => isnewerthan("$(global_vars.file2)", "$(global_vars.file1)"); reports: "*********************************"; + ok:: "Using isgreaterthan+filestat determined that $(global_vars.file2) was modified later than $(global_vars.file1)."; + !ok:: "Using isgreaterthan+filestat determined that $(global_vars.file2) was not modified later than $(global_vars.file1)."; + newer:: "Using isnewerthan determined that $(global_vars.file2) was modified later than $(global_vars.file1)."; + !newer:: "Using isnewerthan determined that $(global_vars.file2) was not modified later than $(global_vars.file1)."; } diff --git a/content/examples/tutorials/files-tutorial.markdown b/content/examples/tutorials/files-tutorial.markdown index 5108895a0..7684e8ad7 100644 --- a/content/examples/tutorials/files-tutorial.markdown +++ b/content/examples/tutorials/files-tutorial.markdown @@ -15,9 +15,7 @@ aliases: ```cf3 body common control { - inputs => { - "libraries/cfengine_stdlib.cf", - }; + inputs => { "libraries/cfengine_stdlib.cf" }; } ``` @@ -33,10 +31,10 @@ Note: The following workflow assumes the directory /home/user already exists. If bundle agent list_file { vars: - "ls" - slist => lsdir("/home/user", "test_plain.txt", "true"); + "ls" slist => lsdir("/home/user", "test_plain.txt", "true"); + reports: - "ls: $(ls)"; + "ls: $(ls)"; } ``` @@ -96,8 +94,8 @@ bundle agent testbundle bundle agent list_file { vars: - "ls" - slist => lsdir("/home/user", "test_plain.txt", "true"); + "ls" slist => lsdir("/home/user", "test_plain.txt", "true"); + reports: "ls: $(ls)"; } @@ -105,9 +103,10 @@ bundle agent list_file bundle agent list_file_2 { vars: - "ls" - slist => lsdir("/home/user", "test_plain.txt", "true"); reports: - "ls: $(ls)"; + "ls" slist => lsdir("/home/user", "test_plain.txt", "true"); + + reports: + "ls: $(ls)"; } body perms system @@ -129,9 +128,7 @@ rm /home/user/test_plain.txt ```cf3 {file="file_delete.cf"} body common control { - inputs => { - "libraries/cfengine_stdlib.cf", - }; + inputs => { "libraries/cfengine_stdlib.cf" }; } bundle agent testbundle @@ -145,15 +142,14 @@ bundle agent testbundle bundle agent test_delete { files: - "/home/user/test_plain.txt" - delete => tidy; + "/home/user/test_plain.txt" delete => tidy; } bundle agent list_file { vars: - "ls" - slist => lsdir("/home/user", "test_plain.txt", "true"); + "ls" slist => lsdir("/home/user", "test_plain.txt", "true"); + reports: "ls: $(ls)"; } @@ -161,15 +157,15 @@ bundle agent list_file bundle agent list_file_2 { vars: - "ls" - slist => lsdir("/home/user", "test_plain.txt", "true"); + "ls" slist => lsdir("/home/user", "test_plain.txt", "true"); + reports: "ls: $(ls)"; } body perms system { - mode => "0640"; + mode => "0640"; } ``` @@ -197,9 +193,7 @@ ls /home/user/test_plain.txt ```cf3 {file="file_modify.cf"} body common control { - inputs => { - "libraries/cfengine_stdlib.cf", - }; + inputs => { "libraries/cfengine_stdlib.cf" }; } bundle agent testbundle @@ -213,15 +207,14 @@ bundle agent testbundle bundle agent test_delete { files: - "/home/user/test_plain.txt" - delete => tidy; + "/home/user/test_plain.txt" delete => tidy; } bundle agent list_file { vars: - "ls" - slist => lsdir("/home/user", "test_plain.txt", "true"); + "ls" slist => lsdir("/home/user", "test_plain.txt", "true"); + reports: "ls: $(ls)"; } @@ -229,8 +222,8 @@ bundle agent list_file bundle agent list_file_2 { vars: - "ls" - slist => lsdir("/home/user", "test_plain.txt", "true"); + "ls" slist => lsdir("/home/user", "test_plain.txt", "true"); + reports: "ls: $(ls)"; } @@ -257,8 +250,8 @@ bundle agent outer_bundle_2 bundle edit_line inner_bundle_1 { vars: - "msg" - string => "Helloz to World!"; + "msg" string => "Helloz to World!"; + insert_lines: "$(msg)"; } @@ -267,8 +260,7 @@ bundle edit_line inner_bundle_1 bundle edit_line inner_bundle_2 { replace_patterns: - "Helloz to World!" - replace_with => hello_world; + "Helloz to World!" replace_with => hello_world; } body replace_with hello_world @@ -279,7 +271,7 @@ body replace_with hello_world body perms system { - mode => "0640"; + mode => "0640"; } ``` @@ -294,9 +286,7 @@ rm /home/user/test_plain.txt ```cf3 {file="file_copy.cf"} body common control { - inputs => { - "libraries/cfengine_stdlib.cf", - }; + inputs => { "libraries/cfengine_stdlib.cf" }; } bundle agent testbundle @@ -305,6 +295,7 @@ bundle agent testbundle "/home/ichien/test_plain.txt" perms => system, create => "true"; + reports: "test_plain.txt has been created"; } @@ -312,8 +303,7 @@ bundle agent testbundle bundle agent test_delete { files: - "/home/ichien/test_plain.txt" - delete => tidy; + "/home/ichien/test_plain.txt" delete => tidy; } bundle agent do_files_exist @@ -321,15 +311,16 @@ bundle agent do_files_exist vars: "mylist" slist => { - "/home/ichien/test_plain.txt", - "/home/ichien/test_plain_2.txt", + "/home/ichien/test_plain.txt", "/home/ichien/test_plain_2.txt", }; + classes: - "exists" - expression => filesexist("@(mylist)"); + "exists" expression => filesexist("@(mylist)"); + reports: exists:: "test_plain.txt and test_plain_2.txt files exist"; + !exists:: "test_plain.txt and test_plain_2.txt files do not exist"; } @@ -339,15 +330,16 @@ bundle agent do_files_exist_2 vars: "mylist" slist => { - "/home/ichien/test_plain.txt", - "/home/ichien/test_plain_2.txt" + "/home/ichien/test_plain.txt", "/home/ichien/test_plain_2.txt" }; + classes: - "exists" - expression => filesexist("@(mylist)"); + "exists" expression => filesexist("@(mylist)"); + reports: exists:: "test_plain.txt and test_plain_2.txt files both exist"; + !exists:: "test_plain.txt and test_plain_2.txt files do not exist"; } @@ -355,14 +347,11 @@ bundle agent do_files_exist_2 bundle agent list_file_1 { vars: - "ls1" - slist => lsdir("/home/ichien", "test_plain.txt", "true"); - "ls2" - slist => lsdir("/home/ichien", "test_plain_2.txt", "true"); - "file_content_1" - string => readfile("/home/ichien/test_plain.txt", "33"); - "file_content_2" - string => readfile("/home/ichien/test_plain_2.txt", "33"); + "ls1" slist => lsdir("/home/ichien", "test_plain.txt", "true"); + "ls2" slist => lsdir("/home/ichien", "test_plain_2.txt", "true"); + "file_content_1" string => readfile("/home/ichien/test_plain.txt", "33"); + "file_content_2" string => readfile("/home/ichien/test_plain_2.txt", "33"); + reports: # "ls1: $(ls1)"; # "ls2: $(ls2)"; @@ -373,14 +362,11 @@ bundle agent list_file_1 bundle agent list_file_2 { vars: - "ls1" - slist => lsdir("/home/ichien", "test_plain.txt", "true"); - "ls2" - slist => lsdir("/home/ichien", "test_plain_2.txt", "true"); - "file_content_1" - string => readfile("/home/ichien/test_plain.txt", "33"); - "file_content_2" - string => readfile("/home/ichien/test_plain_2.txt", "33"); + "ls1" slist => lsdir("/home/ichien", "test_plain.txt", "true"); + "ls2" slist => lsdir("/home/ichien", "test_plain_2.txt", "true"); + "file_content_1" string => readfile("/home/ichien/test_plain.txt", "33"); + "file_content_2" string => readfile("/home/ichien/test_plain_2.txt", "33"); + reports: # "ls1: $(ls1)"; # "ls2: $(ls2)"; @@ -402,6 +388,7 @@ bundle agent copy_a_file files: "/home/ichien/test_plain_2.txt" copy_from => local_cp("/home/ichien/test_plain.txt"); + reports: "test_plain.txt has been copied to test_plain_2.txt"; } @@ -417,10 +404,11 @@ bundle agent outer_bundle_2 bundle edit_line inner_bundle_1 { vars: - "msg" - string => "Helloz to World!"; + "msg" string => "Helloz to World!"; + insert_lines: "$(msg)"; + reports: "inserted $(msg) into test_plain.txt"; } @@ -428,8 +416,8 @@ bundle edit_line inner_bundle_1 bundle edit_line inner_bundle_2 { replace_patterns: - "Helloz to World!" - replace_with => hello_world; + "Helloz to World!" replace_with => hello_world; + reports: "Text in test_plain_2.txt has been replaced"; } @@ -442,7 +430,7 @@ body replace_with hello_world body perms system { - mode => "0640"; + mode => "0640"; } ``` diff --git a/content/examples/tutorials/integrating-alerts-with-pager-duty.markdown b/content/examples/tutorials/integrating-alerts-with-pager-duty.markdown index f8f67fea6..1774863ac 100644 --- a/content/examples/tutorials/integrating-alerts-with-pager-duty.markdown +++ b/content/examples/tutorials/integrating-alerts-with-pager-duty.markdown @@ -34,17 +34,17 @@ bundle agent file_integrity { files: any:: - "/tmp/test-integrity" -> {"PCI-DSS-2", "SOX-nightmare"} + "/tmp/test-integrity" -> { "PCI-DSS-2", "SOX-nightmare" } handle => "ensure-test-file-integrity", changes => change_detection; } body changes change_detection { - hash => "md5"; - update_hashes => "true"; - report_changes => "all"; - report_diffs => "true"; + hash => "md5"; + update_hashes => "true"; + report_changes => "all"; + report_diffs => "true"; } ``` diff --git a/content/examples/tutorials/integrating-with-sumo-logic.markdown b/content/examples/tutorials/integrating-with-sumo-logic.markdown index 6245d8c00..531bc505b 100644 --- a/content/examples/tutorials/integrating-with-sumo-logic.markdown +++ b/content/examples/tutorials/integrating-with-sumo-logic.markdown @@ -163,24 +163,22 @@ The policy as found in `sumologic_policy_update.cf`. bundle agent sumo_logic_policy_update { vars: - "policy_update_file" - string => "/tmp/CFEngine_policy_updated"; - "sumo_url" - string => "https://collectors.sumologic.com/receiver/v1/http/"; - "sumo_secret" - string => "MY_SECRET_KEY"; - "curl_args" - string => "-X POST -T $(policy_update_file) $(sumo_url)$(sumo_secret)"; + "policy_update_file" string => "/tmp/CFEngine_policy_updated"; + "sumo_url" string => "https://collectors.sumologic.com/receiver/v1/http/"; + "sumo_secret" string => "MY_SECRET_KEY"; + + "curl_args" + string => "-X POST -T $(policy_update_file) $(sumo_url)$(sumo_secret)"; files: - "$(policy_update_file)" - create => "true", - edit_line => insert_str("CFEngine_update: $(sys.last_policy_update)"), - edit_defaults => file; + "$(policy_update_file)" + create => "true", + edit_line => insert_str("CFEngine_update: $(sys.last_policy_update)"), + edit_defaults => file; - "$(policy_update_file)" - classes => if_repaired("new_policy_update"), - changes => change_detections; + "$(policy_update_file)" + classes => if_repaired("new_policy_update"), + changes => change_detections; commands: new_policy_update:: @@ -193,25 +191,25 @@ bundle agent sumo_logic_policy_update body changes change_detections { - hash => "md5"; - update_hashes => "true"; - report_changes => "content"; - report_diffs => "true"; + hash => "md5"; + update_hashes => "true"; + report_changes => "content"; + report_diffs => "true"; } body contain shell_command { - useshell => "useshell"; + useshell => "useshell"; } bundle edit_line insert_str(str) { insert_lines: - "$(str)"; + "$(str)"; } body edit_defaults file { - empty_file_before_editing => "true"; + empty_file_before_editing => "true"; } ``` diff --git a/content/examples/tutorials/json-yaml-support-in-cfengine.markdown b/content/examples/tutorials/json-yaml-support-in-cfengine.markdown index dd4e2c040..3f86e219a 100644 --- a/content/examples/tutorials/json-yaml-support-in-cfengine.markdown +++ b/content/examples/tutorials/json-yaml-support-in-cfengine.markdown @@ -80,26 +80,29 @@ Easy, right? ```cf3 {file="json_example.cf"} body common control { - bundlesequence => { "run" }; + bundlesequence => { "run" }; } bundle agent run { vars: - "bykey" data => parsejson('{ "dev": ["c", "b"], "prod": ["flea"], "qa": ["a"], "private": ["linux"] }'); + "bykey" + data => parsejson( + '{ "dev": ["c", "b"], "prod": ["flea"], "qa": ["a"], "private": ["linux"] }' + ); - "keys" slist => getindices("bykey"); + "keys" slist => getindices("bykey"); classes: - # define the class from the key name if any of the items under the key match the host name - "$(keys)" expression => regcmp("$(bykey[$(keys)])", $(sys.host)); + # define the class from the key name if any of the items under the key match the host name + "$(keys)" expression => regcmp("$(bykey[$(keys)])", $(sys.host)); - # define the class from the key name if any of the items under the key are a defined class - "$(keys)" expression => classmatch("$(bykey[$(keys)])"); + # define the class from the key name if any of the items under the key are a defined class + "$(keys)" expression => classmatch("$(bykey[$(keys)])"); reports: - "keys = $(keys)"; - "I am in class $(keys)" if => $(keys); + "keys = $(keys)"; + "I am in class $(keys)" if => $(keys); } ``` diff --git a/content/examples/tutorials/manage-local-users.markdown b/content/examples/tutorials/manage-local-users.markdown index a94b8f1c8..676f38028 100644 --- a/content/examples/tutorials/manage-local-users.markdown +++ b/content/examples/tutorials/manage-local-users.markdown @@ -40,21 +40,23 @@ body common control bundle agent main { vars: - "users" slist => { "adam", "eva" }; + "users" slist => { "adam", "eva" }; + users: "$(users)" - policy => "present", - home_dir => "/home/$(users)", - group_primary => "users", - groups_secondary => { "security", "webadmin" }, - shell => "/bin/bash/", - home_bundle => setup_home_dir("$(users)"); + policy => "present", + home_dir => "/home/$(users)", + group_primary => "users", + groups_secondary => { "security", "webadmin" }, + shell => "/bin/bash/", + home_bundle => setup_home_dir("$(users)"); } bundle agent setup_home_dir(user) { vars: "keys" slist => { "id_rsa", "id_rsa.pub" }; + files: "/home/$(user)/." create => "true"; "/home/$(user)/.ssh/." create => "true"; diff --git a/content/examples/tutorials/manage-ntp.markdown b/content/examples/tutorials/manage-ntp.markdown index 1006a7b94..82cf8e8f6 100644 --- a/content/examples/tutorials/manage-ntp.markdown +++ b/content/examples/tutorials/manage-ntp.markdown @@ -15,14 +15,14 @@ Note: For simplicity, in this tutorial we will work directly on top of the Maste ```cf3 {file="ntp.cf"} bundle agent ntp { - vars: - "ntp_package_name" string => "ntp"; - - packages: - "$(ntp_package_name)" -> { "StandardsDoc 3.2.1" } - policy => "present", - handle => "ntp_packages_$(ntp_package_name)", - classes => results("bundle", "ntp_package"); + vars: + "ntp_package_name" string => "ntp"; + + packages: + "$(ntp_package_name)" -> { "StandardsDoc 3.2.1" } + policy => "present", + handle => "ntp_packages_$(ntp_package_name)", + classes => results("bundle", "ntp_package"); } ``` @@ -101,15 +101,14 @@ On your hub create `services/ntp.cf` inside _masterfiles_ with the following con ```cf3 {file="ntp.cf"} bundle agent ntp { - vars: - "ntp_package_name" string => "ntp"; - - packages: - "$(ntp_package_name)" -> { "StandardsDoc 3.2.1" } - policy => "present", - handle => "ntp_packages_$(ntp_package_name)", - classes => results("bundle", "ntp_package"); - + vars: + "ntp_package_name" string => "ntp"; + + packages: + "$(ntp_package_name)" -> { "StandardsDoc 3.2.1" } + policy => "present", + handle => "ntp_packages_$(ntp_package_name)", + classes => results("bundle", "ntp_package"); } ``` @@ -176,30 +175,29 @@ Now that the NTP service has been installed on the system, we need to make sure ```cf3 {file="ntp.cf"} bundle agent ntp { - vars: - "ntp_package_name" string => "ntp"; + vars: + "ntp_package_name" string => "ntp"; - redhat:: - "ntp_service_name" string => "ntpd"; + redhat:: + "ntp_service_name" string => "ntpd"; - debian:: - "ntp_service_name" string => "ntp"; + debian:: + "ntp_service_name" string => "ntp"; - packages: - "$(ntp_package_name)" -> { "StandardsDoc 3.2.1" } - policy => "present", - handle => "ntp_packages_$(ntp_package_name)", - classes => results("bundle", "ntp_package"); + packages: + "$(ntp_package_name)" -> { "StandardsDoc 3.2.1" } + policy => "present", + handle => "ntp_packages_$(ntp_package_name)", + classes => results("bundle", "ntp_package"); services: - "$(ntp_service_name)" -> { "StandardsDoc 3.2.2" } - service_policy => "start", - classes => results( "bundle", "ntp_service"); - - reports: - ntp_service_repaired.inform_mode:: - "NTP service repaired"; + "$(ntp_service_name)" -> { "StandardsDoc 3.2.2" } + service_policy => "start", + classes => results("bundle", "ntp_service"); + reports: + ntp_service_repaired.inform_mode:: + "NTP service repaired"; } ``` @@ -286,16 +284,16 @@ By default, the NTP service leverages configuration properties specified in /etc ```cf3 bundle agent ntp { - vars: - linux:: - "ntp_package_name" string => "ntp"; - "config_file" string => "/etc/ntp.conf"; - "driftfile" string => "/var/lib/ntp/drift"; - "servers" slist => { "time.nist.gov" }; + vars: + linux:: + "ntp_package_name" string => "ntp"; + "config_file" string => "/etc/ntp.conf"; + "driftfile" string => "/var/lib/ntp/drift"; + "servers" slist => { "time.nist.gov" }; # For brevity, and since the template is small, we define it in-line - "config_template_string" - string => "# NTP Config managed by CFEngine + "config_template_string" + string => "# NTP Config managed by CFEngine driftfile {{{driftfile}}} restrict default kod nomodify notrap nopeer noquery restrict -6 default kod nomodify notrap nopeer noquery @@ -308,45 +306,46 @@ includefile /etc/ntp/crypto/pw keys /etc/ntp/keys "; - redhat:: - "ntp_service_name" string => "ntpd"; + redhat:: + "ntp_service_name" string => "ntpd"; - debian:: - "ntp_service_name" string => "ntp"; + debian:: + "ntp_service_name" string => "ntp"; - packages: - "$(ntp_package_name)" -> { "StandardsDoc 3.2.1" } - policy => "present", - handle => "ntp_packages_$(ntp_package_name)", - classes => results("bundle", "ntp_package"); + packages: + "$(ntp_package_name)" -> { "StandardsDoc 3.2.1" } + policy => "present", + handle => "ntp_packages_$(ntp_package_name)", + classes => results("bundle", "ntp_package"); - files: + files: "$(config_file)" - create => "true", - handle => "ntp_files_conf", - perms => mog( "644", "root", "root" ), - template_method => "inline_mustache", - edit_template_string => "$(config_template_string)", - template_data => mergedata( '{ "driftfile": "$(driftfile)", "servers": servers }' ), - classes => results( "bundle", "ntp_config" ); - - services: - "$(ntp_service_name)" -> { "StandardsDoc 3.2.2" } - service_policy => "start", - classes => results( "bundle", "ntp_service_running" ); + create => "true", + handle => "ntp_files_conf", + perms => mog("644", "root", "root"), + template_method => "inline_mustache", + edit_template_string => "$(config_template_string)", + template_data => mergedata( + '{ "driftfile": "$(driftfile)", "servers": servers }' + ), + classes => results("bundle", "ntp_config"); - ntp_config_repaired:: - "$(ntp_service_name)" -> { "StandardsDoc 3.2.2" } - service_policy => "restart", - classes => results( "bundle", "ntp_service_config_change" ); + services: + "$(ntp_service_name)" -> { "StandardsDoc 3.2.2" } + service_policy => "start", + classes => results("bundle", "ntp_service_running"); - reports: - ntp_service_running_repaired.inform_mode:: - "NTP service started"; + ntp_config_repaired:: + "$(ntp_service_name)" -> { "StandardsDoc 3.2.2" } + service_policy => "restart", + classes => results("bundle", "ntp_service_config_change"); - ntp_service_config_change_repaired.inform_mode:: - "NTP service restarted after configuration change"; + reports: + ntp_service_running_repaired.inform_mode:: + "NTP service started"; + ntp_service_config_change_repaired.inform_mode:: + "NTP service restarted after configuration change"; } ``` @@ -511,32 +510,30 @@ CFEngine offers out-of-the-box support for reading and writing JSON data structu ```cf3 {file="ntp.cf"} bundle agent ntp { - vars: - linux:: - "ntp_package_name" string => "ntp"; - "config_file" string => "/etc/ntp.conf"; + vars: + linux:: + "ntp_package_name" string => "ntp"; + "config_file" string => "/etc/ntp.conf"; - # Set the default value for driftfile - "driftfile" - string => "/var/lib/ntp/drift"; + # Set the default value for driftfile + "driftfile" string => "/var/lib/ntp/drift"; - # Overwrite driftfile with value defined from Augments if it's provided - "driftfile" - string => "$(def.ntp[config][driftfile])", - if => isvariable( "def.ntp[config][driftfile]" ); + # Overwrite driftfile with value defined from Augments if it's provided + "driftfile" + string => "$(def.ntp[config][driftfile])", + if => isvariable("def.ntp[config][driftfile]"); - # Set the default value for servers - "servers" - slist => { "time.nist.gov" }; + # Set the default value for servers + "servers" slist => { "time.nist.gov" }; - # Overwrite servers with value defined from Augments if it's provided - "servers" - slist => getvalues( "def.ntp[config][servers]" ), - if => isvariable( "def.ntp[config][servers]" ); + # Overwrite servers with value defined from Augments if it's provided + "servers" + slist => getvalues("def.ntp[config][servers]"), + if => isvariable("def.ntp[config][servers]"); # For brevity, and since the template is small, we define it in-line - "config_template_string" - string => "# NTP Config managed by CFEngine + "config_template_string" + string => "# NTP Config managed by CFEngine driftfile {{{driftfile}}} restrict default kod nomodify notrap nopeer noquery restrict -6 default kod nomodify notrap nopeer noquery @@ -549,45 +546,46 @@ includefile /etc/ntp/crypto/pw keys /etc/ntp/keys "; - redhat:: - "ntp_service_name" string => "ntpd"; + redhat:: + "ntp_service_name" string => "ntpd"; - debian:: - "ntp_service_name" string => "ntp"; + debian:: + "ntp_service_name" string => "ntp"; - packages: - "$(ntp_package_name)" -> { "StandardsDoc 3.2.1" } - policy => "present", - handle => "ntp_packages_$(ntp_package_name)", - classes => results("bundle", "ntp_package"); + packages: + "$(ntp_package_name)" -> { "StandardsDoc 3.2.1" } + policy => "present", + handle => "ntp_packages_$(ntp_package_name)", + classes => results("bundle", "ntp_package"); - files: + files: "$(config_file)" - create => "true", - handle => "ntp_files_conf", - perms => mog( "644", "root", "root" ), - template_method => "inline_mustache", - edit_template_string => "$(config_template_string)", - template_data => mergedata( '{ "driftfile": "$(driftfile)", "servers": servers }' ), - classes => results( "bundle", "ntp_config" ); - - services: - "$(ntp_service_name)" -> { "StandardsDoc 3.2.2" } - service_policy => "start", - classes => results( "bundle", "ntp_service_running" ); + create => "true", + handle => "ntp_files_conf", + perms => mog("644", "root", "root"), + template_method => "inline_mustache", + edit_template_string => "$(config_template_string)", + template_data => mergedata( + '{ "driftfile": "$(driftfile)", "servers": servers }' + ), + classes => results("bundle", "ntp_config"); - ntp_config_repaired:: - "$(ntp_service_name)" -> { "StandardsDoc 3.2.2" } - service_policy => "restart", - classes => results( "bundle", "ntp_service_config_change" ); + services: + "$(ntp_service_name)" -> { "StandardsDoc 3.2.2" } + service_policy => "start", + classes => results("bundle", "ntp_service_running"); - reports: - ntp_service_running_repaired.inform_mode:: - "NTP service started"; + ntp_config_repaired:: + "$(ntp_service_name)" -> { "StandardsDoc 3.2.2" } + service_policy => "restart", + classes => results("bundle", "ntp_service_config_change"); - ntp_service_config_change_repaired.inform_mode:: - "NTP service restarted after configuration change"; + reports: + ntp_service_running_repaired.inform_mode:: + "NTP service started"; + ntp_service_config_change_repaired.inform_mode:: + "NTP service restarted after configuration change"; } ``` @@ -600,28 +598,26 @@ Let's review the changes to the vars promises as they were the only changes made ```cf3 bundle agent ntp { - vars: - linux:: - "ntp_package_name" string => "ntp"; - "config_file" string => "/etc/ntp.conf"; - - # Set the default value for driftfile - "driftfile" - string => "/var/lib/ntp/drift"; - - # Overwrite driftfile with value defined from Augments if it's provided - "driftfile" - string => "$(def.ntp[config][driftfile])", - if => isvariable( "def.ntp[config][driftfile]" ); - - # Set the default value for servers - "servers" - slist => { "time.nist.gov" }; - - # Overwrite servers with value defined from Augments if it's provided - "servers" - slist => getvalues( "def.ntp[config][servers]" ), - if => isvariable( "def.ntp[config][servers]" ); + vars: + linux:: + "ntp_package_name" string => "ntp"; + "config_file" string => "/etc/ntp.conf"; + + # Set the default value for driftfile + "driftfile" string => "/var/lib/ntp/drift"; + + # Overwrite driftfile with value defined from Augments if it's provided + "driftfile" + string => "$(def.ntp[config][driftfile])", + if => isvariable("def.ntp[config][driftfile]"); + + # Set the default value for servers + "servers" slist => { "time.nist.gov" }; + + # Overwrite servers with value defined from Augments if it's provided + "servers" + slist => getvalues("def.ntp[config][servers]"), + if => isvariable("def.ntp[config][servers]"); ``` Notice two promises were introduced, one setting `driftfile` to the value of `$(def.ntp[config][driftfile])` if it is defined and one setting servers to the list of values for `def.ntp[config][servers]` if it is defined. [Augments][Augments] allows for variables to be set in the _def_ bundle scope very early before policy is evaluated. diff --git a/content/examples/tutorials/manage-packages.markdown b/content/examples/tutorials/manage-packages.markdown index c0fb6031f..fca1916c4 100644 --- a/content/examples/tutorials/manage-packages.markdown +++ b/content/examples/tutorials/manage-packages.markdown @@ -18,17 +18,18 @@ use the packages promise type, like this: ```cf3 {file="manage_packages.cf"} body common control { - inputs => { "$(sys.libdir)/stdlib.cf" }; + inputs => { "$(sys.libdir)/stdlib.cf" }; } bundle agent manage_packages { -packages: - "openssl" - policy => "present", - version => "latest", - package_module => yum; + packages: + "openssl" + policy => "present", + version => "latest", + package_module => yum; } + bundle agent __main__ { methods: @@ -89,22 +90,22 @@ promise to our previous policy, this time using the absent policy: ```cf3 {file="manage_packages.cf"} body common control { - inputs => { "$(sys.libdir)/stdlib.cf" }; + inputs => { "$(sys.libdir)/stdlib.cf" }; } bundle agent manage_packages { -packages: - "openssl" - policy => "present", - version => "latest", - package_module => yum; - -"telnet" - policy => "absent", - package_module => yum; - + packages: + "openssl" + policy => "present", + version => "latest", + package_module => yum; + + "telnet" + policy => "absent", + package_module => yum; } + bundle agent __main__ { methods: diff --git a/content/examples/tutorials/manage-processes-and-services.markdown b/content/examples/tutorials/manage-processes-and-services.markdown index 247d3f413..9c08ac34f 100644 --- a/content/examples/tutorials/manage-processes-and-services.markdown +++ b/content/examples/tutorials/manage-processes-and-services.markdown @@ -21,14 +21,13 @@ Create a new file called `ensure_process.cf`: ```cf3 {file="ensure_process.cf"} body file control { - inputs => { "$(sys.libdir)/stdlib.cf" }; + inputs => { "$(sys.libdir)/stdlib.cf" }; } bundle agent main { processes: - "/usr/sbin/ntpd" - restart_class => "ntpd_not_running"; + "/usr/sbin/ntpd" restart_class => "ntpd_not_running"; commands: ntpd_not_running:: diff --git a/content/examples/tutorials/policy-writing/_index.markdown b/content/examples/tutorials/policy-writing/_index.markdown index 3c880939c..189d1bf5e 100644 --- a/content/examples/tutorials/policy-writing/_index.markdown +++ b/content/examples/tutorials/policy-writing/_index.markdown @@ -31,12 +31,9 @@ When individual components are empowered with clear guidance, independent decisi bundle agent hello_world { reports: - any:: - "Hello World!" comment => "This is a simple promise saying hello to the world."; - } ``` diff --git a/content/examples/tutorials/policy-writing/authoring-policy-tools-and-workflow.markdown b/content/examples/tutorials/policy-writing/authoring-policy-tools-and-workflow.markdown index 384f0fe8c..5eccfc9f3 100644 --- a/content/examples/tutorials/policy-writing/authoring-policy-tools-and-workflow.markdown +++ b/content/examples/tutorials/policy-writing/authoring-policy-tools-and-workflow.markdown @@ -111,17 +111,17 @@ git remote -v ```cf3 {file="vcs_update.cf"} bundle agent vcs_update - { - commands: - "/usr/bin/git" - args => "pull --ff-only upstream master", - contain => masterfiles_contain; - } +{ + commands: + "/usr/bin/git" + args => "pull --ff-only upstream master", + contain => masterfiles_contain; +} body contain masterfiles_contain - { - chdir => "/var/cfengine/masterfiles"; - } +{ + chdir => "/var/cfengine/masterfiles"; +} ``` 3. Save the file. diff --git a/content/examples/tutorials/policy-writing/bundles-best-practices.markdown b/content/examples/tutorials/policy-writing/bundles-best-practices.markdown index 583acc26f..81e526244 100644 --- a/content/examples/tutorials/policy-writing/bundles-best-practices.markdown +++ b/content/examples/tutorials/policy-writing/bundles-best-practices.markdown @@ -65,36 +65,25 @@ names, and then call the method passing the list of names as a parameter to redu ```cf3 {file="testbundle.cf"} bundle agent testbundle { -vars: - - "userlist" slist => { "mark", "jeang", "jonhenrik", "thomas", "eben" }; - -methods: - - "any" usebundle => subtest("$(userlist)"); + vars: + "userlist" slist => { "mark", "jeang", "jonhenrik", "thomas", "eben" }; + methods: + "any" usebundle => subtest("$(userlist)"); } ########################################### - bundle agent subtest(user) - { -commands: - - "/bin/echo Fix $(user)"; - -files: - - "/home/$(user)/." - - create => "true"; - -reports: + commands: + "/bin/echo Fix $(user)"; - linux:: + files: + "/home/$(user)/." create => "true"; - "Finished doing stuff for $(user)"; + reports: + linux:: + "Finished doing stuff for $(user)"; } ``` diff --git a/content/examples/tutorials/policy-writing/controlling-frequency.markdown b/content/examples/tutorials/policy-writing/controlling-frequency.markdown index 3bb1503ef..66d8f66cd 100644 --- a/content/examples/tutorials/policy-writing/controlling-frequency.markdown +++ b/content/examples/tutorials/policy-writing/controlling-frequency.markdown @@ -25,9 +25,9 @@ bundle agent __main__ { packages: Tuesday.Hr05_Q1:: - "sshd" - version => "latest", - comment => "Make sure sshd is at the latest version, but only Tuesday between 5:00 and 5:15am"; + "sshd" + version => "latest", + comment => "Make sure sshd is at the latest version, but only Tuesday between 5:00 and 5:15am"; } ``` @@ -46,12 +46,13 @@ bundle agent __main__ "/tmp/heartbeat.dat" create => "true", touch => "true", - classes => persistent_results( "heartbeat", 10 ); + classes => persistent_results("heartbeat", 10); } -body classes persistent_results( prefix, time ) + +body classes persistent_results(prefix, time) { - inherit_from => results( "namespace", "$(prefix)" ); - persist_time => "$(time)"; + inherit_from => results("namespace", "$(prefix)"); + persist_time => "$(time)"; } ``` @@ -84,7 +85,7 @@ setting is defined in `body agent control`. ```cf3 body agent control { - ifelapsed => "60"; # one hour + ifelapsed => "60"; # one hour } ``` @@ -96,7 +97,7 @@ promise body by setting [`ifelapsed`][Promise types#ifelapsed] in the promise bo ```cf3 body action example { - ifelapsed => "90"; # 1.5 hours + ifelapsed => "90"; # 1.5 hours } ``` diff --git a/content/examples/tutorials/policy-writing/introduction-to-policy-writing.markdown b/content/examples/tutorials/policy-writing/introduction-to-policy-writing.markdown index 7a39dda23..e9c309f92 100644 --- a/content/examples/tutorials/policy-writing/introduction-to-policy-writing.markdown +++ b/content/examples/tutorials/policy-writing/introduction-to-policy-writing.markdown @@ -51,8 +51,7 @@ The following policy ensures the existence of the `/tmp/hello-world` file: bundle agent example { files: - "/tmp/hello-world" - create => "true"; + "/tmp/hello-world" create => "true"; } ``` @@ -86,13 +85,13 @@ bundle agent example { files: linux:: - "/tmp/hello-world" - create => "true"; + "/tmp/hello-world" create => "true"; } bundle agent __main__ { - methods: "example"; + methods: + "example"; } ``` diff --git a/content/examples/tutorials/policy-writing/policy-layers-abstraction.markdown b/content/examples/tutorials/policy-writing/policy-layers-abstraction.markdown index 74d4f50cc..225ad8117 100644 --- a/content/examples/tutorials/policy-writing/policy-layers-abstraction.markdown +++ b/content/examples/tutorials/policy-writing/policy-layers-abstraction.markdown @@ -27,23 +27,28 @@ one places hosts into roles that will keep certain promises. ```cf3 bundle agent service_catalogue # menu { -methods: - any:: # selected by everyone - "everyone" usebundle => time_management, - comment => "Ensure clocks are synchronized"; - "everyone" usebundle => garbage_collection, - comment => "Clear junk and rotate logs"; - - mailservers:: # selected by hosts in class - "mail server" -> { "goal_3", "goal_1", "goal_2" } - usebundle => app_mail_postfix, - comment => "The mail delivery agent"; - "mail server" -> goal_3, - usebundle => app_mail_imap, - comment => "The mail reading service"; - "mail server" -> goal_3, - usebundle => app_mail_mailman, - comment => "The mailing list handler"; + methods: + any:: # selected by everyone + "everyone" + usebundle => time_management, + comment => "Ensure clocks are synchronized"; + + "everyone" + usebundle => garbage_collection, + comment => "Clear junk and rotate logs"; + + mailservers:: # selected by hosts in class + "mail server" -> { "goal_3", "goal_1", "goal_2" } + usebundle => app_mail_postfix, + comment => "The mail delivery agent"; + + "mail server" -> goal_3, + usebundle => app_mail_imap, + comment => "The mail reading service"; + + "mail server" -> goal_3, + usebundle => app_mail_mailman, + comment => "The mailing list handler"; } ``` @@ -55,12 +60,9 @@ standard methods, e.g. for editing files: ```cf3 body common control { -bundlesequence => { - webserver("on"), - dns("on"), - security_set("on"), - ftp("off") - }; + bundlesequence => { + webserver("on"), dns("on"), security_set("on"), ftp("off") + }; } ``` @@ -76,20 +78,17 @@ bundles and methods from standard libraries, or creating your own. ```cf3 bundle agent addpasswd { -vars: - - # want to set these values by the names of their array keys - - "pwd[mark]" string => "mark:x:1000:100:Mark B:/home/mark:/bin/bash"; - "pwd[fred]" string => "fred:x:1001:100:Right Said:/home/fred:/bin/bash"; - "pwd[jane]" string => "jane:x:1002:100:Jane Doe:/home/jane:/bin/bash"; - -files: - - "/etc/passwd" # Use standard library functions - create => "true", - comment => "Ensure listed users are present", - perms => mog("644","root","root"), - edit_line => append_users_starting("addpasswd.pwd"); + vars: + # want to set these values by the names of their array keys + "pwd[mark]" string => "mark:x:1000:100:Mark B:/home/mark:/bin/bash"; + "pwd[fred]" string => "fred:x:1001:100:Right Said:/home/fred:/bin/bash"; + "pwd[jane]" string => "jane:x:1002:100:Jane Doe:/home/jane:/bin/bash"; + + files: + "/etc/passwd" # Use standard library functions + create => "true", + comment => "Ensure listed users are present", + perms => mog("644", "root", "root"), + edit_line => append_users_starting("addpasswd.pwd"); } ``` diff --git a/content/examples/tutorials/policy-writing/policy-style.markdown b/content/examples/tutorials/policy-writing/policy-style.markdown index 61686489f..08b1d6ab5 100644 --- a/content/examples/tutorials/policy-writing/policy-style.markdown +++ b/content/examples/tutorials/policy-writing/policy-style.markdown @@ -48,8 +48,7 @@ a policy expert who is familiar with Normal ordering. bundle agent main { vars: - "sshd_config" - string => "/etc/ssh/sshd_config"; + "sshd_config" string => "/etc/ssh/sshd_config"; files: "$(sshd_config)" @@ -68,7 +67,6 @@ bundle agent main comment => "After the sshd config file has been repaired, the service must be reloaded in order for the new settings to take effect."; - } ``` @@ -99,8 +97,7 @@ bundle agent main package_module => apt_get; vars: - "sshd_config" - string => "/etc/ssh/sshd_config"; + "sshd_config" string => "/etc/ssh/sshd_config"; files: "$(sshd_config)" @@ -114,7 +111,6 @@ bundle agent main comment => "After the sshd config file has been repaired, the service must be reloaded in order for the new settings to take effect."; - } ``` @@ -139,11 +135,7 @@ bundle agent example vars: "people" slist => { - "Obi-Wan Kenobi", - "Luke Skywalker", - "Chewbacca", - "Yoda", - "Darth Vader", + "Obi-Wan Kenobi", "Luke Skywalker", "Chewbacca", "Yoda", "Darth Vader", }; "cuddly" slist => { "Chewbacca", "Yoda" }; @@ -183,8 +175,10 @@ bundle agent example vars: any:: "foo" string => "bar"; + windows:: "foo" string => "baz"; + any:: "fizz" string => "buzz"; } @@ -205,15 +199,19 @@ bundle agent example vars: # Short promises can be on one line: "a" string => "foo"; + # Small lists are also okay: "b" slist => { "1", "2", "3" }; # Don't put multiple attributes on one line: - "c" string => "foo", comment => "bar"; + "c" + string => "foo", + comment => "bar"; # Not like this either: "c" - string => "foo", comment => "bar"; + string => "foo", + comment => "bar"; # Split up instead: "c" @@ -221,19 +219,12 @@ bundle agent example comment => "bar"; # When splitting up, don't keep the attribute name on the same line: - "e" slist => { - "lorem ipsum dolor sit", - "foo bar baz", - "fizz buzz fizzbuzz", - }; + "e" + slist => { "lorem ipsum dolor sit", "foo bar baz", "fizz buzz fizzbuzz" }; - # Instead, put the attribute name on a separate line: - "e" - slist => { - "lorem ipsum dolor sit", - "foo bar baz", - "fizz buzz fizzbuzz", - }; + # Instead, put the attribute name on a separate line: + "e" + slist => { "lorem ipsum dolor sit", "foo bar baz", "fizz buzz fizzbuzz" }; } ``` @@ -262,10 +253,11 @@ bundle agent example(param1) "Luke Skywalker", "Yoda", "Darth Vader", # He used to be a Jedi, and since he - # tossed the emperor into the Death - # Star's reactor shaft we are including - # him. + # tossed the emperor into the Death + # Star's reactor shaft we are including + # him. }; + classes: # Most of the time we don't need differentiation of redhat and centos "EL5" or => { "centos_5", "redhat_5" }; @@ -321,10 +313,10 @@ bundle agent example commands: dev:: "/usr/bin/git" - args => "pull", + args => "pull", contain => in_dir("/var/srv/myrepo"), - if => "redhat", - handle => "example_commands_dev_redhat_git_pull"; + if => "redhat", + handle => "example_commands_dev_redhat_git_pull"; } ``` @@ -341,13 +333,15 @@ bundle agent example files: any:: "/var/cfengine/inputs/" - copy_from => update_policy( "/var/cfengine/masterfiles","$(policyhost)" ), - classes => policy_updated( "policy_updated" ), + copy_from => update_policy( + "/var/cfengine/masterfiles", "$(policyhost)" + ), + classes => policy_updated("policy_updated"), depth_search => recurse("inf"); "/var/cfengine/modules" - copy_from => update_policy( "/var/cfengine/modules", "$(policyhost" ), - classes => policy_updated( "modules_updated" ); + copy_from => update_policy("/var/cfengine/modules", "$(policyhost"), + classes => policy_updated("modules_updated"); classes: "EL5" or => { "centos_5", "redhat_5" }; @@ -363,13 +357,15 @@ bundle agent example files: any:: "/var/cfengine/inputs/" - copy_from => update_policy( "/var/cfengine/masterfiles","$(policyhost)" ), - classes => policy_updated( "policy_updated" ), + copy_from => update_policy( + "/var/cfengine/masterfiles", "$(policyhost)" + ), + classes => policy_updated("policy_updated"), depth_search => recurse("inf"); "/var/cfengine/modules" - copy_from => update_policy( "/var/cfengine/modules", "$(policyhost" ), - classes => policy_updated( "modules_updated" ); + copy_from => update_policy("/var/cfengine/modules", "$(policyhost"), + classes => policy_updated("modules_updated"); classes: "EL5" or => { "centos_5", "redhat_5" }; @@ -459,8 +455,7 @@ highly recommended. bundle agent main { vars: - "sshd_config" - string => "/etc/ssh/sshd_config"; + "sshd_config" string => "/etc/ssh/sshd_config"; files: "$(sshd_config)" @@ -515,11 +510,10 @@ Example policy: ```cf3 bundle agent satellite_bootstrap_main { - @if feature(this_is_not_the_feature_your_looking_for) - some_promise: "foo" unknown => "bar"; + some_promise: + "foo" unknown => "bar"; @endif - meta: (!ubuntu&!vvlan&!role_satellite):: "tags" slist => { "autorun" }; @@ -544,7 +538,7 @@ bundle agent satellite_bootstrap_main() { meta: (!ubuntu&!vvlan&!sarcrole_satellite):: - "tags" slist => {"autorun"}; + "tags" slist => { "autorun" }; methods: any:: diff --git a/content/examples/tutorials/policy-writing/policy-writing-with-cfbs.markdown b/content/examples/tutorials/policy-writing/policy-writing-with-cfbs.markdown index 4c2c78b16..d76489af9 100644 --- a/content/examples/tutorials/policy-writing/policy-writing-with-cfbs.markdown +++ b/content/examples/tutorials/policy-writing/policy-writing-with-cfbs.markdown @@ -32,8 +32,7 @@ Let's take a look at the traditional "Hello, world!" example: bundle agent hello_world { files: - "/tmp/hello" - content => "Hello, world!"; + "/tmp/hello" content => "Hello, world!"; } ``` @@ -137,8 +136,7 @@ Here is a simple example: bundle agent hello_world { vars: - "github_path" - string => "/tmp/github.com"; + "github_path" string => "/tmp/github.com"; files: "$(github_path)/." # /. means a folder @@ -171,14 +169,13 @@ To take the output of a command and put it in a variable, we will use the `execr bundle agent hello_world { vars: - "github_path" - string => "/tmp/github.com"; - - "hugo_path" - string => "$(github_path)/hugo"; + "github_path" string => "/tmp/github.com"; + "hugo_path" string => "$(github_path)/hugo"; "hugo_commit" - string => execresult('cd "$(hugo_path)" && git log -1 --format="%H"', "useshell"), + string => execresult( + 'cd "$(hugo_path)" && git log -1 --format="%H"', "useshell" + ), meta => { "inventory", "attribute_name=Hugo commit" }, if => fileexists("$(hugo_path)/.git"); diff --git a/content/examples/tutorials/promise-type-module-development.markdown b/content/examples/tutorials/promise-type-module-development.markdown index eb92b007f..27e1991d5 100644 --- a/content/examples/tutorials/promise-type-module-development.markdown +++ b/content/examples/tutorials/promise-type-module-development.markdown @@ -40,12 +40,10 @@ Then, we should edit our policy example, `my_policy.cf` to use this module: bundle agent hello_world { meta: - "tags" - slist => { "autorun" }; + "tags" slist => { "autorun" }; git_example: - "/tmp/hugo" - repository => "https://github.com/gohugoio/hugo.git"; + "/tmp/hugo" repository => "https://github.com/gohugoio/hugo.git"; } ``` diff --git a/content/examples/tutorials/render-files-with-mustache-templates.markdown b/content/examples/tutorials/render-files-with-mustache-templates.markdown index c1e849368..78f4763c9 100644 --- a/content/examples/tutorials/render-files-with-mustache-templates.markdown +++ b/content/examples/tutorials/render-files-with-mustache-templates.markdown @@ -61,11 +61,12 @@ Create a file called `/tmp/editconfig.cf` with the following content: bundle agent myapp_confs { files: - "/tmp/myapp.conf" + "/tmp/myapp.conf" create => "true", edit_template => "/tmp/myapp.conf.template", template_method => "mustache", - template_data => parsejson(' + template_data => parsejson( + ' { "port": 3508, "protocol": 2, @@ -78,8 +79,10 @@ bundle agent myapp_confs {"user": "malin", "level": "guest"} ] } - '); + ' + ); } + bundle agent __main__ { methods: diff --git a/content/examples/tutorials/report_inventory_remediate_sec_vulnerabilities.markdown b/content/examples/tutorials/report_inventory_remediate_sec_vulnerabilities.markdown index 0913152be..93c7445cb 100644 --- a/content/examples/tutorials/report_inventory_remediate_sec_vulnerabilities.markdown +++ b/content/examples/tutorials/report_inventory_remediate_sec_vulnerabilities.markdown @@ -42,7 +42,9 @@ interface in CFEngine Enterprise. bundle agent inventory_cve_2014_6271 { meta: - "description" string => "Remote exploit vulnerability in bash http://web.nvd.nist.gov/view/vuln/detail?vulnId=CVE-2014-6271"; + "description" + string => "Remote exploit vulnerability in bash http://web.nvd.nist.gov/view/vuln/detail?vulnId=CVE-2014-6271"; + "tags" slist => { "autorun" }; vars: @@ -50,7 +52,11 @@ bundle agent inventory_cve_2014_6271 "bash" string => "/bin/bash"; "echo" string => "$(paths.echo)"; - "test_result" string => execresult("$(env) x='() { :;}; $(echo) vulnerable' $(bash) -c 'echo testing CVE-2014-6271'", "useshell"); + "test_result" + string => execresult( + "$(env) x='() { :;}; $(echo) vulnerable' $(bash) -c 'echo testing CVE-2014-6271'", + "useshell" + ); cve_2014_6271:: "vulnerable" @@ -59,7 +65,7 @@ bundle agent inventory_cve_2014_6271 classes: "cve_2014_6271" - expression => regcmp( "vulnerable.*", "$(test_result)" ), + expression => regcmp("vulnerable.*", "$(test_result)"), scope => "namespace", persistence => "10", comment => "We persist the class for 2 agent runs so that bundles @@ -167,8 +173,7 @@ bundle agent remediate_cve_2014_6271 methods: allow_update.cve_2014_6271:: - "Upgrade_Bash" - usebundle => package_latest("bash"); + "Upgrade_Bash" usebundle => package_latest("bash"); } ``` diff --git a/content/examples/tutorials/reporting/command-line-reports.markdown b/content/examples/tutorials/reporting/command-line-reports.markdown index afed4ad17..1896363c4 100644 --- a/content/examples/tutorials/reporting/command-line-reports.markdown +++ b/content/examples/tutorials/reporting/command-line-reports.markdown @@ -58,19 +58,14 @@ example of this is shown below. ```cf3 body common control { -bundlesequence => { "test" }; + bundlesequence => { "test" }; } -# - bundle agent test { -reports: - - cfengine_3:: - - "$(sys.date),This is a report" - report_to_file => "/tmp/test_log"; + reports: + cfengine_3:: + "$(sys.date),This is a report" report_to_file => "/tmp/test_log"; } ``` @@ -81,50 +76,36 @@ existing software: ```cf3 body common control { -bundlesequence => { "test" }; + bundlesequence => { "test" }; } -# - bundle agent test { -vars: - - "software" slist => { "gpg", "zip", "rsync" }; + vars: + "software" slist => { "gpg", "zip", "rsync" }; -classes: - - "no_report" expression => fileexists("/tmp/report.html"); - "have_$(software)" expression => fileexists("/usr/bin/$(software)"); - -reports: - - no_report:: + classes: + "no_report" expression => fileexists("/tmp/report.html"); + "have_$(software)" expression => fileexists("/usr/bin/$(software)"); + reports: + no_report:: " Name of this host is: $(sys.host)
Type of this host is: $(sys.os)
" - - report_to_file => "/tmp/report.html"; - - # + report_to_file => "/tmp/report.html"; " Host has software $(software)
" - - if => "have_$(software)", + if => "have_$(software)", report_to_file => "/tmp/report.html"; - # - " - " - report_to_file => "/tmp/report.html"; - + " report_to_file => "/tmp/report.html"; } ``` @@ -155,24 +136,17 @@ For example, the agent `cf-agent` interfaces with the local light-weight monitor ```cf3 body common control - { -bundlesequence => { "report" }; + bundlesequence => { "report" }; } ########################################################### - bundle agent report - { -reports: - - linux:: - - "/etc/passwd except $(const.n)" - - showstate => { "otherprocs", "rootprocs" }; - + reports: + linux:: + "/etc/passwd except $(const.n)" + showstate => { "otherprocs", "rootprocs" }; } ``` @@ -221,33 +195,23 @@ Finally, you can quote lines from files in your data for convenience: ```cf3 body common control - { -bundlesequence => { "report" }; + bundlesequence => { "report" }; } ########################################################### - bundle agent report - { -reports: - - linux:: - - "/etc/passwd except $(const.n)" - - printfile => pr("/etc/passwd","5"); - + reports: + linux:: + "/etc/passwd except $(const.n)" printfile => pr("/etc/passwd", "5"); } ###################################################################### - -body printfile pr(file,lines) - +body printfile pr(file, lines) { -file_to_print => "$(file)"; -number_of_lines => "$(lines)"; + file_to_print => "$(file)"; + number_of_lines => "$(lines)"; } ``` @@ -273,12 +237,10 @@ handle. `vars` and `classes` type promises can be excluded using its handle bundle agent main { files: - linux:: - - "/var/log/noisy.log" - handle => "noreport_noisy_log_rotation", - rename => rotate(5); + "/var/log/noisy.log" + handle => "noreport_noisy_log_rotation", + rename => rotate(5); } body report_data_select default_data_select_policy_hub @@ -288,17 +250,17 @@ body report_data_select default_data_select_policy_hub # reporting value) should be prefixed with an underscore. By default the policy # framework explicitly excludes these variables and classes from collection. { - # Collect all classes or vars tagged with `inventory` or `report` - metatags_include => { "inventory", "report" }; + # Collect all classes or vars tagged with `inventory` or `report` + metatags_include => { "inventory", "report" }; - # Exclude any classes or vars tagged with `noreport` - metatags_exclude => { "noreport" }; + # Exclude any classes or vars tagged with `noreport` + metatags_exclude => { "noreport" }; - # Exclude any promise with handle matching `noreport_.*` from report collection. - promise_handle_exclude => { "noreport_.*" }; + # Exclude any promise with handle matching `noreport_.*` from report collection. + promise_handle_exclude => { "noreport_.*" }; - # Include all metrics from cf-monitord - monitoring_include => { ".*" }; + # Include all metrics from cf-monitord + monitoring_include => { ".*" }; } ``` @@ -311,20 +273,15 @@ in the Unix/C standard manner: ```cf3 bundle agent test { -commands: - - "/tmp/myjob", - - action => logme("executor"); - + commands: + "/tmp/myjob" action => logme("executor"); } ############################################ - body action logme(x) { -log_repaired => "stdout"; -log_string => " -> Started the $(x) (success)"; + log_repaired => "stdout"; + log_string => " -> Started the $(x) (success)"; } ``` @@ -334,32 +291,26 @@ In the following example, a file creation promise logs different outcomes ```cf3 body common control { -bundlesequence => { "test" }; + bundlesequence => { "test" }; } bundle agent test { -vars: - - "software" slist => { "/root/xyz", "/tmp/xyz" }; - -files: - - "$(software)" - - create => "true", - action => logme("$(software)"); + vars: + "software" slist => { "/root/xyz", "/tmp/xyz" }; + files: + "$(software)" + create => "true", + action => logme("$(software)"); } -# - body action logme(x) { -log_kept => "/tmp/private_keptlog.log"; -log_failed => "/tmp/private_faillog.log"; -log_repaired => "/tmp/private_replog.log"; -log_string => "$(sys.date) $(x) promise status"; + log_kept => "/tmp/private_keptlog.log"; + log_failed => "/tmp/private_faillog.log"; + log_repaired => "/tmp/private_replog.log"; + log_string => "$(sys.date) $(x) promise status"; } ``` @@ -384,22 +335,20 @@ system logger on a per-promise basis: ```cf3 body common control { -bundlesequence => { "one" }; + bundlesequence => { "one" }; } bundle agent one { -files: - - "/tmp/xyz" - - create => "true", - action => log; + files: + "/tmp/xyz" + create => "true", + action => log; } body action log { -log_level => "inform"; + log_level => "inform"; } ``` @@ -414,31 +363,27 @@ To make a change tripwire, use a files promise, as shown below: ```cf3 body common control { -bundlesequence => { "testbundle" }; + bundlesequence => { "testbundle" }; } -# bundle agent testbundle - { -files: - - "/home/mark/tmp" -> "me" - changes => scan_files, - depth_search => recurse("inf"); + files: + "/home/mark/tmp" -> "me" + changes => scan_files, + depth_search => recurse("inf"); } # library code ... - body changes scan_files { -report_changes => "all"; -update_hashes => "true"; + report_changes => "all"; + update_hashes => "true"; } body depth_search recurse(d) { -depth => "$(d)"; + depth => "$(d)"; } ``` diff --git a/content/examples/tutorials/tags.markdown b/content/examples/tutorials/tags.markdown index 2b3a8d7fe..4ca6a09e0 100644 --- a/content/examples/tutorials/tags.markdown +++ b/content/examples/tutorials/tags.markdown @@ -48,7 +48,7 @@ An example is easiest: bundle agent run_deprecated { meta: - "tags" slist => { "deprecated" }; + "tags" slist => { "deprecated" }; } ``` diff --git a/content/overview/client-server-communication.markdown b/content/overview/client-server-communication.markdown index 50bcdde58..31e724a3d 100644 --- a/content/overview/client-server-communication.markdown +++ b/content/overview/client-server-communication.markdown @@ -112,8 +112,8 @@ bundle server my_access_rules() { access: "/path/file" - admit => { "127.0.0.1", "127.0.0.2", "127.0.0.3" }, - deny => { "192.168.0.0/8" }; + admit => { "127.0.0.1", "127.0.0.2", "127.0.0.3" }, + deny => { "192.168.0.0/8" }; } ``` diff --git a/content/reference/components/_index.markdown b/content/reference/components/_index.markdown index 64f57cebe..8fc155f5a 100644 --- a/content/reference/components/_index.markdown +++ b/content/reference/components/_index.markdown @@ -27,24 +27,13 @@ affect the behavior of all the components. ```cf3 body common control - { -inputs => { - "update.cf", - "library.cf" - }; - -bundlesequence => { - update("policy_host.domain.tld"), - "main", - "cfengine2" - }; - -goal_categories => { "goals", "targets", "milestones" }; -goal_patterns => { "goal_.*", "target.*" }; - -output_prefix => "cfengine>"; -version => "1.2.3"; + inputs => { "update.cf", "library.cf" }; + bundlesequence => { update("policy_host.domain.tld"), "main", "cfengine2" }; + goal_categories => { "goals", "targets", "milestones" }; + goal_patterns => { "goal_.*", "target.*" }; + output_prefix => "cfengine>"; + version => "1.2.3"; } ``` @@ -70,13 +59,8 @@ A `bundlesequence` may also be specified using the `-b` or ```cf3 body common control - { -bundlesequence => { - update("policy_host.domain.tld"), - "main", - "cfengine2" - }; + bundlesequence => { update("policy_host.domain.tld"), "main", "cfengine2" }; } ``` @@ -108,21 +92,17 @@ use global variable lists to do this: ```cf3 body common control { -webservers:: - - bundlesequence => { @(g.bs), "web" }; - -others:: - - bundlesequence => { @(g.bs), "otherstuff" }; + webservers:: + bundlesequence => { @(g.bs), "web" }; + others:: + bundlesequence => { @(g.bs), "otherstuff" }; } bundle common g { -vars: - - "bs" slist => { "main", "basic_stuff" }; + vars: + "bs" slist => { "main", "basic_stuff" }; } ``` @@ -156,7 +136,6 @@ facilities. ```cf3 body common control - { bwlimit => "10M"; } @@ -216,7 +195,7 @@ discovery and name-lookup. ```cf3 body common control { -domain => "example.org"; + domain => "example.org"; } ``` @@ -269,7 +248,7 @@ business goals in promises. ```cf3 body common control { -goal_patterns => { "goal_.*", "target.*" }; + goal_patterns => { "goal_.*", "target.*" }; } ``` @@ -350,10 +329,7 @@ as the file which references them (this is usually ```cf3 body common control { -inputs => { - "update.cf", - "library.cf" - }; + inputs => { "update.cf", "library.cf" }; } ``` @@ -395,7 +371,7 @@ after which last-seen entries are purged. It is an **enterprise-only** feature. ```cf3 body common control { -lastseenexpireafter => "72"; + lastseenexpireafter => "72"; } ``` @@ -416,7 +392,7 @@ lastseenexpireafter => "72"; ```cf3 body common control { -output_prefix => "my_cf3"; + output_prefix => "my_cf3"; } ``` @@ -442,7 +418,7 @@ Enterprise inventory reporting. ```cf3 body common control { - package_inventory => { "apt_get" }; + package_inventory => { "apt_get" }; } ``` @@ -462,7 +438,7 @@ if none is specified in the promise. ```cf3 body common control { - package_module => "apt_get"; + package_module => "apt_get"; } ``` @@ -502,11 +478,9 @@ promises. ```cf3 body common control - { -common:: - -require_comments => "true"; + common:: + require_comments => "true"; } ``` @@ -534,7 +508,7 @@ Each string is expected to be a class. ```cf3 body common control { -site_classes => { "datacenters","datacentres" }; # locations is by default + site_classes => { "datacenters", "datacentres" }; # locations is by default } ``` @@ -559,8 +533,8 @@ CFEngine's components may promise to send data. ```cf3 body common control { -syslog_host => "syslog.example.org"; -syslog_port => "514"; + syslog_host => "syslog.example.org"; + syslog_port => "514"; } ``` @@ -583,8 +557,8 @@ components may promise to send data. ```cf3 body common control { -syslog_host => "syslog.example.org"; -syslog_port => "514"; + syslog_host => "syslog.example.org"; + syslog_port => "514"; } ``` @@ -608,6 +582,7 @@ body common control @if minimum_version(3.18.1) windows:: system_log_level => "critical"; + cfengine:: @endif } @@ -632,8 +607,8 @@ For a list of possible ciphers, see man page for "openssl ciphers". ```cf3 body common control { - # Use one of these ciphers when making outbound connections - tls_ciphers => "AES128-SHA"; + # Use one of these ciphers when making outbound connections + tls_ciphers => "AES128-SHA"; } ``` @@ -650,8 +625,8 @@ body common control ```cf3 body common control { - # Allow only TLSv1.1 or higher for outgoing connections - tls_min_version => "1.1"; + # Allow only TLSv1.1 or higher for outgoing connections + tls_min_version => "1.1"; } ``` @@ -679,7 +654,7 @@ restriction might be lifted later. ```cf3 body common control { -version => "1.2.3"; + version => "1.2.3"; } ``` diff --git a/content/reference/components/cf-agent.markdown b/content/reference/components/cf-agent.markdown index 8472da7de..0350880ef 100644 --- a/content/reference/components/cf-agent.markdown +++ b/content/reference/components/cf-agent.markdown @@ -42,7 +42,7 @@ bundle agent __main__ { vars: "msg" - string => execresult( "/bin/echo Hello world!", "useshell" ), + string => execresult("/bin/echo Hello world!", "useshell"), meta => { "simulate_safe" }; } ``` @@ -152,9 +152,11 @@ body agent control alpha_cfengine_com:: domain => "alpha.cfengine.com"; mailto => "admins@alpha.cfengine.com"; + beta_domain_com:: domain => "beta.cfengine.com"; mailto => "admins@beta.cfengine.com"; + any:: mailfrom => "root"; } @@ -181,36 +183,33 @@ method bundle. ```cf3 body common control { - bundlesequence => { "testbundle" }; + bundlesequence => { "testbundle" }; version => "1.2.3"; } ################################# - body agent control { abortbundleclasses => { "invalid.*" }; } ################################# - bundle agent testbundle { vars: "userlist" slist => { "xyz", "mark", "jeang", "jonhenrik", "thomas", "eben" }; + methods: - "any" - usebundle => subtest("$(userlist)"); + "any" usebundle => subtest("$(userlist)"); } ################################# - bundle agent subtest(user) { classes: - "invalid" - not => regcmp("[a-z]{4}","$(user)"); + "invalid" not => regcmp("[a-z]{4}", "$(user)"); + reports: !invalid:: "User name $(user) is valid at exactly 4 letters"; @@ -725,7 +724,7 @@ body common control body agent control { - environment => { "A=123", "B=456", "PGK_PATH=/tmp"}; + environment => { "A=123", "B=456", "PGK_PATH=/tmp" }; } bundle agent one @@ -795,7 +794,7 @@ kill and restart its attempt to keep a promise. ```cf3 body action example { - ifelapsed => "120"; # 2 hours + ifelapsed => "120"; # 2 hours expireafter => "240"; # 4 hours } ``` @@ -924,7 +923,7 @@ another which is not tied to a specific time. ```cf3 body agent control { - ifelapsed => "180"; # 3 hours + ifelapsed => "180"; # 3 hours } ``` @@ -1013,7 +1012,6 @@ number of outgoing connections to `cf-serverd`. ```cf3 # client side - body agent control { maxconnections => "1000"; @@ -1095,7 +1093,8 @@ The mode string may be symbolic or numerical, like `chmod`. **Example:** ```cf3 -body agent control { +body agent control +{ # Override the default directory create mode to 0755 (it defaults to 0700 if # not specified) default_directory_create_mode => "a+rx"; # Can also use octets 0755 @@ -1135,6 +1134,7 @@ at the start of every scheduled bundle. body agent control { refresh_processes => { "mybundle" }; + # refresh_processes => { "none" }; } ``` diff --git a/content/reference/components/cf-execd.markdown b/content/reference/components/cf-execd.markdown index 1c05f6746..6d68e81af 100644 --- a/content/reference/components/cf-execd.markdown +++ b/content/reference/components/cf-execd.markdown @@ -39,11 +39,11 @@ times and output capture to `WORKDIR/outputs` and relay via email. ```cf3 body executor control { - splaytime => "5"; - mailto => "cfengine@example.org"; - mailfrom => "cfengine@$(host).example.org"; - smtpserver => "localhost"; - schedule => { "Min00", "Min30" } + splaytime => "5"; + mailto => "cfengine@example.org"; + mailfrom => "cfengine@$(host).example.org"; + smtpserver => "localhost"; + schedule => { "Min00", "Min30" } } ``` @@ -73,7 +73,7 @@ this threshold. This will reset the timer. ```cf3 body executor control { -agent_expireafter => "120"; + agent_expireafter => "120"; } ``` @@ -115,7 +115,7 @@ See the syslog manual pages. ```cf3 body executor control { -executorfacility => "LOG_USER"; + executorfacility => "LOG_USER"; } ``` @@ -165,8 +165,8 @@ different from the previous run for an email to be generated. ```cf3 body executor control { - # Ignore agent execution emails about permission errors. - mailfilter_exclude => { ".*Permission denied.*" }; + # Ignore agent execution emails about permission errors. + mailfilter_exclude => { ".*Permission denied.*" }; } ``` @@ -197,8 +197,8 @@ different from the previous run for an email to be generated. ```cf3 body executor control { - # Only include reports in agent execution emails. - mailfilter_include => { "R:.*" }; + # Only include reports in agent execution emails. + mailfilter_include => { "R:.*" }; } ``` @@ -219,7 +219,7 @@ body executor control ```cf3 body executor control { - mailfrom => "mrcfengine@example.org"; + mailfrom => "mrcfengine@example.org"; } ``` @@ -247,7 +247,7 @@ viewed on demand. A reference to the appropriate file is given. ```cf3 body executor control { -mailmaxlines => "100"; + mailmaxlines => "100"; } ``` @@ -271,7 +271,7 @@ architecture. ```cf3 body executor control { - mailsubject => "CFEngine report ($(sys.fqhost))"; + mailsubject => "CFEngine report ($(sys.fqhost))"; } ``` @@ -294,7 +294,7 @@ The address to whom email is sent if an smtp host is configured. ```cf3 body executor control { - mailto => "cfengine_alias@example.org"; + mailto => "cfengine_alias@example.org"; } ``` @@ -332,7 +332,9 @@ function may be affected by changing the `schedule`. ```cf3 body executor control { -schedule => { "Min00", "(Evening|Night).Min15", "Min30", "(Evening|Night).Min45" }; + schedule => { + "Min00", "(Evening|Night).Min15", "Min30", "(Evening|Night).Min45" + }; } ``` @@ -358,7 +360,7 @@ localhost and point this to localhost. ```cf3 body executor control { - smtpserver => "smtp.example.org"; + smtpserver => "smtp.example.org"; } ``` @@ -400,7 +402,7 @@ The CFEngine default policy sets `splaytime` to 1. ```cf3 body executor control { - splaytime => "2"; + splaytime => "2"; } ``` @@ -427,7 +429,7 @@ body executor control ```cf3 body executor control { - runagent_socket_allow_users => { "yoda", "obi-wan" }; + runagent_socket_allow_users => { "yoda", "obi-wan" }; } ``` diff --git a/content/reference/components/cf-hub.markdown b/content/reference/components/cf-hub.markdown index c4b6c8da3..28e2ef022 100644 --- a/content/reference/components/cf-hub.markdown +++ b/content/reference/components/cf-hub.markdown @@ -75,12 +75,9 @@ currently not supported. ```cf3 body hub control { - # Collect reports every at the top and half of the hour. Additionally collect # reports during the evening or night at Minute 45. - hub_schedule => { "Min00", "Min30", "(Evening|Night).Min45" }; - } ``` @@ -108,7 +105,6 @@ body hub control # Configure network connection timeout when connecting to hosts # for querying reporting data. query_timeout => "10"; - } ``` @@ -146,16 +142,16 @@ If both are not specified (or `0`), the default is used. ```cf3 body hub control { -port => "5308"; + port => "5308"; } body server control { -specialhost:: - port => "5308"; + specialhost:: + port => "5308"; -!specialhost:: - port => "5308"; + !specialhost:: + port => "5308"; } ``` @@ -186,7 +182,7 @@ and minimize data transfer. The default value is 6 hours. ```cf3 body hub control { -client_history_timeout => 6; + client_history_timeout => 6; } ``` @@ -202,7 +198,7 @@ client_history_timeout => 6; ```cf3 body hub control { -export_zenoss => "/var/www/reports/summary.z"; + export_zenoss => "/var/www/reports/summary.z"; } ``` diff --git a/content/reference/components/cf-monitord.markdown b/content/reference/components/cf-monitord.markdown index fc552b3b8..92a3f4166 100644 --- a/content/reference/components/cf-monitord.markdown +++ b/content/reference/components/cf-monitord.markdown @@ -167,11 +167,10 @@ to developing the integrated monitoring capabilities of CFEngine. ```cf3 body monitor control { - #version => "1.2.3.4"; - - forgetrate => "0.7"; - tcpdump => "false"; - tcpdumpcommand => "/usr/sbin/tcpdump -i eth1 -n -t -v"; + #version => "1.2.3.4"; + forgetrate => "0.7"; + tcpdump => "false"; + tcpdumpcommand => "/usr/sbin/tcpdump -i eth1 -n -t -v"; } ``` @@ -196,7 +195,7 @@ rate) how quickly CFEngine forgets its previous history. ```cf3 body monitor control { -forgetrate => "0.7"; + forgetrate => "0.7"; } ``` @@ -222,7 +221,7 @@ fluctuations about the mean. ```cf3 body monitor control { -histograms => "true"; + histograms => "true"; } ``` @@ -293,7 +292,7 @@ stream and monitor generic package categories for anomalies. ```cf3 body monitor control { -tcpdumpcommand => "/usr/sbin/tcpdump -i eth1"; + tcpdumpcommand => "/usr/sbin/tcpdump -i eth1"; } ``` diff --git a/content/reference/components/cf-runagent.markdown b/content/reference/components/cf-runagent.markdown index fc2721828..f8d079b53 100644 --- a/content/reference/components/cf-runagent.markdown +++ b/content/reference/components/cf-runagent.markdown @@ -42,10 +42,10 @@ introducing such dependencies makes configuration brittle. ```cf3 body runagent control { - # default port is 5308 - hosts => { "127.0.0.1:5308", "eternity.iu.hio.no:80", "slogans.iu.hio.no" }; + # default port is 5308 + hosts => { "127.0.0.1:5308", "eternity.iu.hio.no:80", "slogans.iu.hio.no" }; - #output_to_file => "true"; + #output_to_file => "true"; } ``` @@ -99,10 +99,10 @@ body hub control body server control { specialhost:: - port => "5308"; + port => "5308"; !specialhost:: - port => "5308"; + port => "5308"; } ``` @@ -192,7 +192,7 @@ public/private keys for the client and server hosts. ```cf3 body copy_from example { - servers => { "remote-host.example.org" }; + servers => { "remote-host.example.org" }; encrypt => "true"; } ``` diff --git a/content/reference/components/cf-serverd.markdown b/content/reference/components/cf-serverd.markdown index a5572e0ae..ba36e652e 100644 --- a/content/reference/components/cf-serverd.markdown +++ b/content/reference/components/cf-serverd.markdown @@ -45,11 +45,11 @@ files must be granted in addition. ```cf3 body server control { - allowconnects => { "127.0.0.1" , "::1" }; - allowallconnects => { "127.0.0.1" , "::1" }; + allowconnects => { "127.0.0.1", "::1" }; + allowallconnects => { "127.0.0.1", "::1" }; - # Uncomment me under controlled circumstances - #trustkeysfrom => { "127.0.0.1" , "::1" }; + # Uncomment me under controlled circumstances + #trustkeysfrom => { "127.0.0.1" , "::1" }; } ``` @@ -162,8 +162,8 @@ For a list of possible ciphers, see man page for "openssl ciphers". ```cf3 body server control { - # Only this non-default cipher is to be accepted - allowciphers => "RC4-MD5"; + # Only this non-default cipher is to be accepted + allowciphers => "RC4-MD5"; } ``` @@ -194,8 +194,8 @@ this does not do anything as the classic protocol does not support TLS ciphers. ```cf3 body server control { - # Allow only TLSv1.1 or higher - allowtlsversion => "1.1"; + # Allow only TLSv1.1 or higher + allowtlsversion => "1.1"; } ``` @@ -330,7 +330,7 @@ shell command at your own risk. ```cf3 body server control { -cfruncommand => "/var/cfengine/bin/cf-agent"; + cfruncommand => "/var/cfengine/bin/cf-agent"; } ``` @@ -401,40 +401,34 @@ The full configuration to enable client initiated reporting would look something ######################################################### # Server config ######################################################### - body server control { - allowconnects => { "10.10.10.0/24" , "::1" }; - allowallconnects => { "10.10.10.0/24" , "::1" }; - trustkeysfrom => { "10.10.10.0/24" , "::1" }; - + allowconnects => { "10.10.10.0/24", "::1" }; + allowallconnects => { "10.10.10.0/24", "::1" }; + trustkeysfrom => { "10.10.10.0/24", "::1" }; call_collect_interval => "5"; } ######################################################### - bundle server my_access_rules() { access: - policy_server:: - - "collect_calls" - resource_type => "query", - admit => { "10.10.10.10" }, - comment => "The policy server must admit queries for collect_calls (client initated reporting)."; + "collect_calls" + resource_type => "query", + admit => { "10.10.10.10" }, + comment => "The policy server must admit queries for collect_calls (client initated reporting)."; satellite_hosts:: - "delta" - comment => "Grant access to cfengine hub to collect report deltas", - resource_type => "query", - admit => { "policy_hub" }; + comment => "Grant access to cfengine hub to collect report deltas", + resource_type => "query", + admit => { "policy_hub" }; "full" - comment => "Grant access to cfengine hub to collect full report dump", + comment => "Grant access to cfengine hub to collect full report dump", resource_type => "query", - admit => { "policy_hub" }; + admit => { "policy_hub" }; } ``` @@ -485,7 +479,7 @@ attempts based on clock corruption. ```cf3 body server control { -denybadclocks => "true"; + denybadclocks => "true"; } ``` @@ -514,7 +508,7 @@ See also the warning about regular expressions in ```cf3 body server control { -denyconnects => { "badhost\.domain\.evil", "host3\.domain\.com" }; + denyconnects => { "badhost\.domain\.evil", "host3\.domain\.com" }; } ``` @@ -541,7 +535,7 @@ to syslog. These files are deemed to be particularly sensitive. ```cf3 body server control { -logencryptedtransfers => "true"; + logencryptedtransfers => "true"; } ``` @@ -563,17 +557,15 @@ number of hosts bootstrapped to this hub**. ```cf3 # client side - body agent control { -maxconnections => "1000"; + maxconnections => "1000"; } # server side - body server control { -maxconnections => "1000"; + maxconnections => "1000"; } ``` @@ -596,16 +588,16 @@ maxconnections => "1000"; ```cf3 body hub control { -port => "5308"; + port => "5308"; } body server control { -specialhost:: - port => "5308"; + specialhost:: + port => "5308"; -!specialhost:: - port => "5308"; + !specialhost:: + port => "5308"; } ``` @@ -650,7 +642,7 @@ See syslog notes. ```cf3 body server control { -serverfacility => "LOG_USER"; + serverfacility => "LOG_USER"; } ``` @@ -668,7 +660,7 @@ for backward compatibility. ```cf3 body server control { -skipverify => { "special_host.*", "192.168\..*" }; + skipverify => { "special_host.*", "192.168\..*" }; } ``` @@ -702,7 +694,7 @@ See also the warning about regular expressions in ```cf3 body server control { -trustkeysfrom => { "10.0.1.1", "192.168.0.0/16"}; + trustkeysfrom => { "10.0.1.1", "192.168.0.0/16" }; } ``` @@ -750,7 +742,6 @@ not be affected. Changing this setting requires a restart of ```cf3 body server control { - listening_host_context:: listen => "true"; diff --git a/content/reference/components/file_control_promises.markdown b/content/reference/components/file_control_promises.markdown index 3a2ba0c41..42f5690f0 100644 --- a/content/reference/components/file_control_promises.markdown +++ b/content/reference/components/file_control_promises.markdown @@ -9,7 +9,7 @@ aliases: ```cf3 body file control { -namespace => "name1"; + namespace => "name1"; } bundle agent private @@ -56,15 +56,20 @@ body file control bundle agent reports_top_down { - reports: "Hello world:"; + reports: + "Hello world:"; - commands: "/bin/echo hi"; + commands: + "/bin/echo hi"; - reports: "bye:"; + reports: + "bye:"; } + bundle agent __main__ { - methods: "reports_top_down"; + methods: + "reports_top_down"; } body agent control @@ -152,7 +157,7 @@ to switch to in order to protect the current file from duplicate definitions. ```cf3 body file control { -namespace => "name1"; + namespace => "name1"; } ``` diff --git a/content/reference/functions/_index.markdown b/content/reference/functions/_index.markdown index 05059fccd..ef47ea273 100644 --- a/content/reference/functions/_index.markdown +++ b/content/reference/functions/_index.markdown @@ -28,9 +28,11 @@ define classes, and use classes instead of boolean values: bundle agent main { vars: - "five" int => "5"; + "five" int => "5"; + classes: - "is_var" if => isvariable("five"); + "is_var" if => isvariable("five"); + reports: is_var:: "Success!"; @@ -44,10 +46,11 @@ If you want to store or print the class expression, you can use `concat()`: bundle agent main { vars: - "five" int => "5"; - "expression" string => concat(isvariable("five")); + "five" int => "5"; + "expression" string => concat(isvariable("five")); + classes: - "is_var" if => "$(expression)"; # Will be expanded and evaluated + "is_var" if => "$(expression)"; # Will be expanded and evaluated reports: is_var:: "Success: expression expanded to '$(expression)' and evaluated to true!"; @@ -73,15 +76,18 @@ and `unless`, can take a function call which returns string or boolean as well. bundle agent main { vars: - "five" int => "5"; - "is_var_class_expression" string => concat(isvariable("$(five)")); + "five" int => "5"; + "is_var_class_expression" string => concat(isvariable("$(five)")); + classes: - "five_less_than_seven" expression => islessthan("$(five)", 7); - "five_is_variable" if => "$(is_var_class_expression)"; + "five_less_than_seven" expression => islessthan("$(five)", 7); + "five_is_variable" if => "$(is_var_class_expression)"; + reports: any:: "five: $(five)"; "is_var_class_expression: $(is_var_class_expression)"; + five_less_than_seven:: "$(five) is smaller than 7"; } diff --git a/content/reference/functions/accumulated.markdown b/content/reference/functions/accumulated.markdown index 45f85a63a..1dfa2abf8 100644 --- a/content/reference/functions/accumulated.markdown +++ b/content/reference/functions/accumulated.markdown @@ -49,22 +49,20 @@ Seconds of runtime bundle agent testbundle { processes: - - ".*" - - process_count => anyprocs, - process_select => proc_finder; + ".*" + process_count => anyprocs, + process_select => proc_finder; reports: - - any_procs:: - - "Found processes in range"; + any_procs:: + "Found processes in range"; } body process_select proc_finder { - ttime_range => irange(accumulated(0,0,0,0,2,0),accumulated(0,0,0,0,20,0)); + ttime_range => irange( + accumulated(0, 0, 0, 0, 2, 0), accumulated(0, 0, 0, 0, 20, 0) + ); process_result => "ttime"; } diff --git a/content/reference/functions/changedbefore.markdown b/content/reference/functions/changedbefore.markdown index 5c7b5524c..08a402b1d 100644 --- a/content/reference/functions/changedbefore.markdown +++ b/content/reference/functions/changedbefore.markdown @@ -22,19 +22,16 @@ Comparisons like this are normally used for updating files (like the ```cf3 body common control { - bundlesequence => { "example" }; + bundlesequence => { "example" }; } bundle agent example { classes: - - "do_it" and => { changedbefore("/tmp/earlier","/tmp/later"), "linux" }; + "do_it" and => { changedbefore("/tmp/earlier", "/tmp/later"), "linux" }; reports: - do_it:: - "The derived file needs updating"; } ``` diff --git a/content/reference/functions/datastate.markdown b/content/reference/functions/datastate.markdown index 1437e1ff7..b9c9dc5be 100644 --- a/content/reference/functions/datastate.markdown +++ b/content/reference/functions/datastate.markdown @@ -47,7 +47,7 @@ bundle agent main vars: "_state" data => datastate(), - unless => isvariable( $(this.promiser) ); + unless => isvariable($(this.promiser)); } ``` diff --git a/content/reference/functions/getacls.markdown b/content/reference/functions/getacls.markdown index 324bdd0e6..3341e0867 100644 --- a/content/reference/functions/getacls.markdown +++ b/content/reference/functions/getacls.markdown @@ -35,10 +35,8 @@ list. bundle agent __main__ { vars: - "default_acls" - slist => getacls("/tmp/foo/", "default"); - "access_acls" - slist => getacls("/tmp/bar", "access"); + "default_acls" slist => getacls("/tmp/foo/", "default"); + "access_acls" slist => getacls("/tmp/bar", "access"); } ``` diff --git a/content/reference/functions/getbundlemetatags.markdown b/content/reference/functions/getbundlemetatags.markdown index 3bca74563..7944e6eea 100644 --- a/content/reference/functions/getbundlemetatags.markdown +++ b/content/reference/functions/getbundlemetatags.markdown @@ -19,11 +19,7 @@ bundle agent example { meta: "tags" - slist => { - "mykey=myvalue1", - "mykey=myvalue2", - "yourkey=yourvalue1", - }; + slist => { "mykey=myvalue1", "mykey=myvalue2", "yourkey=yourvalue1" }; } ``` diff --git a/content/reference/functions/getgroups.markdown b/content/reference/functions/getgroups.markdown index b87a19e08..6d9dd61f3 100644 --- a/content/reference/functions/getgroups.markdown +++ b/content/reference/functions/getgroups.markdown @@ -17,15 +17,11 @@ aliases: bundle agent main { vars: - "groups" - slist => getgroups("root", ""); - - "first_three_groups" - slist => sublist("@(groups)", head, 3); + "groups" slist => getgroups("root", ""); + "first_three_groups" slist => sublist("@(groups)", head, 3); reports: "$(first_three_groups)"; - } ``` diff --git a/content/reference/functions/hashmatch.markdown b/content/reference/functions/hashmatch.markdown index ef0a4df27..8ec3c5ed4 100644 --- a/content/reference/functions/hashmatch.markdown +++ b/content/reference/functions/hashmatch.markdown @@ -21,15 +21,14 @@ version of a binary file (e.g. software patch). ```cf3 bundle agent example { -classes: - - "matches" expression => hashmatch("/etc/passwd","md5","c5068b7c2b1707f8939b283a2758a691"); - -reports: - - matches:: - - "File has correct version"; - + classes: + "matches" + expression => hashmatch( + "/etc/passwd", "md5", "c5068b7c2b1707f8939b283a2758a691" + ); + + reports: + matches:: + "File has correct version"; } ``` diff --git a/content/reference/functions/hostsseen.markdown b/content/reference/functions/hostsseen.markdown index 10db8be2f..577ebd4c3 100644 --- a/content/reference/functions/hostsseen.markdown +++ b/content/reference/functions/hostsseen.markdown @@ -22,12 +22,11 @@ connected within the specified time. ```cf3 bundle agent test { -vars: + vars: + "myhosts" slist => { hostsseen("inf", "lastseen", "address") }; - "myhosts" slist => { hostsseen("inf","lastseen","address") }; - -reports: - "Found client/peer: $(myhosts)"; + reports: + "Found client/peer: $(myhosts)"; } ``` diff --git a/content/reference/functions/hostswithclass.markdown b/content/reference/functions/hostswithclass.markdown index 2ebe53802..a405440ca 100644 --- a/content/reference/functions/hostswithclass.markdown +++ b/content/reference/functions/hostswithclass.markdown @@ -26,16 +26,15 @@ classes set during the most recently collected agent run. ```cf3 bundle agent debian_hosts { -vars: - - am_policy_hub:: - "host_list" slist => hostswithclass( "debian", "name" ); - -files: - am_policy_hub:: - "/tmp/master_config.cfg" - edit_line => insert_lines("host=$(host_list)"), - create => "true"; + vars: + am_policy_hub:: + "host_list" slist => hostswithclass("debian", "name"); + + files: + am_policy_hub:: + "/tmp/master_config.cfg" + edit_line => insert_lines("host=$(host_list)"), + create => "true"; } ``` diff --git a/content/reference/functions/hostswithgroup.markdown b/content/reference/functions/hostswithgroup.markdown index 4d987eea4..c063e9a34 100644 --- a/content/reference/functions/hostswithgroup.markdown +++ b/content/reference/functions/hostswithgroup.markdown @@ -22,8 +22,7 @@ bundle agent debian_hosts { vars: am_policy_hub:: - "host_list" - slist => hostswithgroup( "Linux", "name" ); + "host_list" slist => hostswithgroup("Linux", "name"); files: am_policy_hub:: diff --git a/content/reference/functions/ifelse.markdown b/content/reference/functions/ifelse.markdown index 92821985f..fa451e9be 100644 --- a/content/reference/functions/ifelse.markdown +++ b/content/reference/functions/ifelse.markdown @@ -64,29 +64,32 @@ affect the default case?). Here's the alternative with `ifelse`: bundle agent example { classes: - "myclass" expression => "any"; - "myclass2" expression => "any"; - "secondpass" expression => "any"; - vars: - # we need to use the secondpass class because on the first pass, - # myclass and myclass2 are not defined yet + "myclass" expression => "any"; + "myclass2" expression => "any"; + "secondpass" expression => "any"; + vars: + # we need to use the secondpass class because on the first pass, + # myclass and myclass2 are not defined yet secondpass:: - # result: { "1", "single string parameter", "hardclass OK", "bundle class OK", "5 parameters OK" } - - "mylist" slist => { - ifelse(1), - ifelse("single string parameter"), - ifelse("cfengine", "hardclass OK", "hardclass broken"), - ifelse("myclass.myclass2", "bundle class OK", "bundle class broken"), - ifelse("this is not true", "5 parameters broken", - "this is also not true", "5 parameters broken 2", - "5 parameters OK"), - }; + "mylist" + slist => { + ifelse(1), + ifelse("single string parameter"), + ifelse("cfengine", "hardclass OK", "hardclass broken"), + ifelse("myclass.myclass2", "bundle class OK", "bundle class broken"), + ifelse( + "this is not true", + "5 parameters broken", + "this is also not true", + "5 parameters broken 2", + "5 parameters OK" + ), + }; reports: - "ifelse result list: $(mylist)"; + "ifelse result list: $(mylist)"; } ``` @@ -99,13 +102,12 @@ bundle agent example { vars: "passwd_path" - string => ifelse( isvariable("def.passwd_path"), "$(def.passwd_path)", - "/etc/passwd"), - + string => ifelse( + isvariable("def.passwd_path"), "$(def.passwd_path)", "/etc/passwd" + ), comment => "Use the user provided path for the passwd file if its defined in the def scope, else use a sane default. This can allow for easier policy testing and default overrides."; - } ``` diff --git a/content/reference/functions/iprange.markdown b/content/reference/functions/iprange.markdown index 53ecfac90..15e4774c4 100644 --- a/content/reference/functions/iprange.markdown +++ b/content/reference/functions/iprange.markdown @@ -19,23 +19,18 @@ Pattern matching based on IP addresses. ```cf3 bundle agent example { -classes: - - "dmz_1" expression => iprange("128.39.89.10-15"); - "lab_1" expression => iprange("128.39.74.1/23"); - - "dmz_1_eth0" expression => iprange("128.39.89.10-15", "eth0"); - "lab_1_eth0" expression => iprange("128.39.74.1/23", "eth0"); - -reports: - - dmz_1:: - - "DMZ 1 subnet"; - - lab_1:: - - "Lab 1 subnet"; + classes: + "dmz_1" expression => iprange("128.39.89.10-15"); + "lab_1" expression => iprange("128.39.74.1/23"); + "dmz_1_eth0" expression => iprange("128.39.89.10-15", "eth0"); + "lab_1_eth0" expression => iprange("128.39.74.1/23", "eth0"); + + reports: + dmz_1:: + "DMZ 1 subnet"; + + lab_1:: + "Lab 1 subnet"; } ``` diff --git a/content/reference/functions/laterthan.markdown b/content/reference/functions/laterthan.markdown index da8667cb1..c0a826636 100644 --- a/content/reference/functions/laterthan.markdown +++ b/content/reference/functions/laterthan.markdown @@ -20,12 +20,12 @@ Note that, unlike some other functions, the month argument is 1-based (i.e. 1 co ```cf3 bundle agent example { - classes: + classes: + "after_deadline" expression => laterthan(2000, 1, 1, 0, 0, 0); - "after_deadline" expression => laterthan(2000,1,1,0,0,0); - reports: - after_deadline:: - "deadline has passed"; + reports: + after_deadline:: + "deadline has passed"; } ``` diff --git a/content/reference/functions/now.markdown b/content/reference/functions/now.markdown index f4b74ae14..cdf8050e8 100644 --- a/content/reference/functions/now.markdown +++ b/content/reference/functions/now.markdown @@ -21,24 +21,21 @@ Reporting the system time of agent start and calculating what yesterday was. bundle agent example_now { vars: - "epoch" int => now(); - - "24_hours_ago" - string => format( "%d", - eval( "$(epoch)-86400", math, infix )); + "epoch" int => now(); + "24_hours_ago" string => format("%d", eval("$(epoch)-86400", math, infix)); reports: - "Today is $(with) or in unix format '$(epoch)'" - with => strftime( gmtime, "%Y-%m-%d %T", $(epoch) ); + "Today is $(with) or in unix format '$(epoch)'" + with => strftime(gmtime, "%Y-%m-%d %T", $(epoch)); - "24 hours ago was $(with) or in unix format '$(epoch)'" - with => strftime( gmtime, "%Y-%m-%d %T", $(24_hours_ago) ); + "24 hours ago was $(with) or in unix format '$(epoch)'" + with => strftime(gmtime, "%Y-%m-%d %T", $(24_hours_ago)); } bundle agent __main__ { methods: - "example_now"; + "example_now"; } ``` @@ -55,20 +52,18 @@ based on a time relative to the agent start can make use of this function. ```cf3 bundle agent gzip_recent_pdfs { - files: - - # Ensure that any file ending in .pdf that has been - # modified in the last year is compressed - - "/tmp/" - file_select => pdf_modified_within_last_year, - transformer => '/bin/gzip $(this.promiser)'; + files: + # Ensure that any file ending in .pdf that has been + # modified in the last year is compressed + "/tmp/" + file_select => pdf_modified_within_last_year, + transformer => '/bin/gzip $(this.promiser)'; } body file_select pdf_modified_within_last_year # @brief Sllect files that have been modified in the last year AND end in .pdf { - mtime => irange(ago(1,0,0,0,0,0),now); + mtime => irange(ago(1, 0, 0, 0, 0, 0), now); leaf_name => { ".*\.pdf" }; file_result => "mtime.leaf_name"; } diff --git a/content/reference/functions/on.markdown b/content/reference/functions/on.markdown index 0fe151c76..d54f01777 100644 --- a/content/reference/functions/on.markdown +++ b/content/reference/functions/on.markdown @@ -18,7 +18,7 @@ The specified date/time is an absolute date in the local timezone. ```cf3 body file_select zero_age { - mtime => irange(on(2000,1,1,0,0,0),now); + mtime => irange(on(2000, 1, 1, 0, 0, 0), now); file_result => "mtime"; } ``` diff --git a/content/reference/functions/regline.markdown b/content/reference/functions/regline.markdown index 9cf5159bb..83eaf7f18 100644 --- a/content/reference/functions/regline.markdown +++ b/content/reference/functions/regline.markdown @@ -31,32 +31,25 @@ example: bundle edit_line upgrade_cfexecd { classes: - # Check there is not already a crontab line, not identical to # the one proposed below... - "exec_fix" - not => regline(".*cf-execd.*","$(edit.filename)"), + not => regline(".*cf-execd.*", "$(edit.filename)"), scope => "bundle"; # Unless you need the class outside of the bundle you - # should always scope it to the bundle. This can - # prevent issues when the bundle is used multiple - # times, and the classes promise is expected to be - # re-evaluated. If the class is namespace scoped the - # class will be available to other bundles and persist - # until it is explicitly canceled or until the end of - # the agent run. - + # should always scope it to the bundle. This can + # prevent issues when the bundle is used multiple + # times, and the classes promise is expected to be + # re-evaluated. If the class is namespace scoped the + # class will be available to other bundles and persist + # until it is explicitly canceled or until the end of + # the agent run. insert_lines: - exec_fix:: - - "0,5,10,15,20,25,30,35,40,45,50,55 * * * * /var/cfengine/bin/cf-execd -F"; + "0,5,10,15,20,25,30,35,40,45,50,55 * * * * /var/cfengine/bin/cf-execd -F"; reports: - exec_fix:: - - "Added a 5 minute schedule to crontabs"; + "Added a 5 minute schedule to crontabs"; } ``` diff --git a/content/reference/functions/remotescalar.markdown b/content/reference/functions/remotescalar.markdown index 0fd2f60da..9f21d0567 100644 --- a/content/reference/functions/remotescalar.markdown +++ b/content/reference/functions/remotescalar.markdown @@ -41,12 +41,12 @@ vars: ```cf3 bundle server access { -access: - "value of my test_scalar, can expand variables here - $(sys.host)" - handle => "test_scalar", - comment => "Grant access to contents of test_scalar VAR", - resource_type => "literal", - admit => { "127.0.0.1" }; + access: + "value of my test_scalar, can expand variables here - $(sys.host)" + handle => "test_scalar", + comment => "Grant access to contents of test_scalar VAR", + resource_type => "literal", + admit => { "127.0.0.1" }; } ``` diff --git a/content/reference/functions/selectservers.markdown b/content/reference/functions/selectservers.markdown index 2d065e8d2..00a9c35e3 100644 --- a/content/reference/functions/selectservers.markdown +++ b/content/reference/functions/selectservers.markdown @@ -26,34 +26,37 @@ allows maintaining a list of pretested failover alternatives. ```cf3 bundle agent example { -vars: + vars: + "hosts" + slist => { "slogans.iu.hio.no", "eternity.iu.hio.no", "nexus.iu.hio.no" }; - "hosts" slist => { "slogans.iu.hio.no", "eternity.iu.hio.no", "nexus.iu.hio.no" }; - "fhosts" slist => { "www.cfengine.com", "www.cfengine.org" }; + "fhosts" slist => { "www.cfengine.com", "www.cfengine.org" }; - "up_servers" int => selectservers("@(hosts)","80","","","100","alive_servers"); - "has_favicon" int => - selectservers( - "@(hosts)", "80", + "up_servers" + int => selectservers("@(hosts)", "80", "", "", "100", "alive_servers"); + + "has_favicon" + int => selectservers( + "@(hosts)", + "80", "GET /favicon.ico HTTP/1.0$(const.n)Host: www.cfengine.com$(const.n)$(const.n)", "(?s).*OK.*", - "200", "favicon_servers"); - -classes: + "200", + "favicon_servers" + ); - "someone_alive" expression => isgreaterthan("$(up_servers)","0"); + classes: + "someone_alive" expression => isgreaterthan("$(up_servers)", "0"); + "has_favicon" expression => isgreaterthan("$(has_favicon)", "0"); - "has_favicon" expression => isgreaterthan("$(has_favicon)","0"); - -reports: + reports: "Number of active servers $(up_servers)"; - someone_alive:: - "First server $(alive_servers[0]) fails over to $(alive_servers[1])"; - - has_favicon:: - "At least $(favicon_servers[0]) has a favicon.ico"; + someone_alive:: + "First server $(alive_servers[0]) fails over to $(alive_servers[1])"; + has_favicon:: + "At least $(favicon_servers[0]) has a favicon.ico"; } ``` diff --git a/content/reference/functions/splayclass.markdown b/content/reference/functions/splayclass.markdown index 503122350..ed519edf4 100644 --- a/content/reference/functions/splayclass.markdown +++ b/content/reference/functions/splayclass.markdown @@ -42,15 +42,12 @@ by the `splayclass` is a time when you have told CFEngine _not_ to run). ```cf3 bundle agent example { -classes: + classes: + "my_turn" expression => splayclass("$(sys.host)$(sys.ipv4)", "daily"); - "my_turn" expression => splayclass("$(sys.host)$(sys.ipv4)","daily"); - -reports: - - my_turn:: - - "Load balanced class activated"; + reports: + my_turn:: + "Load balanced class activated"; } ``` diff --git a/content/reference/functions/usemodule.markdown b/content/reference/functions/usemodule.markdown index da96a462c..ee2dd14fc 100644 --- a/content/reference/functions/usemodule.markdown +++ b/content/reference/functions/usemodule.markdown @@ -21,14 +21,11 @@ directory, `WORKDIR/modules`. bundle agent test { classes: - - # returns $(user) - - "done" expression => usemodule("getusers",""); + # returns $(user) + "done" expression => usemodule("getusers", ""); commands: - - "/bin/echo" args => "test $(user)"; + "/bin/echo" args => "test $(user)"; } ``` diff --git a/content/reference/functions/version_compare.markdown b/content/reference/functions/version_compare.markdown index a7475cb8a..524599b38 100644 --- a/content/reference/functions/version_compare.markdown +++ b/content/reference/functions/version_compare.markdown @@ -35,8 +35,7 @@ bundle agent main reports: "Same patch version, but not exactly the same version string" if => and( - version_compare("$(a)", "=", "$(b)"), - not(strcmp("$(a)", "$(b)")) + version_compare("$(a)", "=", "$(b)"), not(strcmp("$(a)", "$(b)")) ); } ``` @@ -47,14 +46,13 @@ CFEngine's version comparison functions also support partial version numbers, so bundle agent main { vars: - "patch_a" - string => "3.21.1"; - "patch_b" - string => "4.0.1"; + "patch_a" string => "3.21.1"; + "patch_b" string => "4.0.1"; reports: "patch_a is a part of the 3.21 series: 3.21 == $(patch_a)" if => version_compare("3.21", "==", "$(patch_a)"); + "patch_b is in major version 4: 4 == $(patch_b)" if => version_compare("4", "==", "$(patch_b)"); } @@ -68,6 +66,7 @@ bundle agent main reports: "3.22.1 > 3.22" # No, won't be printed if => version_compare("3.22.1", ">", "3.22"); + "3.22.1 >= 3.22" # Yes, will be printed if => version_compare("3.22.1", ">=", "3.22"); } diff --git a/content/reference/language-concepts/augments.markdown b/content/reference/language-concepts/augments.markdown index e3fa910e3..440dd36a4 100644 --- a/content/reference/language-concepts/augments.markdown +++ b/content/reference/language-concepts/augments.markdown @@ -180,14 +180,15 @@ Is equivalent to this policy: ```cf3 body file control { - namespace => "MyNamespace"; + namespace => "MyNamespace"; } + bundle agent my_bundle { vars: - "Variable" - string => "value", - comment => "An optional note about why this variable is important"; + "Variable" + string => "value", + comment => "An optional note about why this variable is important"; } ``` @@ -211,14 +212,15 @@ Is equivalent to this policy: ```cf3 body file control { - namespace => "MyNamespace"; + namespace => "MyNamespace"; } + bundle agent my_bundle { vars: - "Variable" - string => "value", - meta => { "inventory", "attribute_name=My Inventory" }; + "Variable" + string => "value", + meta => { "inventory", "attribute_name=My Inventory" }; } ``` diff --git a/content/reference/language-concepts/bodies.markdown b/content/reference/language-concepts/bodies.markdown index 92ed2731d..8e01dcae8 100644 --- a/content/reference/language-concepts/bodies.markdown +++ b/content/reference/language-concepts/bodies.markdown @@ -41,11 +41,11 @@ body perms system groups => { "root" }; } -body perms mog(mode,user,group) +body perms mog(mode, user, group) { owners => { "$(user)" }; groups => { "$(group)" }; - mode => "$(mode)"; + mode => "$(mode)"; } ``` @@ -153,7 +153,7 @@ special body whose name is `control`. ```cf3 body agent control { - bundlesequence => { "test" }; + bundlesequence => { "test" }; } ``` @@ -162,7 +162,7 @@ This promise bodies configures the `bundlesequence` to execute on a cf-agent. ```cf3 body server control { - allowconnects => { "127.0.0.1" , "::1", @(def.acl) }; + allowconnects => { "127.0.0.1", "::1", @(def.acl) }; } ``` @@ -206,31 +206,28 @@ unaffected. ```cf3 bundle agent example { - files: - - # Since the 'files_action' action body is defined in the 'bodydefault' namespce, - # and since this promise is in the 'default' namespace (no alternate namespace is - # declared previously) this promise will not actually modify the file content if - # it is not as promised. Instead it will warn that a change wants to be made. - - "/etc/motd" - content => "There are, in fact, rules. You have been notified."; - - # Since this promise has an action body attached, the default action body for - # files will not be applied and this file would be fixed. + files: + # Since the 'files_action' action body is defined in the 'bodydefault' namespce, + # and since this promise is in the 'default' namespace (no alternate namespace is + # declared previously) this promise will not actually modify the file content if + # it is not as promised. Instead it will warn that a change wants to be made. + "/etc/motd" content => "There are, in fact, rules. You have been notified."; - "/etc/issue.net" - content => "WARNING: You are being monitored. We are all being monitored. This is a cry for help.", - action => if_elapsed_day; + # Since this promise has an action body attached, the default action body for + # files will not be applied and this file would be fixed. + "/etc/issue.net" + content => "WARNING: You are being monitored. We are all being monitored. This is a cry for help.", + action => if_elapsed_day; } + body file control { - namespace => "bodydefault"; + namespace => "bodydefault"; } body action files_action { - action_policy => "warn"; + action_policy => "warn"; } body file control diff --git a/content/reference/language-concepts/bundles.markdown b/content/reference/language-concepts/bundles.markdown index 8794b390d..d0d125548 100644 --- a/content/reference/language-concepts/bundles.markdown +++ b/content/reference/language-concepts/bundles.markdown @@ -64,13 +64,11 @@ definitions. ```cf3 bundle common globals { -vars: - - "global_var" string => "value"; - -classes: + vars: + "global_var" string => "value"; - "global_class" expression => "value"; + classes: + "global_class" expression => "value"; } ``` @@ -152,7 +150,7 @@ from it that correspond to the second evaluation. In other words, if you have: bundle agent mybundle(x) { vars: - "y" string => $(x); + "y" string => $(x); } ``` diff --git a/content/reference/language-concepts/classes.markdown b/content/reference/language-concepts/classes.markdown index 49862f9b5..d7685c87b 100644 --- a/content/reference/language-concepts/classes.markdown +++ b/content/reference/language-concepts/classes.markdown @@ -255,18 +255,18 @@ This example defines a few soft classes local to the `myclasses` bundle. ```cf3 bundle agent myclasses { -classes: - "always"; - "always2" expression => "any"; - "solinux" expression => "linux||solaris"; - "alt_class" or => { "linux", "solaris", fileexists("/etc/fstab") }; - "oth_class" and => { fileexists("/etc/shadow"), fileexists("/etc/passwd") }; + classes: + "always"; + "always2" expression => "any"; + "solinux" expression => "linux||solaris"; + "alt_class" or => { "linux", "solaris", fileexists("/etc/fstab") }; + "oth_class" and => { fileexists("/etc/shadow"), fileexists("/etc/passwd") }; -reports: - alt_class:: - # This will only report "Boo!" on linux, solaris, or any system - # on which the file /etc/fstab exists - "Boo!"; + reports: + alt_class:: + # This will only report "Boo!" on linux, solaris, or any system + # on which the file /etc/fstab exists + "Boo!"; } ``` @@ -314,14 +314,14 @@ bundle agent greetings Evening:: "Good evening!"; - "! any":: + "! any":: "This report won't ever be seen."; - # whitespace allowed only in 3.8 and later - Friday . Evening:: + # whitespace allowed only in 3.8 and later + Friday . Evening:: "It's Friday evening, TGIF!"; - "Monday . Evening":: + "Monday . Evening":: "It's Monday evening."; } ``` @@ -355,16 +355,16 @@ variables: ```cf3 bundle agent greetings { - vars: - "myclassname" string => "Evening"; + vars: + "myclassname" string => "Evening"; reports: - "$(myclassname)":: - "Good evening!"; - "What a wonderful sunset"; + "$(myclassname)":: + "Good evening!"; + "What a wonderful sunset"; - any:: - "Good evening too!" if => "$(myclassname)"; + any:: + "Good evening too!" if => "$(myclassname)"; } ``` @@ -378,42 +378,39 @@ as the resulting expansion is a legal class expression. bundle agent example { vars: - "french_cities" slist => { "toulouse", "paris" }; - "german_cities" slist => { "berlin" }; - "italian_cities" slist => { "milan" }; - "usa_cities" slist => { "lawrence" }; + "french_cities" slist => { "toulouse", "paris" }; + "german_cities" slist => { "berlin" }; + "italian_cities" slist => { "milan" }; + "usa_cities" slist => { "lawrence" }; - "all_cities" slist => { @(french_cities), @(german_cities), @(italian_cities), @(usa_cities) }; + "all_cities" + slist => { + @(french_cities), @(german_cities), @(italian_cities), @(usa_cities) + }; classes: - "italy" or => { @(italian_cities) }; - "germany" or => { @(german_cities) }; - "france" or => { @(french_cities) }; + "italy" or => { @(italian_cities) }; + "germany" or => { @(german_cities) }; + "france" or => { @(french_cities) }; reports: "It's $(sys.date) here"; Morning.italy:: - "Good morning from Italy", - if => "$(all_cities)"; + "Good morning from Italy" if => "$(all_cities)"; Afternoon.germany:: - "Good afternoon from Germany", - if => "$(all_cities)"; + "Good afternoon from Germany" if => "$(all_cities)"; france:: - "Hello from France", - if => "$(all_cities)"; + "Hello from France" if => "$(all_cities)"; france:: - "IMPOSSSIBLE! THIS WILL NOT PRINT!!!", - unless => "france"; + "IMPOSSSIBLE! THIS WILL NOT PRINT!!!" unless => "france"; "$(all_cities)":: "Hello from $(all_cities)"; - - "Hello from $(all_cities), if edition", - if => "$(all_cities)"; + "Hello from $(all_cities), if edition" if => "$(all_cities)"; } ``` @@ -544,27 +541,32 @@ containers to be used in context expressions: ```cf3 bundle agent main { - vars: - "checks" data => '[true, false]'; - # find all classes named - "classes_named_true" slist => classesmatching('true'); + vars: + "checks" data => '[true, false]'; + + # find all classes named + "classes_named_true" slist => classesmatching('true'); classes: - # always defined - "first_check" expression => "$(checks[0])"; - # never defined - "second_check" expression => "$(checks[1])"; + # always defined + "first_check" expression => "$(checks[0])"; + + # never defined + "second_check" expression => "$(checks[1])"; reports: - # prints nothing, there are no classes named 'true' - "Classes named 'true': $(classes_named_true)"; + # prints nothing, there are no classes named 'true' + "Classes named 'true': $(classes_named_true)"; first_check:: "The class was defined from '$(checks[0])'"; + !first_check:: "The class was NOT defined from '$(checks[0])'"; + second_check:: "The class was defined from '$(checks[1])'"; + !second_check:: "The class was NOT defined from '$(checks[1])'"; } @@ -640,42 +642,39 @@ Finally, `restart_class` classes in `processes` are global. ```cf3 body common control { - bundlesequence => { "global","local_one", "local_two" }; + bundlesequence => { "global", "local_one", "local_two" }; } ################################# - bundle common global { - classes: - # The soft class "zero" is always satisfied, - # and is global in scope - "zero" expression => "any"; + classes: + # The soft class "zero" is always satisfied, + # and is global in scope + "zero" expression => "any"; } ################################# - bundle agent local_one { - classes: - # The soft class "one" is always satisfied, - # and is local in scope to local_one - "one" expression => "any"; + classes: + # The soft class "one" is always satisfied, + # and is local in scope to local_one + "one" expression => "any"; } ################################# - bundle agent local_two { - classes: - # The soft class "two" is always satisfied, - # and is local in scope to ls_2 - "two" expression => "any"; - - reports: - zero.!one.two:: - # This report will be generated - "Success"; + classes: + # The soft class "two" is always satisfied, + # and is local in scope to ls_2 + "two" expression => "any"; + + reports: + zero.!one.two:: + # This report will be generated + "Success"; } ``` diff --git a/content/reference/language-concepts/loops.markdown b/content/reference/language-concepts/loops.markdown index 0c94210ac..35b14d065 100644 --- a/content/reference/language-concepts/loops.markdown +++ b/content/reference/language-concepts/loops.markdown @@ -16,16 +16,16 @@ about color." ```cf3 body common control { - bundlesequence => { "color_example" }; + bundlesequence => { "color_example" }; } bundle agent color_example { - vars: - "color" slist => { "red", "green", "blue" }; + vars: + "color" slist => { "red", "green", "blue" }; - reports: - "Let's talk about $(color)"; + reports: + "Let's talk about $(color)"; } ``` @@ -44,20 +44,19 @@ Here's a more complex example. ```cf3 body common control { - bundlesequence => { "example" }; + bundlesequence => { "example" }; } bundle agent example { - vars: - "component" slist => { "cf-monitord", "cf-serverd", "cf-execd" }; - - "array[cf-monitord]" string => "The monitor"; - "array[cf-serverd]" string => "The server"; - "array[cf-execd]" string => "The executor, not executionist"; - - reports: - "$(component) is $(array[$(component)])"; + vars: + "component" slist => { "cf-monitord", "cf-serverd", "cf-execd" }; + "array[cf-monitord]" string => "The monitor"; + "array[cf-serverd]" string => "The server"; + "array[cf-execd]" string => "The executor, not executionist"; + + reports: + "$(component) is $(array[$(component)])"; } ``` @@ -86,21 +85,19 @@ output of: ```cf3 body common control { - bundlesequence => { "example" }; + bundlesequence => { "example" }; } bundle agent example { -vars: - "component" slist => { "cf-monitord", "cf-serverd", "cf-execd" }; - - "array[cf-monitord]" string => "The monitor"; - "array[cf-serverd]" string => "The server"; - "array[cf-execd]" string => "The executor, not executioner"; - -commands: - "/bin/echo $(component) is" - args => "$(array[$(component)])"; + vars: + "component" slist => { "cf-monitord", "cf-serverd", "cf-execd" }; + "array[cf-monitord]" string => "The monitor"; + "array[cf-serverd]" string => "The server"; + "array[cf-execd]" string => "The executor, not executioner"; + + commands: + "/bin/echo $(component) is" args => "$(array[$(component)])"; } ``` @@ -117,16 +114,11 @@ CFEngine can iterate across multiple lists simultaneously. ```cf3 bundle agent iteration { -vars: - "stats" slist => { "value", "av", "dev" }; - - "monvars" slist => { - "rootprocs", - "otherprocs", - "diskfree", - "loadavg" - }; -reports: + vars: + "stats" slist => { "value", "av", "dev" }; + "monvars" slist => { "rootprocs", "otherprocs", "diskfree", "loadavg" }; + + reports: "mon.$(stats)_$(monvars) is $(mon.$(stats)_$(monvars))"; } ``` diff --git a/content/reference/language-concepts/pattern-matching-and-referencing.markdown b/content/reference/language-concepts/pattern-matching-and-referencing.markdown index cb410f162..62a3dd3ad 100644 --- a/content/reference/language-concepts/pattern-matching-and-referencing.markdown +++ b/content/reference/language-concepts/pattern-matching-and-referencing.markdown @@ -38,14 +38,11 @@ Consider the examples below: ```cf3 bundle agent testbundle { -files: - - # This might be a dangerous pattern - see explanation in the next section - - # on "Runaway change warning" - - "/home/mark/tmp/cf([23])?_(.*)" - edit_line => myedit("second backref: $(match.2)"); + files: + # This might be a dangerous pattern - see explanation in the next section + # on "Runaway change warning" + "/home/mark/tmp/cf([23])?_(.*)" + edit_line => myedit("second backref: $(match.2)"); } ``` @@ -83,39 +80,32 @@ the `replace_patterns` promise. bundle edit_line myedit(parameter) { vars: - - "edit_variable" string => "private edit variable is $(parameter)"; + "edit_variable" string => "private edit variable is $(parameter)"; insert_lines: - - "$(edit_variable)"; + "$(edit_variable)"; replace_patterns: - - # replace shell comments with C comments - - "#(.*)" - + # replace shell comments with C comments + "#(.*)" replace_with => C_comment, - select_region => MySection("New section"); - } + select_region => MySection("New section"); +} ######################################## # Bodies ######################################## - body replace_with C_comment { -replace_value => "/* $(match.1) */"; # backreference from replace_patterns -occurrences => "all"; # first, last, or all + replace_value => "/* $(match.1) */"; # backreference from replace_patterns + occurrences => "all"; # first, last, or all } ######################################################## - body select_region MySection(x) { - select_start => "\[$(x)\]"; - select_end => "\[.*\]"; + select_start => "\[$(x)\]"; + select_end => "\[.*\]"; } ``` @@ -185,45 +175,38 @@ CFEngine. # HashCommentLines implemented in CFEngine 3 # ###################################################################### - body common control { - version => "1.2.3"; - bundlesequence => { "testbundle" }; + version => "1.2.3"; + bundlesequence => { "testbundle" }; } ######################################################## - bundle agent testbundle { -files: - "/home/mark/tmp/comment_test" - create => "true", - edit_line => comment_lines_matching; + files: + "/home/mark/tmp/comment_test" + create => "true", + edit_line => comment_lines_matching; } ######################################################## - bundle edit_line comment_lines_matching - { +{ vars: - "regexes" slist => { "one.*", "two.*", "four.*" }; replace_patterns: - - "^($(regexes))$" - replace_with => comment("# "); - } + "^($(regexes))$" replace_with => comment("# "); +} ######################################## # Bodies ######################################## - body replace_with comment(c) { - replace_value => "$(c) $(match.1)"; - occurrences => "all"; + replace_value => "$(c) $(match.1)"; + occurrences => "all"; } ``` @@ -251,31 +234,28 @@ pathname either one way or another. (see the `pathtype` attribute). ```cf3 body common control { - bundlesequence => { "wintest" }; + bundlesequence => { "wintest" }; } ######################################## - bundle agent wintest { -files: - "c:/tmp/file/f.*" # "best guess" interpretation - delete => nodir; - - "c:\tmp\file" - delete => nodir, - pathtype => "literal"; # force literal string interpretation - - "C:/windows/tmp/f\d" - delete => nodir, - pathtype => "regex"; # force regular expression interpretation + files: + "c:/tmp/file/f.*" # "best guess" interpretation + delete => nodir; + + "c:\tmp\file" + delete => nodir, + pathtype => "literal"; # force literal string interpretation + "C:/windows/tmp/f\d" + delete => nodir, + pathtype => "regex"; # force regular expression interpretation } ######################################## - body delete nodir { - rmdirs => "false"; + rmdirs => "false"; } ``` diff --git a/content/reference/language-concepts/promises.markdown b/content/reference/language-concepts/promises.markdown index 13e971513..a62565ed3 100644 --- a/content/reference/language-concepts/promises.markdown +++ b/content/reference/language-concepts/promises.markdown @@ -138,16 +138,15 @@ For example, the following promises use the same attribute multiple times. bundle agent bad_example { classes: - "myclass" expression => "cfengine", expression => "my_other_class"; files: "/tmp/example" - perms => m( 600 ), - perms => owner( "root" ), - perms => group( "root" ); + perms => m(600), + perms => owner("root"), + perms => group("root"); } ``` diff --git a/content/reference/macros.markdown b/content/reference/macros.markdown index 020012a99..6d65baa1a 100644 --- a/content/reference/macros.markdown +++ b/content/reference/macros.markdown @@ -29,8 +29,9 @@ The contained policy is only included if the version is greater than or equal to bundle agent extractor { @if minimum_version(3.8) -# This block is only parsed on CFEngine 3.8 or later -vars: "container" data => parsejson('{}'); + # This block is only parsed on CFEngine 3.8 or later + vars: + "container" data => parsejson('{}'); @endif } ``` @@ -112,8 +113,7 @@ bundle agent extractor @if before_version(3.15) # Policy to work around issue which was fixed in 3.15 vars: - "container" - data => parsejson('{}'); + "container" data => parsejson('{}'); @endif } ``` @@ -134,8 +134,7 @@ bundle agent extractor @if after_version(3.15) # This policy is only parsed on 3.16+ vars: - "container" - data => parsejson('{}'); + "container" data => parsejson('{}'); @endif } ``` @@ -158,13 +157,11 @@ bundle agent extractor @if minimum_version(3.16) # Implementation for 3.16+ vars: - "container" - data => classfiltercsv("/tmp/data.csv", "true", "any"); + "container" data => classfiltercsv("/tmp/data.csv", "true", "any"); @else # Implementation for versions before 3.16 vars: - "container" - data => readcsv("/tmp/data.csv"); + "container" data => readcsv("/tmp/data.csv"); @endif } ``` @@ -180,10 +177,11 @@ You can conditionally include policy test using the `@if` macro. ```cf3 bundle agent extractor { - @if feature(xml) -# the yaml library may not be compiled in - vars: "container" data => parseyaml("---"); - @endif +@if feature(xml) + # the yaml library may not be compiled in + vars: + "container" data => parseyaml("---"); +@endif } ``` diff --git a/content/reference/promise-types/_index.markdown b/content/reference/promise-types/_index.markdown index 9a3d3a317..031d690ab 100644 --- a/content/reference/promise-types/_index.markdown +++ b/content/reference/promise-types/_index.markdown @@ -97,8 +97,8 @@ for the specific promise it's attached to. ```cf3 body action example { - ifelapsed => "120"; # 2 hours - expireafter => "240"; # 4 hours + ifelapsed => "120"; # 2 hours + expireafter => "240"; # 4 hours } ``` @@ -137,8 +137,8 @@ on the long running promise. ```cf3 body action example { - ifelapsed => "120"; # 2 hours - expireafter => "240"; # 4 hours + ifelapsed => "120"; # 2 hours + expireafter => "240"; # 4 hours } ``` @@ -224,16 +224,12 @@ defined in body common control over UDP. Please note bundle agent test { vars: - - "software" slist => { "/root/xyz", "/tmp/xyz" }; + "software" slist => { "/root/xyz", "/tmp/xyz" }; files: - - "$(software)" - - create => "true", - action => logme("$(software)"); - + "$(software)" + create => "true", + action => logme("$(software)"); } body action logme(x) @@ -364,15 +360,13 @@ background on Windows. bundle agent main { commands: - - "/bin/sleep 10" - action => background; + "/bin/sleep 10" action => background; "/bin/sleep" args => "20", - action => background; - + action => background; } + body action background { background => "true"; @@ -737,12 +731,11 @@ from 0 to 255. bundle agent cmdtest { commands: - "/bin/false" - classes => example; + "/bin/false" classes => example; reports: - waskept:: - "The command-promise was kept!"; + waskept:: + "The command-promise was kept!"; } body classes example @@ -788,12 +781,11 @@ from 0 to 255. bundle agent cmdtest { commands: - "/bin/false" - classes => example; + "/bin/false" classes => example; reports: - wasrepaired:: - "The command-promise got repaired!"; + wasrepaired:: + "The command-promise got repaired!"; } body classes example @@ -845,16 +837,15 @@ body common control bundle agent cmdtest { files: - "/tmp/test" - copy_from => copy("/etc/passwd"); + "/tmp/test" copy_from => copy("/etc/passwd"); - "/tmp/test" - classes => example, - transformer => "/bin/grep -q lkajfo999999 $(this.promiser)"; + "/tmp/test" + classes => example, + transformer => "/bin/grep -q lkajfo999999 $(this.promiser)"; reports: - hasfailed:: - "The files-promise failed!"; + hasfailed:: + "The files-promise failed!"; } body classes example @@ -1035,14 +1026,9 @@ A specific example would be: bundle agent example { commands: - - any:: - - "/bin/echo This is linux" - if => "linux"; - - "/bin/echo This is solaris" - if => "solaris"; + any:: + "/bin/echo This is linux" if => "linux"; + "/bin/echo This is solaris" if => "solaris"; } ``` @@ -1080,8 +1066,8 @@ will be skipped if `something` is never resolved: bundle agent main { classes: - "a" if => "$(no_such_var)"; # Will be skipped - "b" if => not("$(no_such_var)"); # Will be skipped + "a" if => "$(no_such_var)"; # Will be skipped + "b" if => not("$(no_such_var)"); # Will be skipped } ``` @@ -1182,9 +1168,8 @@ A specific example would be: bundle agent example { commands: - any:: - "/bin/echo This is NOT linux" - unless => "linux"; + any:: + "/bin/echo This is NOT linux" unless => "linux"; } ``` @@ -1208,11 +1193,10 @@ promise to be skipped. Since `if` defaults to skipping in those cases, bundle agent main { classes: - "a" if => "any"; # Will be evaluated - "b" unless => "any"; # Will be skipped - - "c" if => "$(no_such_var)"; # Will be skipped - "d" unless => "$(no_such_var)"; # Will be evaluated + "a" if => "any"; # Will be evaluated + "b" unless => "any"; # Will be skipped + "c" if => "$(no_such_var)"; # Will be skipped + "d" unless => "$(no_such_var)"; # Will be evaluated } ``` @@ -1287,7 +1271,7 @@ Since the right hand side for this attribute is an slist, multiple strings (tags ```cf3 body ANYTYPE mybody { - meta => { "deprecated" , "CFE-1234", "CVE-2020-1234" }; + meta => { "deprecated", "CFE-1234", "CVE-2020-1234" }; } ``` diff --git a/content/reference/promise-types/access.markdown b/content/reference/promise-types/access.markdown index d67676164..b13a46d26 100644 --- a/content/reference/promise-types/access.markdown +++ b/content/reference/promise-types/access.markdown @@ -303,16 +303,10 @@ policy. Example: ```cf3 bundle server my_access_rules() { -access: - "/directory/" - admit => { - "127.0.0.1", - ".example.org", - }, - deny => { - "badhost_1.example.org", - "badhost_1.example.org", - }; + access: + "/directory/" + admit => { "127.0.0.1", ".example.org" }, + deny => { "badhost_1.example.org", "badhost_1.example.org" }; } ``` @@ -323,12 +317,9 @@ bundle server my_access_rules() { access: "/directory/" - admit_ips => { "127.0.0.1" }, + admit_ips => { "127.0.0.1" }, admit_hostnames => { ".example.org" }, - deny_hostnames => { - "badhost_1.example.org", - "badhost_1.example.org" - }; + deny_hostnames => { "badhost_1.example.org", "badhost_1.example.org" }; } ``` @@ -623,27 +614,32 @@ bundle server my_access_rules() comment => "Grant access to contents of test_scalar VAR", resource_type => "literal", admit_ips => { "127.0.0.1" }; + "XYZ" resource_type => "variable", handle => "XYZ", admit_ips => { "$(sys.policy_hub)" }; - "delta" + + "delta" comment => "Grant access to cfengine hub to collect report deltas", resource_type => "query", - admit_ips => { "$(sys.policy_hub)" }; - "full" + admit_ips => { "$(sys.policy_hub)" }; + + "full" comment => "Grant access to cfengine hub to collect full report dump", resource_type => "query", - admit_ips => { "$(sys.policy_hub)" }; - "magic_bundle" + admit_ips => { "$(sys.policy_hub)" }; + + "magic_bundle" comment => "Grant access to the hub to activate magic_bundle with cf-runagent", resource_type => "bundle", admit_ips => { "$(sys.policy_hub)" }; - am_policy_hub:: - "collect_calls" - comment => "Enable call-collect report collection for the specific client", - resource_type => "query", - admit_ips => { "1.2.3.4" }; + + am_policy_hub:: + "collect_calls" + comment => "Enable call-collect report collection for the specific client", + resource_type => "query", + admit_ips => { "1.2.3.4" }; } ``` diff --git a/content/reference/promise-types/classes.markdown b/content/reference/promise-types/classes.markdown index f6f517e20..5af7a28f3 100644 --- a/content/reference/promise-types/classes.markdown +++ b/content/reference/promise-types/classes.markdown @@ -12,12 +12,10 @@ default. ```cf3 bundle common g { -classes: - - "one" expression => "any"; # always defined - "two"; # always defined - - "client_network" expression => iprange("128.39.89.0/24"); + classes: + "one" expression => "any"; # always defined + "two"; # always defined + "client_network" expression => iprange("128.39.89.0/24"); } ``` @@ -46,8 +44,7 @@ For example, the following promise defines the class `web` when a file exists: bundle agent example { classes: - "web" - if => fileexists("/etc/httpd/httpd.conf"); + "web" if => fileexists("/etc/httpd/httpd.conf"); } ``` @@ -232,16 +229,14 @@ The value specifies time in minutes. ```cf3 bundle common setclasses { -classes: - - "cached_classes" - or => { "any" }, - persistence => "1"; - - "cached_class" - expression => "any", - persistence => "1"; + classes: + "cached_classes" + or => { "any" }, + persistence => "1"; + "cached_class" + expression => "any", + persistence => "1"; } ``` @@ -259,28 +254,26 @@ put them into a separate bundle in a file `classes.cf`. ```cf3 # promises.cf - body common control { -persistent_classes:: - bundlesequence => { "test" }; + persistent_classes:: + bundlesequence => { "test" }; -!persistent_classes:: - bundlesequence => { "setclasses", "test" }; + !persistent_classes:: + bundlesequence => { "setclasses", "test" }; -!persistent_classes:: - inputs => { "classes.cf" }; + !persistent_classes:: + inputs => { "classes.cf" }; } bundle agent test { -reports: - - !my_persistent_class:: - "no persistent class"; + reports: + !my_persistent_class:: + "no persistent class"; - my_persistent_class:: - "persistent class defined"; + my_persistent_class:: + "persistent class defined"; } ``` @@ -308,6 +301,52 @@ classes: **See also:** [`persistence` classes attribute][classes#persistence], [`persist_time` in classes body][Promise types#persist_time] +### timer_policy + +**Description:** Determines whether a persistent class restarts its counter +when rediscovered. + +When a [`persistence`][classes#persistence] timer is set, `timer_policy` +controls what happens on later runs while the class is still defined (loaded +from the persistent store): + +- `reset` re-evaluates the promise and restarts the timer, so the class keeps + persisting for as long as the policy keeps running and the expression stays + true. +- `absolute` preserves the original expiry. While the class is already defined + the promise is skipped, so the class disappears once the original timer + elapses, regardless of how often the policy runs. + +This is the counterpart of `timer_policy` in the classes body, which has always +defaulted to `reset`. + +**Type:** (menu option) + +**Allowed input range:** `absolute|reset` + +**Default value:** absolute + +**Example:** + +```cf3 +bundle common setclasses +{ + classes: + "cached_class" + expression => "any", + persistence => "120", + timer_policy => "reset"; +} +``` + +**History:** + +- Introduced in CFEngine 3.27.2. +- The default is `absolute`, preserving the historical persistent-class + behavior. The default changed to `reset` in 3.28.0. + +**See also:** [`persistence` classes attribute][classes#persistence], [`timer_policy` in classes body][Promise types#timer_policy], [`persist_time` in classes body][Promise types#persist_time] + ### not **Description:** Evaluate the negation of string expression in normal form @@ -385,16 +424,18 @@ CFEngine. ```cf3 bundle common g { -classes: - "selection" select_class => { "one", "two" }; - -reports: - one:: - "One was selected"; - two:: - "Two was selected"; - selection:: - "A selection was made"; + classes: + "selection" select_class => { "one", "two" }; + + reports: + one:: + "One was selected"; + + two:: + "Two was selected"; + + selection:: + "A selection was made"; } ``` diff --git a/content/reference/promise-types/commands.markdown b/content/reference/promise-types/commands.markdown index ad05f0d2d..e7dab07b9 100644 --- a/content/reference/promise-types/commands.markdown +++ b/content/reference/promise-types/commands.markdown @@ -29,17 +29,13 @@ commands-promise in a very flexible way. See the `kept_returncodes`, ```cf3 bundle agent example - { -commands: - - "/bin/sleep 10" - action => background; - - "/bin/sleep" - args => "20", - action => background; + commands: + "/bin/sleep 10" action => background; + "/bin/sleep" + args => "20", + action => background; } ``` @@ -72,8 +68,7 @@ bundle agent example "/usr/bin/env MY_ENVIRONMENT_VARIABLE=something_special /tmp/cmd"; # Or equivalent - "/usr/bin/env" - args => "ME=something_special /tmp/cmd"; + "/usr/bin/env" args => "ME=something_special /tmp/cmd"; } ``` @@ -182,13 +177,13 @@ as a non-privileged user inside an isolated directory tree. ```cf3 body contain example { - useshell => "noshell"; - umask => "077"; + useshell => "noshell"; + umask => "077"; exec_owner => "mysql_user"; exec_group => "nogroup"; -exec_timeout => "60"; - chdir => "/working/path"; - chroot => "/private/path"; + exec_timeout => "60"; + chdir => "/working/path"; + chroot => "/private/path"; } ``` @@ -229,7 +224,7 @@ For compatibility, the boolean values are also supported, and map to ```cf3 body contain example { -useshell => "useshell"; + useshell => "useshell"; } ``` @@ -262,7 +257,7 @@ thus ignored by Windows versions of CFEngine. ```cf3 body contain example { -umask => "077"; + umask => "077"; } ``` @@ -287,7 +282,7 @@ CFEngine. ```cf3 body contain example { -exec_owner => "mysql_user"; + exec_owner => "mysql_user"; } ``` @@ -309,7 +304,7 @@ them. ```cf3 body contain example { -exec_group => "nogroup"; + exec_group => "nogroup"; } ``` @@ -329,7 +324,7 @@ case of failure. ```cf3 body contain example { -exec_timeout => "30"; + exec_timeout => "30"; } ``` @@ -351,9 +346,8 @@ it works like the cd shell command. ```cf3 body contain example - { -chdir => "/containment/directory"; + chdir => "/containment/directory"; } ``` @@ -374,9 +368,8 @@ process. Windows does not support this feature. ```cf3 body contain example - { -chroot => "/private/path"; + chroot => "/private/path"; } ``` @@ -400,7 +393,7 @@ checks to user defined scripts. ```cf3 body contain example { -preview => "true"; + preview => "true"; } ``` @@ -420,7 +413,7 @@ error to `/dev/null`. ```cf3 body contain example { -no_output => "true"; + no_output => "true"; } ``` @@ -510,35 +503,28 @@ And here is an example using it: ```cf3 body common control { -bundlesequence => { def, modtest }; + bundlesequence => { def, modtest }; } bundle agent def { -commands: - - "$(sys.workdir)/modules/module_name" - module => "true"; - -reports: - - # Each module forms a private context with its name as id - module_class:: + commands: + "$(sys.workdir)/modules/module_name" module => "true"; - "Module set variable $(module_name.myscalar)"; + reports: + # Each module forms a private context with its name as id + module_class:: + "Module set variable $(module_name.myscalar)"; } bundle agent modtest { -vars: - - "mylist" slist => { @(module_name.mylist) }; + vars: + "mylist" slist => { @(module_name.mylist) }; -reports: - - module_class:: - - "Module set variable $(mylist)"; + reports: + module_class:: + "Module set variable $(mylist)"; } ``` @@ -568,30 +554,29 @@ execution of a command): ```cf3 bundle agent sendmail { -commands: - # This next module checks a specific failure mode of dcc, namely - # more than 3 error states since the last time we ran cf-agent - is_mailhost:: - "/bin/test `/usr/bin/tail -100 /var/log/maillog | /usr/bin/grep 'Milter (dcc): to error state' | /usr/bin/wc -l` -gt 3 echo '+start_dccm' || echo + commands: + # This next module checks a specific failure mode of dcc, namely + # more than 3 error states since the last time we ran cf-agent + is_mailhost:: + "/bin/test `/usr/bin/tail -100 /var/log/maillog | /usr/bin/grep 'Milter (dcc): to error state' | /usr/bin/wc -l` -gt 3 echo '+start_dccm' || echo ''" - contain => shell_command, - module => "true"; + contain => shell_command, + module => "true"; start_dccm:: - "/var/dcc/libexec/start-dccm" - contain => not_paranoid; + "/var/dcc/libexec/start-dccm" contain => not_paranoid; } body contain shell_command { - useshell => "useshell"; + useshell => "useshell"; } body contain not_paranoid { - useshell => "no"; - exec_owner => "root"; - umask => "22"; + useshell => "no"; + exec_owner => "root"; + umask => "22"; } ``` diff --git a/content/reference/promise-types/databases.markdown b/content/reference/promise-types/databases.markdown index 3024a22e2..eb65863eb 100644 --- a/content/reference/promise-types/databases.markdown +++ b/content/reference/promise-types/databases.markdown @@ -82,57 +82,49 @@ body database_server name ```cf3 body common control { -bundlesequence => { "databases" }; + bundlesequence => { "databases" }; } bundle agent databases - { -#commands: - -# "/usr/bin/createdb cf_topic_maps", - -# contain => as_user("mysql"); - -databases: - - "cf_topic_maps/topics" - - database_operation => "create", - database_type => "sql", - database_columns => { - "topic_name,varchar,256", - "topic_comment,varchar,1024", - "topic_id,varchar,256", - "topic_type,varchar,256", - "topic_extra,varchar,26" - }, - - database_server => myserver; - + #commands: + # "/usr/bin/createdb cf_topic_maps", + # contain => as_user("mysql"); + databases: + "cf_topic_maps/topics" + database_operation => "create", + database_type => "sql", + database_columns => { + "topic_name,varchar,256", + "topic_comment,varchar,1024", + "topic_id,varchar,256", + "topic_type,varchar,256", + "topic_extra,varchar,26", + }, + database_server => myserver; } ################################################ - body database_server myserver { -any:: - db_server_owner => "postgres"; - db_server_password => ""; - db_server_host => "localhost"; - db_server_type => "postgres"; - db_server_connection_db => "postgres"; -none:: - db_server_owner => "root"; - db_server_password => ""; - db_server_host => "localhost"; - db_server_type => "mysql"; - db_server_connection_db => "mysql"; + any:: + db_server_owner => "postgres"; + db_server_password => ""; + db_server_host => "localhost"; + db_server_type => "postgres"; + db_server_connection_db => "postgres"; + + none:: + db_server_owner => "root"; + db_server_password => ""; + db_server_host => "localhost"; + db_server_type => "mysql"; + db_server_connection_db => "mysql"; } body contain as_user(x) { -exec_owner => "$(x)"; + exec_owner => "$(x)"; } ``` @@ -245,11 +237,11 @@ for their respective database servers. ```cf3 body database_server myserver(x) { -db_server_owner => "$(x)"; -db_server_password => ""; -db_server_host => "localhost"; -db_server_type => "$(mysql)"; -db_server_connection_db => "$(x)"; + db_server_owner => "$(x)"; + db_server_password => ""; + db_server_host => "localhost"; + db_server_type => "$(mysql)"; + db_server_connection_db => "$(x)"; } ``` @@ -348,17 +340,15 @@ considered to be instances of individual columns. ```cf3 bundle agent databases { -databases: - - windows:: - - # Registry has (value,data) pairs in "keys" which are directories - - "HKEY_LOCAL_MACHINE\SOFTWARE\CFEngine AS\CFEngine" - - database_operation => "create", - database_rows => { "value1,REG_SZ,new value 1", "value2,REG_DWORD,12345"} , - database_type => "ms_registry"; + databases: + windows:: + # Registry has (value,data) pairs in "keys" which are directories + "HKEY_LOCAL_MACHINE\SOFTWARE\CFEngine AS\CFEngine" + database_operation => "create", + database_rows => { + "value1,REG_SZ,new value 1", "value2,REG_DWORD,12345" + }, + database_type => "ms_registry"; } ``` @@ -375,14 +365,12 @@ If a column value has a comma you can escape the comma with backslash `\,`. bundle agent main # @brief Configure system variables for hosts that should not use a proxy { - databases: windows:: "HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment" database_operation => "create", - database_rows => - { - "NO_PROXY,REG_SZ,localhost\,127.0.0.1\,localaddress\,.localdomain\,169.254.169.254\,.cfengine.com" + database_rows => { + "NO_PROXY,REG_SZ,localhost\,127.0.0.1\,localaddress\,.localdomain\,169.254.169.254\,.cfengine.com", }, database_type => "ms_registry"; } diff --git a/content/reference/promise-types/files/_index.markdown b/content/reference/promise-types/files/_index.markdown index cf97fc892..78562a950 100644 --- a/content/reference/promise-types/files/_index.markdown +++ b/content/reference/promise-types/files/_index.markdown @@ -15,8 +15,7 @@ Files promises manage all aspects of files. Presence, absence, file content, per bundle agent __main__ { files: - "/tmp/hello" - content => "Hello, CFEngine"; + "/tmp/hello" content => "Hello, CFEngine"; } ``` @@ -51,8 +50,7 @@ bundle agent __main__ { files: ubuntu_18|ubuntu_20:: - "/tmp/hello" - create => "true"; + "/tmp/hello" create => "true"; } ``` @@ -475,16 +473,12 @@ aces = { ```cf3 body acl template { -acl_method => "overwrite"; -acl_type => "posix"; -acl_default => "access"; - -aces => { - "user:*:r(wwx),-r:allow", - "group:*:+rw:allow", - "mask:x:allow", - "all:r" - }; + acl_method => "overwrite"; + acl_type => "posix"; + acl_default => "access"; + aces => { + "user:*:r(wwx),-r:allow", "group:*:+rw:allow", "mask:x:allow", "all:r" + }; } ``` @@ -519,18 +513,11 @@ clear ```cf3 body acl template - { -acl_method => "overwrite"; -acl_type => "posix"; -acl_default => "access"; - -aces => { - "user:*:rwx:allow", - "group:*:+rw:allow", - "mask:rx:allow", - "all:r" - }; + acl_method => "overwrite"; + acl_type => "posix"; + acl_default => "access"; + aces => { "user:*:rwx:allow", "group:*:+rw:allow", "mask:rx:allow", "all:r" }; } ``` @@ -574,11 +561,10 @@ overwrite ```cf3 body acl template - { -acl_method => "overwrite"; -acl_type => "posix"; -aces => { "user:*:rw:allow", "group:*:+r:allow", "all:"}; + acl_method => "overwrite"; + acl_type => "posix"; + aces => { "user:*:rw:allow", "group:*:+r:allow", "all:" }; } ``` @@ -610,10 +596,9 @@ ntfs ```cf3 body acl template - { -acl_type => "ntfs"; -aces => { "user:Administrator:rwx(po)", "user:Auditor:r(o)"}; + acl_type => "ntfs"; + aces => { "user:Administrator:rwx(po)", "user:Auditor:r(o)" }; } ``` @@ -641,7 +626,7 @@ that do not have a clear inheritance policy. ```cf3 body acl template { -specify_default_aces => { "all:r" }; + specify_default_aces => { "all:r" }; } ``` @@ -676,7 +661,7 @@ best ```cf3 body changes example { -hash => "md5"; + hash => "md5"; } ``` @@ -702,7 +687,7 @@ none ```cf3 body changes example { -report_changes => "content"; + report_changes => "content"; } ``` @@ -722,7 +707,7 @@ applies to addition and removal too. ```cf3 body changes example { -update_hashes => "true"; + update_hashes => "true"; } ``` @@ -755,7 +740,7 @@ Diffs for binary files are not generated. Files are considered binary files if [ ```cf3 body changes example { -report_diffs => "true"; + report_diffs => "true"; } ``` @@ -784,7 +769,7 @@ activation. ```cf3 body copy_from example { -source => "/path/to/source"; + source => "/path/to/source"; } ``` @@ -801,8 +786,9 @@ source => "/path/to/source"; ```cf3 body copy_from example { -servers => { "primary.example.org", "secondary.example.org", - "tertiary.other.domain" }; + servers => { + "primary.example.org", "secondary.example.org", "tertiary.other.domain" + }; } ``` @@ -823,11 +809,11 @@ itself; in other words, a single destination directory. So `src/subdir/file` wil **Example:** ```cf3 -body copy_from mycopy(from,server) +body copy_from mycopy(from, server) { -source => "$(from)"; -servers => { "$(server)" }; -collapse_destination_dir => "true"; + source => "$(from)"; + servers => { "$(server)" }; + collapse_destination_dir => "true"; } ``` @@ -895,7 +881,7 @@ used. ```cf3 body copy_from example { -compare => "digest"; + compare => "digest"; } ``` @@ -948,8 +934,8 @@ for the client and server hosts. ```cf3 body copy_from example { -servers => { "remote-host.example.org" }; -encrypt => "true"; + servers => { "remote-host.example.org" }; + encrypt => "true"; } ``` @@ -974,7 +960,7 @@ objects and subdirectories within this root (false). ```cf3 body copy_from example { -check_root => "true"; + check_root => "true"; } ``` @@ -996,7 +982,7 @@ feature is not available there. ```cf3 body copy_from example { -copylink_patterns => { "special_node1", "other_node.*" }; + copylink_patterns => { "special_node1", "other_node.*" }; } ``` @@ -1019,7 +1005,7 @@ comma separated numbers. ```cf3 body copy_from example { -copy_size => irange("0","50000"); + copy_size => irange("0", "50000"); } ``` @@ -1044,7 +1030,7 @@ MacOSX ```cf3 body copy_from example { -findertype => "MacOSX"; + findertype => "MacOSX"; } ``` @@ -1065,8 +1051,8 @@ absolute path. Windows only supports hard links. ```cf3 body copy_from mycopy(from) { -source => "$(from)"; -linkcopy_patterns => { ".*" }; + source => "$(from)"; + linkcopy_patterns => { ".*" }; } ``` @@ -1105,8 +1091,8 @@ absolute ```cf3 body copy_from example { -link_type => "symlink"; -source => "/tmp/source"; + link_type => "symlink"; + source => "/tmp/source"; } ``` @@ -1158,7 +1144,7 @@ by network disruptions. ```cf3 body copy_from example { -force_update => "true"; + force_update => "true"; } ``` @@ -1177,7 +1163,7 @@ IPv6 should be harmless to most users unless you have a partially or mis-configu ```cf3 body copy_from example { -force_ipv4 => "true"; + force_ipv4 => "true"; } ``` @@ -1199,7 +1185,7 @@ change in the future. ```cf3 body copy_from example { -portnumber => "5308"; + portnumber => "5308"; } ``` @@ -1223,7 +1209,7 @@ security contexts. For remote copies, only Unix mode is preserved. ```cf3 body copy_from example { -preserve => "true"; + preserve => "true"; } ``` @@ -1267,7 +1253,7 @@ is set to true. ```cf3 body copy_from example { -purge => "true"; + purge => "true"; } ``` @@ -1286,7 +1272,7 @@ modification times on the promiser files. ```cf3 body copy_from example { -stealth => "true"; + stealth => "true"; } ``` @@ -1306,7 +1292,7 @@ timeout, in seconds. ```cf3 body copy_from example { -timeout => "10"; + timeout => "10"; } ``` @@ -1346,7 +1332,7 @@ revoked by a system administrator. Keys are stored in `WORKDIR/ppkeys`. ```cf3 body copy_from example { -trustkey => "true"; + trustkey => "true"; } ``` @@ -1366,7 +1352,7 @@ off. ```cf3 body copy_from example { -type_check => "false"; + type_check => "false"; } ``` @@ -1387,7 +1373,7 @@ recommended for large file transfers. ```cf3 body copy_from example { -verify => "true"; + verify => "true"; } ``` @@ -1486,7 +1472,7 @@ keep ```cf3 body delete example { -dirlinks => "keep"; + dirlinks => "keep"; } ``` @@ -1508,7 +1494,7 @@ recursive deletion ```cf3 body delete example { -rmdirs => "true"; + rmdirs => "true"; } ``` @@ -1549,7 +1535,7 @@ Note that the value inf may be used for an unlimited value. ```cf3 body depth_search example { -depth => "inf"; + depth => "inf"; } ``` @@ -1570,8 +1556,8 @@ a file system. ```cf3 body depth_search example { - # no dot directories - exclude_dirs => { "\..*" }; + # no dot directories + exclude_dirs => { "\..*" }; } ``` @@ -1610,7 +1596,7 @@ This is the complement of `exclude_dirs`. ```cf3 body depth_search example { -include_dirs => { "subdir1", "subdir2", "pattern.*" }; + include_dirs => { "subdir1", "subdir2", "pattern.*" }; } ``` @@ -1630,7 +1616,7 @@ exist should be deleted; or kept if set to false. ```cf3 body depth_search example { -rmdeadlinks => "true"; + rmdeadlinks => "true"; } ``` @@ -1651,7 +1637,7 @@ dangerous assumption and links are not traversed. ```cf3 body depth_search example { -traverse_links => "true"; + traverse_links => "true"; } ``` @@ -1701,7 +1687,7 @@ A value of `true` (the default behavior) will result in the agent retaining the previous version of the file suffixed with `.cf-before-edit`. ```cf3 -body edit_defaults backup( edit_backup ) +body edit_defaults backup(edit_backup) { edit_backup => "$(edit_backup)"; } @@ -1709,15 +1695,15 @@ body edit_defaults backup( edit_backup ) bundle agent main { files: - "/tmp/example_edit_backup_true" - create => "true"; + "/tmp/example_edit_backup_true" create => "true"; "/tmp/example_edit_backup_true" edit_line => insert_lines("Hello World"), edit_defaults => backup("true"); vars: - "example_files" slist => sort(lsdir( "/tmp/", "example_edit_backup_true.*", false), lex); + "example_files" + slist => sort(lsdir("/tmp/", "example_edit_backup_true.*", false), lex); reports: "$(example_files)"; @@ -1737,7 +1723,7 @@ epoch and the canonified form of the date when the file was changed followed by `_1511292441_Tue_Nov_21_13_27_22_2017.cf-before-edit`. ```cf3 -body edit_defaults backup( edit_backup ) +body edit_defaults backup(edit_backup) { edit_backup => "$(edit_backup)"; } @@ -1745,15 +1731,15 @@ body edit_defaults backup( edit_backup ) bundle agent main { files: - "/tmp/example_edit_backup_timestamp" - create => "true"; + "/tmp/example_edit_backup_timestamp" create => "true"; "/tmp/example_edit_backup_timestamp" edit_line => insert_lines("Hello World"), edit_defaults => backup("timestamp"); vars: - "example_files" slist => lsdir( "/tmp/", "example_edit_backup_timestamp.*", false); + "example_files" + slist => lsdir("/tmp/", "example_edit_backup_timestamp.*", false); reports: "$(example_files)"; @@ -1775,7 +1761,7 @@ of the file. The number of rotations is managed by the `rotate` attribute in `edit_defaults`. ```cf3 -body edit_defaults backup( edit_backup ) +body edit_defaults backup(edit_backup) { edit_backup => "$(edit_backup)"; rotate => "2"; @@ -1784,8 +1770,7 @@ body edit_defaults backup( edit_backup ) bundle agent main { files: - "/tmp/example_edit_backup_rotate" - create => "true"; + "/tmp/example_edit_backup_rotate" create => "true"; "/tmp/example_edit_backup_rotate" edit_line => insert_lines("Hello World"), @@ -1797,7 +1782,8 @@ bundle agent main edit_defaults => backup("rotate"); vars: - "example_files" slist => lsdir( "/tmp/", "example_edit_backup_rotate.*", false); + "example_files" + slist => lsdir("/tmp/", "example_edit_backup_rotate.*", false); reports: "$(example_files)"; @@ -1835,7 +1821,7 @@ recipe allows an ordered procedure to be convergent. ```cf3 body edit_defaults example { -empty_file_before_editing => "true"; + empty_file_before_editing => "true"; } ``` @@ -1851,15 +1837,15 @@ classes of its parent ```cf3 bundle agent name { -methods: - - "group name" usebundle => my_method, - inherit => "true"; + methods: + "group name" + usebundle => my_method, + inherit => "true"; } body edit_defaults example { -inherit => "true"; + inherit => "true"; } ``` @@ -1894,7 +1880,7 @@ determined by the global control body setting whose default value is ```cf3 body edit_defaults example { -max_file_size => "50K"; + max_file_size => "50K"; } ``` @@ -1964,8 +1950,8 @@ deleted (that is, it "falls off the end" of the rotation). ```cf3 body edit_defaults example { -edit_backup => "rotate"; -rotate => "4"; + edit_backup => "rotate"; + rotate => "4"; } ``` @@ -1988,21 +1974,18 @@ rotate => "4"; ```cf3 bundle agent example { - files: - - !use_mustache:: - - "/etc/motd" - create => "true", - edit_template => "$(this.promise_dirname)/templates/motd.tpl", - template_method => "cfengine"; - - use_mustache:: + files: + !use_mustache:: + "/etc/motd" + create => "true", + edit_template => "$(this.promise_dirname)/templates/motd.tpl", + template_method => "cfengine"; - "/etc/motd" - create => "true", - edit_template => "$(this.promise_dirname)/templates/motd.mustache", - template_method => "mustache"; + use_mustache:: + "/etc/motd" + create => "true", + edit_template => "$(this.promise_dirname)/templates/motd.mustache", + template_method => "mustache"; } ``` @@ -2057,8 +2040,8 @@ This pattern matches only the node name of the file, not its path. ```cf3 body file_select example { -leaf_name => { "S[0-9]+[a-zA-Z]+", "K[0-9]+[a-zA-Z]+" }; -file_result => "leaf_name"; + leaf_name => { "S[0-9]+[a-zA-Z]+", "K[0-9]+[a-zA-Z]+" }; + file_result => "leaf_name"; } ``` @@ -2078,10 +2061,9 @@ of appropriate regular expressions. ```cf3 body file_select example { -leaf_name => { "prog.pid", "prog.log" }; -path_name => { "/etc/.*", "/var/run/.*" }; - -file_result => "leaf_name.path_name" + leaf_name => { "prog.pid", "prog.log" }; + path_name => { "/etc/.*", "/var/run/.*" }; + file_result => "leaf_name.path_name" } ``` @@ -2102,25 +2084,22 @@ implies `u` AND `g`. ```cf3 bundle agent testbundle { -files: - - "/home/mark/tmp/testcopy" - - file_select => by_modes, - transformer => "/bin/echo DETECTED $(this.promiser)", - depth_search => recurse("inf"); - + files: + "/home/mark/tmp/testcopy" + file_select => by_modes, + transformer => "/bin/echo DETECTED $(this.promiser)", + depth_search => recurse("inf"); } body file_select by_modes { -search_mode => { "711" , "666" }; -file_result => "mode"; + search_mode => { "711", "666" }; + file_result => "mode"; } body depth_search recurse(d) { -depth => "$(d)"; + depth => "$(d)"; } ``` @@ -2137,8 +2116,8 @@ depth => "$(d)"; ```cf3 body file_select example { -search_size => irange("0","20k"); -file_result => "size"; + search_size => irange("0", "20k"); + file_result => "size"; } ``` @@ -2159,8 +2138,8 @@ userid. ```cf3 body file_select example { -search_owners => { "mark", "jeang", "student_.*" }; -file_result => "owner"; + search_owners => { "mark", "jeang", "student_.*" }; + file_result => "owner"; } ``` @@ -2183,8 +2162,8 @@ A list of [anchored][anchored] regular expressions, any of which must match the ```cf3 body file_select example { -search_groups => { "users", "special_.*" }; -file_result => "group"; + search_groups => { "users", "special_.*" }; + file_result => "group"; } ``` @@ -2208,8 +2187,8 @@ CFEngine). See the manual page for `chflags` for more details. ```cf3 body file_select xyz { -search_bsdflags => "archived|dump"; -file_result => "bsdflags"; + search_bsdflags => "archived|dump"; + file_result => "bsdflags"; } ``` @@ -2230,8 +2209,8 @@ time. ```cf3 body files_select example { -ctime => irange(ago(1,0,0,0,0,0),now); -file_result => "ctime"; + ctime => irange(ago(1, 0, 0, 0, 0, 0), now); + file_result => "ctime"; } ``` @@ -2253,9 +2232,9 @@ not other attributes, such as permissions. ```cf3 body files_select example { - # Files modified more than one year ago (i.e., not in mtime range) - mtime => irange(ago(1,0,0,0,0,0),now); - file_result => "!mtime"; + # Files modified more than one year ago (i.e., not in mtime range) + mtime => irange(ago(1, 0, 0, 0, 0, 0), now); + file_result => "!mtime"; } ``` @@ -2277,16 +2256,16 @@ A range of times during which a file was accessed can be specified in a ```cf3 body file_select used_recently { - # files accessed within the last hour - atime => irange(ago(0,0,0,1,0,0),now); - file_result => "atime"; + # files accessed within the last hour + atime => irange(ago(0, 0, 0, 1, 0, 0), now); + file_result => "atime"; } body file_select not_used_much { - # files not accessed since 00:00 1st Jan 2000 (in the local timezone) - atime => irange(on(2000,1,1,0,0,0),now); - file_result => "!atime"; + # files not accessed since 00:00 1st Jan 2000 (in the local timezone) + atime => irange(on(2000, 1, 1, 0, 0, 0), now); + file_result => "!atime"; } ``` @@ -2311,9 +2290,9 @@ output must be matched. ```cf3 body file_select example { -exec_regex => "SPECIAL_LINE: .*"; -exec_program => "/path/test_program $(this.promiser)"; -file_result => "exec_program.exec_regex"; + exec_regex => "SPECIAL_LINE: .*"; + exec_program => "/path/test_program $(this.promiser)"; + file_result => "exec_program.exec_regex"; } ``` @@ -2335,8 +2314,8 @@ matched. ```cf3 body file_select example { -exec_program => "/path/test_program $(this.promiser)"; -file_result => "exec_program"; + exec_program => "/path/test_program $(this.promiser)"; + file_result => "exec_program"; } ``` @@ -2369,9 +2348,8 @@ block ```cf3 body file_select filter { -file_types => { "plain","symlink" }; - -file_result => "file_types"; + file_types => { "plain", "symlink" }; + file_result => "file_types"; } ``` @@ -2391,7 +2369,7 @@ expressions, the file will be selected. ```cf3 body file_select example { -issymlinkto => { "/etc/[^/]*", "/etc/init\.d/[a-z0-9]*" }; + issymlinkto => { "/etc/[^/]*", "/etc/init\.d/[a-z0-9]*" }; } ``` @@ -2419,17 +2397,16 @@ components. ```cf3 body file_select year_or_less { -mtime => irange(ago(1,0,0,0,0,0),now); -file_result => "mtime"; + mtime => irange(ago(1, 0, 0, 0, 0, 0), now); + file_result => "mtime"; } body file_select my_pdf_files_morethan1dayold { -mtime => irange(ago(0,0,1,0,0,0),now); -leaf_name => { ".*\.pdf" , ".*\.fdf" }; -search_owners => { "mark" }; - -file_result => "owner.leaf_name.!mtime"; + mtime => irange(ago(0, 0, 1, 0, 0, 0), now); + leaf_name => { ".*\.pdf", ".*\.fdf" }; + search_owners => { "mark" }; + file_result => "owner.leaf_name.!mtime"; } ``` @@ -2483,7 +2460,7 @@ updated by modification time. ```cf3 body link_from example { -copy_patterns => { "special_node1", "/path/special_node2" }; + copy_patterns => { "special_node1", "/path/special_node2" }; } ``` @@ -2543,8 +2520,8 @@ absolute ```cf3 body link_from example { -link_type => "symlink"; -source => "/tmp/source"; + link_type => "symlink"; + source => "/tmp/source"; } ``` @@ -2570,7 +2547,7 @@ For remote copies this refers to the file name on the remote server. ```cf3 body link_from example { -source => "/path/to/source"; + source => "/path/to/source"; } ``` @@ -2601,7 +2578,7 @@ if_no_such_file ```cf3 body link_from example { -when_linking_children => "if_no_such_file"; + when_linking_children => "if_no_such_file"; } ``` @@ -2631,7 +2608,7 @@ nop ```cf3 body link_from example { -when_no_source => "force"; + when_no_source => "force"; } ``` @@ -2810,8 +2787,9 @@ not supported and instead log a verbose message (to avoid too much noise). ```cf3 body perms example { -bsdflags => { "uappnd","uchg","uunlnk","nodump", - "opaque","sappnd","schg","sunlnk" }; + bsdflags => { + "uappnd", "uchg", "uunlnk", "nodump", "opaque", "sappnd", "schg", "sunlnk" + }; } ``` @@ -2839,7 +2817,7 @@ group. ```cf3 body perms example { -groups => { "users", "administrators" }; + groups => { "users", "administrators" }; } ``` @@ -2862,7 +2840,7 @@ The mode string may be symbolic or numerical, like `chmod`. ```cf3 body perms example { -mode => "a+rx,o+w"; + mode => "a+rx,o+w"; } ``` @@ -2890,7 +2868,7 @@ registered user. ```cf3 body perms example { -owners => { "mark", "wwwrun", "jeang" }; + owners => { "mark", "wwwrun", "jeang" }; } ``` @@ -2948,8 +2926,8 @@ unreadable. ```cf3 body rename example { -disable => "true"; -disable_suffix => ".nuked"; + disable => "true"; + disable_suffix => ".nuked"; } ``` @@ -2969,7 +2947,7 @@ remove the executable flag. ```cf3 body rename example { -disable_mode => "0600"; + disable_mode => "0600"; } ``` @@ -2990,8 +2968,8 @@ To disable files in a particular manner, use this string suffix. ```cf3 body rename example { -disable => "true"; -disable_suffix => ".nuked"; + disable => "true"; + disable_suffix => ".nuked"; } ``` @@ -3008,7 +2986,7 @@ disable_suffix => ".nuked"; ```cf3 body rename example(s) { -newname => "$(s)"; + newname => "$(s)"; } ``` @@ -3039,7 +3017,7 @@ files plus the one "main" file. ```cf3 body rename example { -rotate => "4"; + rotate => "4"; } ``` diff --git a/content/reference/promise-types/files/edit_line/_index.markdown b/content/reference/promise-types/files/edit_line/_index.markdown index f25c86864..923b196b0 100644 --- a/content/reference/promise-types/files/edit_line/_index.markdown +++ b/content/reference/promise-types/files/edit_line/_index.markdown @@ -24,43 +24,39 @@ A typical file editing stanza has the elements in the following example: body common control { version => "1.2.3"; - bundlesequence => { "outerbundle" }; + bundlesequence => { "outerbundle" }; } bundle agent outerbundle { -files: - - "/home/mark/tmp/cf3_test" - create => "true", # Like autocreate in cf2 - edit_line => inner_bundle; + files: + "/home/mark/tmp/cf3_test" + create => "true", # Like autocreate in cf2 + edit_line => inner_bundle; } bundle edit_line inner_bundle { vars: - "who" string => "SysAdmin John"; # private variable in bundle - insert_lines: "/* This file is maintained by CFEngine (see $(who) for details) */", - location => first_line; + location => first_line; replace_patterns: - # replace shell comments with C comments - - "#(.*)" + # replace shell comments with C comments + "#(.*)" replace_with => C_comment, - select_region => MySection("New section"); + select_region => MySection("New section"); reports: - "This is file $(edit.filename)"; + "This is file $(edit.filename)"; } body replace_with C_comment { replace_value => "/* $(match.1) */"; # backreference - occurrences => "all"; # first, last all + occurrences => "all"; # first, last all } body select_region MySection(x) @@ -143,20 +139,18 @@ changes were. ```cf3 bundle agent example { -files: - - "/home/mark/tmp" -> "Security team" - - changes => lay_a_tripwire, - depth_search => recurse("inf"), - action => background; + files: + "/home/mark/tmp" -> "Security team" + changes => lay_a_tripwire, + depth_search => recurse("inf"), + action => background; } body changes lay_a_tripwire { - hash => "md5"; + hash => "md5"; report_changes => "content"; - update => "yes"; + update => "yes"; } ``` @@ -204,11 +198,11 @@ look at the following code example: ```cf3 bundle agent init { -vars: + vars: "states" slist => { "actual", "expected" }; - "actual" string => -"header + "actual" + string => "header header BEGIN One potato @@ -219,8 +213,8 @@ END trailer trailer"; - "expected" string => -"header + "expected" + string => "header header One potato Two potato @@ -228,7 +222,7 @@ Four trailer trailer"; -files: + files: "testfile.$(states)" create => "true", edit_line => init_insert("$(init.$(states))"), @@ -237,7 +231,7 @@ files: bundle edit_line init_insert(str) { -insert_lines: + insert_lines: "$(str)"; } @@ -247,22 +241,19 @@ body edit_defaults init_empty } ####################################################### - bundle agent test { -vars: + vars: "tstr" slist => { "BEGIN", " Three potatoe", "END" }; -files: - "testfile.actual" - edit_line => test_delete("$(test.tstr)"); + files: + "testfile.actual" edit_line => test_delete("$(test.tstr)"); } bundle edit_line test_delete(str) { -delete_lines: - "$(str)" - select_region => test_select; + delete_lines: + "$(str)" select_region => test_select; } body select_region test_select @@ -315,9 +306,9 @@ editing. Setting this option to true makes it included. ```cf3 body select_region BracketSection(x) { -select_start => "$(x) \{"; -select_end => "}"; -include_end_delimiter => "true"; + select_start => "$(x) \{"; + select_end => "}"; + include_end_delimiter => "true"; } ``` @@ -407,8 +398,8 @@ unaffected by any `delete_lines` promises. See the next section on ```cf3 body select_region example(x) { -select_start => "\[$(x)\]"; -select_end => "\[.*\]"; + select_start => "\[$(x)\]"; + select_end => "\[.*\]"; } ``` @@ -440,9 +431,9 @@ the file no matter what the value of `select_end_match_eof` is set to. ```cf3 body select_region example(x) { -select_start => "\[$(x)\]"; -select_end => "\[.*\]"; -select_end_match_eof => "true"; + select_start => "\[$(x)\]"; + select_end => "\[.*\]"; + select_end_match_eof => "true"; } ``` diff --git a/content/reference/promise-types/files/edit_line/delete_lines.markdown b/content/reference/promise-types/files/edit_line/delete_lines.markdown index 3460bc768..4514c1a05 100644 --- a/content/reference/promise-types/files/edit_line/delete_lines.markdown +++ b/content/reference/promise-types/files/edit_line/delete_lines.markdown @@ -14,10 +14,8 @@ with `not_matching`). ```cf3 bundle edit_line example { -delete_lines: - - "olduser:.*"; - + delete_lines: + "olduser:.*"; } ``` @@ -64,14 +62,13 @@ selection). ```cf3 bundle edit_line alpha { -delete_lines: - ".*alpha.*" - delete_select => starters; + delete_lines: + ".*alpha.*" delete_select => starters; } body delete_select starters { - delete_if_startwith_from_list => { "begin", "start", "init" }; + delete_if_startwith_from_list => { "begin", "start", "init" }; } ``` @@ -109,7 +106,7 @@ selection. ```cf3 body delete_select example(s) { -delete_if_not_startwith_from_list => { @(s) }; + delete_if_not_startwith_from_list => { @(s) }; } ``` @@ -129,7 +126,7 @@ initial selection, and the match determination is made only on promised lines. ```cf3 body delete_select example(s) { -delete_if_match_from_list => { @(s) }; + delete_if_match_from_list => { @(s) }; } ``` @@ -149,7 +146,7 @@ initial selection, and the match determination is made only on promised lines. ```cf3 body delete_select example(s) { -delete_if_not_match_from_list => { @(s) }; + delete_if_not_match_from_list => { @(s) }; } ``` @@ -170,7 +167,7 @@ initial selection, and the match determination is made only on promised lines. ```cf3 body delete_select example(s) { -delete_if_contains_from_list => { @(s) }; + delete_if_contains_from_list => { @(s) }; } ``` @@ -191,7 +188,7 @@ promised lines. ```cf3 body delete_select discard(s) { -delete_if_not_contains_from_list => { "substring1", "substring2" }; + delete_if_not_contains_from_list => { "substring1", "substring2" }; } ``` diff --git a/content/reference/promise-types/files/edit_line/field_edits.markdown b/content/reference/promise-types/files/edit_line/field_edits.markdown index 607da82d9..2503ec6ae 100644 --- a/content/reference/promise-types/files/edit_line/field_edits.markdown +++ b/content/reference/promise-types/files/edit_line/field_edits.markdown @@ -24,20 +24,16 @@ removing data from addressable fields. bundle agent example { vars: - - "userset" slist => { "one-x", "two-x", "three-x" }; + "userset" slist => { "one-x", "two-x", "three-x" }; files: - "/tmp/passwd" - - create => "true", - edit_line => set_user_param("mark","6","/set/this/shell"); + create => "true", + edit_line => set_user_param("mark", "6", "/set/this/shell"); "/tmp/group" - - create => "true", - edit_line => append_user_param("root","4","@(userset)"); + create => "true", + edit_line => append_user_param("root", "4", "@(userset)"); } ``` @@ -45,30 +41,23 @@ The promise in this example assumes a parameterizable model for editing the fields of such files. ```cf3 -bundle edit_line set_user_param(user,field,val) +bundle edit_line set_user_param(user, field, val) { field_edits: - - "$(user):.*" - + "$(user):.*" # Set field of the file to parameter - - edit_field => col(":","$(field)","$(val)","set"); + edit_field => col(":", "$(field)", "$(val)", "set"); } -bundle edit_line append_user_param(user,field,allusers) +bundle edit_line append_user_param(user, field, allusers) { vars: - "val" slist => { @(allusers) }; field_edits: - - "$(user):.*" - + "$(user):.*" # Set field of the file to parameter - - edit_field => col(":","$(field)","$(val)","alphanum"); + edit_field => col(":", "$(field)", "$(val)", "alphanum"); } ``` @@ -76,12 +65,12 @@ First you match the line with a regular expression. The regular expression must match the entire line; that is, it is [anchored][anchored]. ```cf3 -body edit_field col(split,col,newval,method) +body edit_field col(split, col, newval, method) { field_separator => "$(split)"; - select_field => "$(col)"; - value_separator => ","; - field_value => "$(newval)"; + select_field => "$(col)"; + value_separator => ","; + field_value => "$(newval)"; field_operation => "$(method)"; extend_fields => "true"; } @@ -104,12 +93,12 @@ ordering the items within them. ```cf3 body edit_field col(split, col, newval, method) { - field_separator => "$(split)"; - select_field => "$(col)"; - value_separator => ","; - field_value => "$(newval)"; - field_operation => "$(method)"; - extend_fields => "true"; + field_separator => "$(split)"; + select_field => "$(col)"; + value_separator => ","; + field_value => "$(newval)"; + field_operation => "$(method)"; + extend_fields => "true"; allow_blank_fields => "true"; start_fields_from_zero => "true"; } @@ -135,7 +124,7 @@ number of field separators. ```cf3 body edit_field example { -allow_blank_fields => "true"; + allow_blank_fields => "true"; } ``` @@ -159,7 +148,7 @@ If in doubt, set this to true. ```cf3 body edit_field example { -extend_fields => "true"; + extend_fields => "true"; } ``` @@ -204,7 +193,7 @@ Delete the specified value (if present) in the specified field/column. ```cf3 body edit_field example { -field_operation => "append"; + field_operation => "append"; } ``` @@ -227,7 +216,7 @@ edit all kinds of line-based text files. ```cf3 body edit_field example { -field_separator => ":"; + field_separator => ":"; } ``` @@ -247,7 +236,7 @@ fixed list. ```cf3 body edit_field example(s) { -field_value => "$(s)"; + field_value => "$(s)"; } ``` @@ -264,7 +253,7 @@ field_value => "$(s)"; ```cf3 body field_edits example { -select_field => "5"; + select_field => "5"; } ``` @@ -299,7 +288,7 @@ the lists of users in these fields are separated by a comma (','). ```cf3 body field_edit example { -value_separator => ","; + value_separator => ","; } ``` diff --git a/content/reference/promise-types/files/edit_line/insert_lines.markdown b/content/reference/promise-types/files/edit_line/insert_lines.markdown index ba7a5b082..447759527 100644 --- a/content/reference/promise-types/files/edit_line/insert_lines.markdown +++ b/content/reference/promise-types/files/edit_line/insert_lines.markdown @@ -30,10 +30,9 @@ incorrect: ```cf3 bundle edit_line x { -insert_lines: - - "line one" location => myloc; - "line two" location => myloc; + insert_lines: + "line one" location => myloc; + "line two" location => myloc; } body location myloc @@ -53,9 +52,8 @@ should be used: ```cf3 bundle edit_line x { -insert_lines: - - "line one$(const.n)line two" location => myloc; + insert_lines: + "line one$(const.n)line two" location => myloc; } ``` @@ -64,11 +62,9 @@ Or: ```cf3 bundle edit_line x { -insert_lines: - - "line one -line two" - location => myloc; + insert_lines: + "line one +line two" location => myloc; } ``` @@ -100,21 +96,18 @@ $(mon.www_in) ```cf3 bundle agent testbundle { -files: - - "/home/mark/tmp/file_based_on_template" - - create => "true", - edit_line => expand_me_from("/tmp/source_template"); + files: + "/home/mark/tmp/file_based_on_template" + create => "true", + edit_line => expand_me_from("/tmp/source_template"); } bundle edit_line expand_me_from(template) { -insert_lines: - "$(template)" - - insert_type => "file", - expand_scalars => "true"; + insert_lines: + "$(template)" + insert_type => "file", + expand_scalars => "true"; } ``` @@ -171,22 +164,19 @@ This was added in CFEngine 3.5.x. ```cf3 bundle edit_line lynryd_skynyrd { - vars: + vars: "keepers" slist => { "Won't you give me", "Gimme three steps" }; - insert_lines: - - "And you'll never see me no more" - insert_type => "literal"; # the default - - "/song/lyrics" - insert_type => "file", # read selected lines from /song/lyrics - insert_select => keep("@{keepers}"); + insert_lines: + "And you'll never see me no more" insert_type => "literal"; # the default + "/song/lyrics" + insert_type => "file", # read selected lines from /song/lyrics + insert_select => keep("@{keepers}"); } body insert_select keep(s) { -insert_if_startwith_from_list => { "@(s)" }; + insert_if_startwith_from_list => { "@(s)" }; } ``` @@ -228,7 +218,7 @@ location in the primary file. ```cf3 body insert_select example { -insert_if_startwith_from_list => { "find_me_1", "find_me_2" }; + insert_if_startwith_from_list => { "find_me_1", "find_me_2" }; } ``` @@ -252,7 +242,7 @@ file being edited. ```cf3 body insert_select example { -insert_if_not_startwith_from_list => { "find_me_1", "find_me_2" }; + insert_if_not_startwith_from_list => { "find_me_1", "find_me_2" }; } ``` @@ -278,7 +268,7 @@ or the promiser is a multi-line block. ```cf3 body insert_select example { -insert_if_match_from_list => { ".*find_.*_1.*", ".*find_.*_2.*" }; + insert_if_match_from_list => { ".*find_.*_1.*", ".*find_.*_2.*" }; } ``` @@ -302,7 +292,7 @@ edited. ```cf3 body insert_select example { -insert_if_not_match_from_list => { ".*find_.*_1.*", ".*find_.*_2.*" }; + insert_if_not_match_from_list => { ".*find_.*_1.*", ".*find_.*_2.*" }; } ``` @@ -328,7 +318,7 @@ location in the primary file. ```cf3 body insert_select example { -insert_if_contains_from_list => { "find_me_1", "find_me_2" }; + insert_if_contains_from_list => { "find_me_1", "find_me_2" }; } ``` @@ -352,7 +342,7 @@ found in the secondary file, it is inserted into the file being edited. ```cf3 body insert_select example { -insert_if_not_contains_from_list => { "find_me_1", "find_me_2" }; + insert_if_not_contains_from_list => { "find_me_1", "find_me_2" }; } ``` @@ -385,7 +375,7 @@ after ```cf3 body location append { -before_after => "before"; + before_after => "before"; } ``` @@ -415,7 +405,7 @@ last ```cf3 body location example { -first_last => "last"; + first_last => "last"; } ``` @@ -434,16 +424,15 @@ that is, it is [anchored][anchored]. ```cf3 # Editing - body location example { -select_line_matching => "Expression match.* whole line"; + select_line_matching => "Expression match.* whole line"; } # Measurement promises body match_value example { -select_line_matching => "Expression match.* whole line"; + select_line_matching => "Expression match.* whole line"; } ``` @@ -499,10 +488,8 @@ exact_match ```cf3 bundle edit_line insert_service(service, filename) { -insert_lines: - - "$(service).* $(filename)" - + insert_lines: + "$(service).* $(filename)" whitespace_policy => { "ignore_trailing", "ignore_embedded" }; } ``` diff --git a/content/reference/promise-types/files/edit_line/replace_patterns.markdown b/content/reference/promise-types/files/edit_line/replace_patterns.markdown index 73e3c2945..1f36ac550 100644 --- a/content/reference/promise-types/files/edit_line/replace_patterns.markdown +++ b/content/reference/promise-types/files/edit_line/replace_patterns.markdown @@ -24,14 +24,13 @@ match a line fragment, that is, it is [unanchored][unanchored]. bundle edit_line upgrade_cfexecd { replace_patterns: - "cfexecd" replace_with => value("cf-execd"); } -body replace_with value(x) # defined in cfengine_stdlib.cf +body replace_with value(x) # defined in cfengine_stdlib.cf { -replace_value => "$(x)"; -occurrences => "all"; + replace_value => "$(x)"; + occurrences => "all"; } ``` @@ -79,7 +78,7 @@ Replace only the first occurrence. Note: this is non-convergent. ```cf3 body replace_with example { -occurrences => "first"; # Warning! Using "first" is non-convergent + occurrences => "first"; # Warning! Using "first" is non-convergent } ``` @@ -96,7 +95,7 @@ occurrences => "first"; # Warning! Using "first" is non-convergent ```cf3 body replace_with example(s) { -replace_value => "$(s)"; + replace_value => "$(s)"; } ``` diff --git a/content/reference/promise-types/files/edit_xml/build_xpath.markdown b/content/reference/promise-types/files/edit_xml/build_xpath.markdown index 8504c8746..1f9ac2506 100644 --- a/content/reference/promise-types/files/edit_xml/build_xpath.markdown +++ b/content/reference/promise-types/files/edit_xml/build_xpath.markdown @@ -17,8 +17,8 @@ referred to is a literal string representation of an XPath. ```cf3 bundle edit_xml example { -build_xpath: - "/Server/Service/Engine/Host"; + build_xpath: + "/Server/Service/Engine/Host"; } ``` diff --git a/content/reference/promise-types/files/edit_xml/delete_attribute.markdown b/content/reference/promise-types/files/edit_xml/delete_attribute.markdown index 35bd0eee4..aae0f57f7 100644 --- a/content/reference/promise-types/files/edit_xml/delete_attribute.markdown +++ b/content/reference/promise-types/files/edit_xml/delete_attribute.markdown @@ -15,9 +15,8 @@ deleted. ```cf3 bundle edit_xml example { -delete_attribute: - "attribute name" - select_xpath => "/Server/Service/Engine/Host"; + delete_attribute: + "attribute name" select_xpath => "/Server/Service/Engine/Host"; } ``` diff --git a/content/reference/promise-types/files/edit_xml/delete_text.markdown b/content/reference/promise-types/files/edit_xml/delete_text.markdown index 499e37c0c..b5711a0b2 100644 --- a/content/reference/promise-types/files/edit_xml/delete_text.markdown +++ b/content/reference/promise-types/files/edit_xml/delete_text.markdown @@ -14,10 +14,9 @@ body-attributes. The promise object referred to is a literal string of text. ```cf3 bundle edit_xml example { -delete_text: - - "text content to match, as a substring, of text to be deleted from specified node" - select_xpath => "/Server/Service/Engine/Host/Alias"; + delete_text: + "text content to match, as a substring, of text to be deleted from specified node" + select_xpath => "/Server/Service/Engine/Host/Alias"; } ``` diff --git a/content/reference/promise-types/files/edit_xml/delete_tree.markdown b/content/reference/promise-types/files/edit_xml/delete_tree.markdown index 183b66413..108643674 100644 --- a/content/reference/promise-types/files/edit_xml/delete_tree.markdown +++ b/content/reference/promise-types/files/edit_xml/delete_tree.markdown @@ -15,10 +15,8 @@ XML subtree. ```cf3 bundle edit_xml example { -delete_tree: - - "" - select_xpath => "/Server/Service/Engine"; + delete_tree: + "" select_xpath => "/Server/Service/Engine"; } ``` diff --git a/content/reference/promise-types/files/edit_xml/insert_text.markdown b/content/reference/promise-types/files/edit_xml/insert_text.markdown index 6530c50ea..0621cf4c2 100644 --- a/content/reference/promise-types/files/edit_xml/insert_text.markdown +++ b/content/reference/promise-types/files/edit_xml/insert_text.markdown @@ -15,10 +15,9 @@ string of text. ```cf3 bundle edit_xml example { -insert_text: - - "text content to be appended to existing text, including whitespace, within specified node" - select_xpath => "/Server/Service/Engine/Host/Alias"; + insert_text: + "text content to be appended to existing text, including whitespace, within specified node" + select_xpath => "/Server/Service/Engine/Host/Alias"; } ``` diff --git a/content/reference/promise-types/files/edit_xml/insert_tree.markdown b/content/reference/promise-types/files/edit_xml/insert_tree.markdown index ff6f1bbc5..6264314f3 100644 --- a/content/reference/promise-types/files/edit_xml/insert_tree.markdown +++ b/content/reference/promise-types/files/edit_xml/insert_tree.markdown @@ -15,10 +15,9 @@ referred to is a literal string representation of a balanced XML tree. ```cf3 bundle edit_xml example { -insert_tree: - - "cfe_alias" - select_xpath => "/Server/Service/Engine"; + insert_tree: + "cfe_alias" + select_xpath => "/Server/Service/Engine"; } ``` diff --git a/content/reference/promise-types/files/edit_xml/set_attribute.markdown b/content/reference/promise-types/files/edit_xml/set_attribute.markdown index 5035da13a..4375334d0 100644 --- a/content/reference/promise-types/files/edit_xml/set_attribute.markdown +++ b/content/reference/promise-types/files/edit_xml/set_attribute.markdown @@ -16,11 +16,10 @@ a literal string representation of the name of the attribute to be set. ```cf3 bundle edit_xml example { -set_attribute: - "name" - - attribute_value => "cfe_host", - select_xpath => "/Server/Service/Engine/Host"; + set_attribute: + "name" + attribute_value => "cfe_host", + select_xpath => "/Server/Service/Engine/Host"; } ``` diff --git a/content/reference/promise-types/files/edit_xml/set_text.markdown b/content/reference/promise-types/files/edit_xml/set_text.markdown index 841f210fb..e14c915b2 100644 --- a/content/reference/promise-types/files/edit_xml/set_text.markdown +++ b/content/reference/promise-types/files/edit_xml/set_text.markdown @@ -14,10 +14,9 @@ The promise object referred to is a literal string of text. ```cf3 bundle edit_xml example { -set_text: - "text content to replace existing text, including whitespace, within selected node" - - select_xpath => "/Server/Service/Engine/Host/Alias"; + set_text: + "text content to replace existing text, including whitespace, within selected node" + select_xpath => "/Server/Service/Engine/Host/Alias"; } ``` diff --git a/content/reference/promise-types/guest_environments.markdown b/content/reference/promise-types/guest_environments.markdown index 7a73687e8..af0d8e9f2 100644 --- a/content/reference/promise-types/guest_environments.markdown +++ b/content/reference/promise-types/guest_environments.markdown @@ -110,17 +110,14 @@ time. ```cf3 body environment_interface vnet(primary) { -env_name => "$(this.promiser)"; -env_addresses => { "$(primary)" }; + env_name => "$(this.promiser)"; + env_addresses => { "$(primary)" }; -host1:: - - env_network => "default_vnet1"; - -host2:: - - env_network => "default_vnet2"; + host1:: + env_network => "default_vnet1"; + host2:: + env_network => "default_vnet2"; } ``` @@ -140,14 +137,14 @@ identifier used as 'promiser' by the virtualization manager. ```cf3 body environment_interface vnet(primary) { -env_name => "$(this.promiser)"; -env_addresses => { "$(primary)" }; + env_name => "$(this.promiser)"; + env_addresses => { "$(primary)" }; -host1:: - env_network => "default_vnet1"; + host1:: + env_network => "default_vnet1"; -host2:: - env_network => "default_vnet2"; + host2:: + env_network => "default_vnet2"; } ``` @@ -164,14 +161,14 @@ host2:: ```cf3 body environment_interface vnet(primary) { -env_name => "$(this.promiser)"; -env_addresses => { "$(primary)" }; + env_name => "$(this.promiser)"; + env_addresses => { "$(primary)" }; -host1:: - env_network => "default_vnet1"; + host1:: + env_network => "default_vnet1"; -host2:: - env_network => "default_vnet2"; + host2:: + env_network => "default_vnet2"; } ``` @@ -198,9 +195,9 @@ will set a natural limit on this value. ```cf3 body environment_resources my_environment { -env_cpus => "2"; -env_memory => "512"; # in KB -env_disk => "1024"; # in MB + env_cpus => "2"; + env_memory => "512"; # in KB + env_disk => "1024"; # in MB } ``` @@ -224,9 +221,9 @@ natural limit on this value. ```cf3 body environment_resources my_environment { -env_cpus => "2"; -env_memory => "512"; # in KB -env_disk => "1024"; # in MB + env_cpus => "2"; + env_memory => "512"; # in KB + env_disk => "1024"; # in MB } ``` @@ -249,9 +246,9 @@ This parameter is currently unsupported, for future extension. ```cf3 body environment_resources my_environment { -env_cpus => "2"; -env_memory => "512"; # in KB -env_disk => "1024"; # in MB + env_cpus => "2"; + env_memory => "512"; # in KB + env_disk => "1024"; # in MB } ``` @@ -295,9 +292,7 @@ creation; in other words, when `environment_state` is create. ```cf3 body environment_resources virt_xml(host) { -env_spec => - -" + env_spec => " $(host)/name> linux/type> diff --git a/content/reference/promise-types/measurements.markdown b/content/reference/promise-types/measurements.markdown index 9b3df1561..d61dd8b60 100644 --- a/content/reference/promise-types/measurements.markdown +++ b/content/reference/promise-types/measurements.markdown @@ -26,27 +26,25 @@ bundle monitor self_watch measurements: # Follow a special process over time # using CFEngine's process cache to avoid resampling - # Example content from /var/cfengine/state/cf_rootprocs #USER PID PPID PGID %CPU %MEM VSZ NI RSS TTY NLWP STIME ELAPSED TIME COMMAND #root 19103 1 19103 0.2 2.1 71716 0 10676 ? 1 18:09 40:13 00:00:06 /var/cfengine/bin/cf-monitord --no-fork - # match_value: #root \s+ [0-9.]+ \s+ [0-9.]+ \s+ [0-9.]+ \s+ [0-9.]+ \s+ [0-9.]+ \s+ [0-9]+ \s+ [0-9]+ \s+ ([0-9]+) .*" - - "/var/cfengine/state/cf_rootprocs" - - handle => "cf_monitord_RSS", - stream_type => "file", - data_type => "int", - history_type => "weekly", - units => "kb", - match_value => proc_value(".*cf-monitord.*", - "root\s+[0-9.]+\s+[0-9.]+\s+[0-9.]+\s+[0-9.]+\s+[0-9.]+\s+\s+[0-9.]+\s+[0-9.]+\s+([0-9]+).*"), - comment => "The amount of memory (RSS or Resident Set Size) cf-monitored is consuming"; + "/var/cfengine/state/cf_rootprocs" + handle => "cf_monitord_RSS", + stream_type => "file", + data_type => "int", + history_type => "weekly", + units => "kb", + match_value => proc_value( + ".*cf-monitord.*", + "root\s+[0-9.]+\s+[0-9.]+\s+[0-9.]+\s+[0-9.]+\s+[0-9.]+\s+\s+[0-9.]+\s+[0-9.]+\s+([0-9]+).*" + ), + comment => "The amount of memory (RSS or Resident Set Size) cf-monitored is consuming"; } -body match_value proc_value(x,y) +body match_value proc_value(x, y) { select_line_matching => "$(x)"; select_multiline_policy => "sum"; @@ -66,7 +64,6 @@ bundle monitor watch_diskspace history_type => "static", units => "device", match_value => file_systems; - } body match_value file_systems @@ -311,17 +308,15 @@ This attribute is mutually exclusive of `select_line_number`. ```cf3 # Editing - body location example { -select_line_matching => "Expression match.* whole line"; + select_line_matching => "Expression match.* whole line"; } # Measurement promises - body match_value example { -select_line_matching => "Expression match.* whole line"; + select_line_matching => "Expression match.* whole line"; } ``` @@ -340,7 +335,7 @@ This is mutually exclusive of [`select_line_matching`][measurements#select_line_ ```cf3 body match_value find_line { -select_line_number => "2"; + select_line_number => "2"; } ``` @@ -362,8 +357,8 @@ it may match a partial string. ```cf3 body match_value free_memory { -select_line_matching => "MemFree:.*"; -extraction_regex => "MemFree:\s+([0-9]+).*"; + select_line_matching => "MemFree:.*"; + extraction_regex => "MemFree:\s+([0-9]+).*"; } ``` @@ -389,33 +384,26 @@ logfile | grep pattern in Unix parlance. ```cf3 bundle monitor watch { -measurements: - - "/home/mark/tmp/file" - - handle => "line_counter", - stream_type => "file", + measurements: + "/home/mark/tmp/file" + handle => "line_counter", + stream_type => "file", data_type => "counter", - match_value => scan_log("MYLINE.*"), - history_type => "log", - action => sample_rate("0"); - + match_value => scan_log("MYLINE.*"), + history_type => "log", + action => sample_rate("0"); } -# - body match_value scan_log(x) { -select_line_matching => "^$(x)$"; -track_growing_file => "true"; + select_line_matching => "^$(x)$"; + track_growing_file => "true"; } -# - body action sample_rate(x) { -ifelapsed => "$(x)"; -expireafter => "10"; + ifelapsed => "$(x)"; + expireafter => "10"; } ``` @@ -444,9 +432,9 @@ last ```cf3 body match_value myvalue(xxx) { - select_line_matching => ".*$(xxx).*"; - extraction_regex => "root\s+\S+\s+\S+\s+\S+\s+\S+\s+\S+\s+\S+\s+\S+\s+(\S+).*"; - select_multiline_policy => "sum"; + select_line_matching => ".*$(xxx).*"; + extraction_regex => "root\s+\S+\s+\S+\s+\S+\s+\S+\s+\S+\s+\S+\s+\S+\s+(\S+).*"; + select_multiline_policy => "sum"; } ``` diff --git a/content/reference/promise-types/meta.markdown b/content/reference/promise-types/meta.markdown index a25a1350d..ea64e4669 100644 --- a/content/reference/promise-types/meta.markdown +++ b/content/reference/promise-types/meta.markdown @@ -14,16 +14,13 @@ CFEngine Enterprise variable reports. ```cf3 bundle agent example { -meta: - - "bundle_version" string => "1.2.3"; - "works_with_cfengine" slist => { "3.4.0", "3.5.0" }; - -reports: - - "Not a local variable: $(bundle_version)"; - "Meta data (variable): $(example_meta.bundle_version)"; + meta: + "bundle_version" string => "1.2.3"; + "works_with_cfengine" slist => { "3.4.0", "3.5.0" }; + reports: + "Not a local variable: $(bundle_version)"; + "Meta data (variable): $(example_meta.bundle_version)"; } ``` diff --git a/content/reference/promise-types/methods.markdown b/content/reference/promise-types/methods.markdown index cc0370463..c20431205 100644 --- a/content/reference/promise-types/methods.markdown +++ b/content/reference/promise-types/methods.markdown @@ -26,36 +26,37 @@ the promiser string. bundle agent example { vars: + "userlist" slist => { "mark", "jeang", "jonhenrik", "thomas", "eben" }; - "userlist" slist => { "mark", "jeang", "jonhenrik", "thomas", "eben" }; - "userinfo" data => parsejson('{ "mark": 10, "jeang":20, "jonhenrik":30, "thomas":40, "eben":-1 }'); + "userinfo" + data => parsejson( + '{ "mark": 10, "jeang":20, "jonhenrik":30, "thomas":40, "eben":-1 }' + ); methods: - # Activate subtest once for each list item - "any" usebundle => subtest("$(userlist)"); + # Activate subtest once for each list item + "any" usebundle => subtest("$(userlist)"); - # Activate subtest once passing the entire list - "amy" usebundle => subtest(@(userlist)); + # Activate subtest once passing the entire list + "amy" usebundle => subtest(@(userlist)); - # Pass a data type variable aka data container - "amp" usebundle => subtest_c(@(userinfo)); + # Pass a data type variable aka data container + "amp" usebundle => subtest_c(@(userinfo)); } bundle agent subtest(user) { commands: - - "/bin/echo Fix $(user)"; + "/bin/echo Fix $(user)"; reports: - "Finished doing stuff for $(user)"; } bundle agent subtest_c(info) { reports: - "user ID of mark is $(info[mark])"; + "user ID of mark is $(info[mark])"; } ``` @@ -83,13 +84,13 @@ contain the variable name of the method if the variable is a list. ```cf3 bundle agent default { -vars: - "m" slist => { "x", "y" }; + vars: + "m" slist => { "x", "y" }; "p" string => "myfunction"; -methods: + methods: "set of $(m)" usebundle => $(m)("one"); - "any" usebundle => $(p)("two"); + "any" usebundle => $(p)("two"); } ``` @@ -136,18 +137,19 @@ example: `$(bundle.variable)`. ```cf3 bundle agent name { -classes: - "name_class"; + classes: + "name_class"; -methods: - "group name" usebundle => my_method, - inherit => "true"; + methods: + "group name" + usebundle => my_method, + inherit => "true"; } bundle agent my_method { -reports: - "$(this.bundle) inherited class 'name_class'" if => "name_class"; + reports: + "$(this.bundle) inherited class 'name_class'" if => "name_class"; } ``` @@ -173,25 +175,21 @@ Return values are limited to scalars. ```cf3 bundle agent test { -methods: - - "any" usebundle => child, - useresult => "my_return_var"; + methods: + "any" + usebundle => child, + useresult => "my_return_var"; -reports: + reports: "My return was: \"$(my_return_var[1])\" and \"$(my_return_var[2])\""; } bundle agent child { -reports: - # Map these indices into the useresult namespace - - "this is a return value" - bundle_return_value_index => "1"; - - "this is another return value" - bundle_return_value_index => "2"; + reports: + # Map these indices into the useresult namespace + "this is a return value" bundle_return_value_index => "1"; + "this is another return value" bundle_return_value_index => "2"; } ``` diff --git a/content/reference/promise-types/packages-deprecated.markdown b/content/reference/promise-types/packages-deprecated.markdown index aed1cdd26..e435eb46a 100644 --- a/content/reference/promise-types/packages-deprecated.markdown +++ b/content/reference/promise-types/packages-deprecated.markdown @@ -157,23 +157,15 @@ Normal ordering for packages is the following: ```cf3 bundle agent packages { -vars: - - # Test the simplest case -- leave everything to the yum smart manager - - "match_package" slist => { - "apache2", - "apache2-mod_php5", - "apache2-prefork", - "php5" - }; -packages: - - "$(match_package)" - - package_policy => "add", - package_method => yum; - + vars: + # Test the simplest case -- leave everything to the yum smart manager + "match_package" + slist => { "apache2", "apache2-mod_php5", "apache2-prefork", "php5" }; + + packages: + "$(match_package)" + package_policy => "add", + package_method => yum; } ``` @@ -292,7 +284,7 @@ prevents CFEngine from appending the package name to the string. ```cf3 body package_method rpm { -package_add_command => "/bin/rpm -i "; + package_add_command => "/bin/rpm -i "; } ``` @@ -315,9 +307,8 @@ the _promiser_ at which the architecture is specified. ```cf3 body package_method rpm - { -package_list_arch_regex => "[^.]+\.([^.]+)"; + package_list_arch_regex => "[^.]+\.([^.]+)"; } ``` @@ -349,9 +340,8 @@ bulk ```cf3 body package_method rpm - { -package_changes => "bulk"; + package_changes => "bulk"; } ``` @@ -376,7 +366,7 @@ prevents CFEngine from appending the package name to the string. ```cf3 body package_method rpm { -package_delete_command => "/bin/rpm -e --nodeps"; + package_delete_command => "/bin/rpm -e --nodeps"; } ``` @@ -407,11 +397,10 @@ to expand the first repository containing the package. For example: ```cf3 body package_method freebsd - { -package_file_repositories => { "/path/to/packages" }; -package_name_convention => "$(name)-$(version).tbz"; -package_delete_convention => "$(name)-$(version)"; + package_file_repositories => { "/path/to/packages" }; + package_name_convention => "$(name)-$(version).tbz"; + package_delete_convention => "$(name)-$(version)"; } ``` @@ -437,7 +426,7 @@ the package name in the package commands. ```cf3 body package_method filebased { -package_file_repositories => { "/package/repos1", "/packages/repos2" }; + package_file_repositories => { "/package/repos1", "/packages/repos2" }; } ``` @@ -461,7 +450,7 @@ be ignored. ```cf3 body package_method yum { -package_installed_regex => ".*installed.*"; + package_installed_regex => ".*installed.*"; } ``` @@ -512,7 +501,7 @@ architecture is specified. ```cf3 body package_method rpm { -package_list_arch_regex => "[^|]+\|[^|]+\|[^|]+\|[^|]+\|\s+([^\s]+).*"; + package_list_arch_regex => "[^|]+\|[^|]+\|[^|]+\|[^|]+\|\s+([^\s]+).*"; } ``` @@ -540,9 +529,8 @@ prevents CFEngine from appending the package name to the string. ```cf3 body package_method rpm - { -package_list_command => "/bin/rpm -qa --queryformat \"%{name} %{version}-%{release}\n\""; + package_list_command => "/bin/rpm -qa --queryformat \"%{name} %{version}-%{release}\n\""; } ``` @@ -562,9 +550,8 @@ reference which marks the name of the package from the package listing. ```cf3 body package_method rpm - { -package_list_name_regex => "([^\s]+).*"; + package_list_name_regex => "([^\s]+).*"; } ``` @@ -585,10 +572,9 @@ executed at intervals determined by `package_list_update_ifelapsed`. ```cf3 body package_method xyz { -debian|ubuntu:: - -package_list_update_command => "/usr/bin/apt-get update"; -package_list_update_ifelapsed => "240"; # 4 hours + debian|ubuntu:: + package_list_update_command => "/usr/bin/apt-get update"; + package_list_update_ifelapsed => "240"; # 4 hours } ``` @@ -606,10 +592,9 @@ locking time in between updates of the package list ```cf3 body package_method xyz { -debian|ubuntu:: - -package_list_update_command => "/usr/bin/apt-get update"; -package_list_update_ifelapsed => "240"; # 4 hours + debian|ubuntu:: + package_list_update_command => "/usr/bin/apt-get update"; + package_list_update_ifelapsed => "240"; # 4 hours } ``` @@ -630,9 +615,8 @@ installed. ```cf3 body package_method rpm - { -package_list_version_regex => "[^\s]+ ([^.]+).*"; + package_list_version_regex => "[^\s]+ ([^.]+).*"; } ``` @@ -663,7 +647,7 @@ If this is not defined, it defaults to the value `$(name)`. ```cf3 body package_method rpm { -package_name_convention => "$(name).$(arch).rpm"; + package_name_convention => "$(name).$(arch).rpm"; } ``` @@ -686,7 +670,7 @@ back-reference to extract the name of the package from the string. ```cf3 body package_method rpm { -package_name_regex => "([^\s]).*"; + package_name_regex => "([^\s]).*"; } ``` @@ -706,10 +690,9 @@ broken. ```cf3 body package_method xyz - { -package_noverify_regex => "Package .* is not installed.*"; -package_verify_command => "/usr/bin/dpkg -s"; + package_noverify_regex => "Package .* is not installed.*"; + package_verify_command => "/usr/bin/dpkg -s"; } ``` @@ -730,8 +713,8 @@ signal for a failed package verification. ```cf3 body package_method xyz { -package_noverify_returncode => "-1"; -package_verify_command => "/bin/rpm -V"; + package_noverify_returncode => "-1"; + package_verify_command => "/bin/rpm -V"; } ``` @@ -753,7 +736,7 @@ an analogous command struct to the packages for patch updates. ```cf3 body package_method zypper { -package_patch_arch_regex => ""; + package_patch_arch_regex => ""; } ``` @@ -776,9 +759,8 @@ interpret as an instruction to not append package names. ```cf3 body package_method zypper - { -package_patch_command => "/usr/bin/zypper -non-interactive patch"; + package_patch_command => "/usr/bin/zypper -non-interactive patch"; } ``` @@ -800,7 +782,7 @@ analogous command struct to the packages for patch updates. ```cf3 body package_method zypper { -package_patch_installed_regex => ".*(Installed|Not Applicable).*"; + package_patch_installed_regex => ".*(Installed|Not Applicable).*"; } ``` @@ -847,7 +829,7 @@ an analogous command struct to the packages for patch updates. ```cf3 body package_method zypper { -package_patch_name_regex => "[^|]+\|\s+([^\s]+).*"; + package_patch_name_regex => "[^|]+\|\s+([^\s]+).*"; } ``` @@ -869,7 +851,7 @@ an analogous command struct to the packages for patch updates. ```cf3 body package_method zypper { -package_patch_version_regex => "[^|]+\|[^|]+\|\s+([^\s]+).*"; + package_patch_version_regex => "[^|]+\|[^|]+\|\s+([^\s]+).*"; } ``` @@ -898,7 +880,7 @@ carry out the update. ```cf3 body package_method zypper { -package_update_command => "/usr/bin/zypper -non-interactive update"; + package_update_command => "/usr/bin/zypper -non-interactive update"; } ``` @@ -932,10 +914,9 @@ prevents CFEngine from appending the package name to the string. ```cf3 body package_method rpm - { -package_verify_command => "/bin/rpm -V"; -package_noverify_returncode => "-1"; + package_verify_command => "/bin/rpm -V"; + package_noverify_returncode => "-1"; } ``` @@ -958,7 +939,7 @@ version string in the promiser. ```cf3 body package_method rpm { -package_version_regex => "[^\s]+ ([^.]+).*"; + package_version_regex => "[^\s]+ ([^.]+).*"; } ``` @@ -979,12 +960,13 @@ record. **Example:** ```cf3 -body package_method solaris (pkgname, spoolfile, adminfile) +body package_method solaris(pkgname, spoolfile, adminfile) { -package_changes => "individual"; -package_list_command => "/usr/bin/pkginfo -l"; -package_multiline_start => "\s*PKGINST:\s+[^\s]+"; -# ... + package_changes => "individual"; + package_list_command => "/usr/bin/pkginfo -l"; + package_multiline_start => "\s*PKGINST:\s+[^\s]+"; + + # ... } ``` @@ -1032,8 +1014,8 @@ v2, and v2 is not less than v1). ```cf3 body package_method deb { -# ... -package_version_less_command => "dpkg --compare-versions ${v1} lt ${v2}"; + # ... + package_version_less_command => "dpkg --compare-versions ${v1} lt ${v2}"; } ``` @@ -1069,8 +1051,8 @@ v2, and v2 is not less than v1). ```cf3 body package_method deb { -# ... -package_version_equal_command => "dpkg --compare-versions ${v1} eq ${v2}"; + # ... + package_version_equal_command => "dpkg --compare-versions ${v1} eq ${v2}"; } ``` diff --git a/content/reference/promise-types/packages.markdown b/content/reference/promise-types/packages.markdown index 28ea995f1..ca221101d 100644 --- a/content/reference/promise-types/packages.markdown +++ b/content/reference/promise-types/packages.markdown @@ -218,7 +218,7 @@ See the `options` attribute for details on what options do. ```cf3 body package_module apt_get { - default_options => { "use_curl=1" }; + default_options => { "use_curl=1" }; } ``` @@ -241,8 +241,8 @@ The cache is always updated when CFEngine makes changes to the system. ```cf3 body package_module apt_get { - # Query the package database only every four hours. - query_installed_ifelapsed => "240"; + # Query the package database only every four hours. + query_installed_ifelapsed => "240"; } ``` @@ -274,8 +274,8 @@ local query in order to update the cache from local, already downloaded data. ```cf3 body package_module apt_get { - # Query package updates only every 24 hours. - query_updates_ifelapsed => "1440"; + # Query package updates only every 24 hours. + query_updates_ifelapsed => "1440"; } ``` @@ -305,8 +305,8 @@ path to the interpreter to use when running the package module. ```cf3 body package_module apt_get { - # better use variable like $(def.python) - interpreter => "/usr/bin/python3.6"; + # better use variable like $(def.python) + interpreter => "/usr/bin/python3.6"; } ``` @@ -333,8 +333,8 @@ different attributes (e.g. `default_options`). ```cf3 body package_module yum_all_repos { - module_path => "$(sys.workdir)/modules/packages/yum"; - default_options => { "--enablerepo=*" }; + module_path => "$(sys.workdir)/modules/packages/yum"; + default_options => { "--enablerepo=*" }; } ``` @@ -474,23 +474,20 @@ Enable a specific repository for a specific promise. bundle agent example { packages: - rocky_8:: # Enable the EPEL repo when making sure etc-keeper is installed # and up to date. - "etckeeper-dnf" - policy => "present", - version => "latest", - options => { "enablerepo=powertools" }; + policy => "present", + version => "latest", + options => { "enablerepo=powertools" }; # Only consider updates from the main repositories for # httpd and disable all other repositories - "httpd" - policy => "present", - version => "latest", - options => { "disablerepo=*", "enablerepo=UPDATES" }; + policy => "present", + version => "latest", + options => { "disablerepo=*", "enablerepo=UPDATES" }; } ``` @@ -770,20 +767,20 @@ bundle agent main policy => "absent", package_module => snap; - "genpw" - policy => "present", - package_module => snap, - version => "2.0.0"; + "genpw" + policy => "present", + package_module => snap, + version => "2.0.0"; - "genpw" - policy => "absent", - package_module => snap, - version => "2.0.0"; + "genpw" + policy => "absent", + package_module => snap, + version => "2.0.0"; - "genpw" - policy => "present", - package_module => snap, - version => "latest"; + "genpw" + policy => "present", + package_module => snap, + version => "latest"; } ``` diff --git a/content/reference/promise-types/processes.markdown b/content/reference/promise-types/processes.markdown index 182a8e4fc..5f9281a4a 100644 --- a/content/reference/promise-types/processes.markdown +++ b/content/reference/promise-types/processes.markdown @@ -32,16 +32,16 @@ This is an example showing how to restart a splunk process owned by root: bundle agent example { processes: - "splunkd" - process_select => by_owner( "root" ), - handle => "example_splunk_stop_gracefully", - process_stop => "/opt/splunkforwarder/bin/splunk stop", - comment => "Find splunkd processes owned by root. Stop it gracefully + "splunkd" + process_select => by_owner("root"), + handle => "example_splunk_stop_gracefully", + process_stop => "/opt/splunkforwarder/bin/splunk stop", + comment => "Find splunkd processes owned by root. Stop it gracefully with the internal splunk binary."; - "splunkd" - restart_class => "splunk_not_running", - comment => "Set splunk_not_running class if we cant find any root owned + "splunkd" + restart_class => "splunk_not_running", + comment => "Set splunk_not_running class if we cant find any root owned splunkd processes so that we can restart it using a commands promise"; @@ -117,7 +117,7 @@ the number of processes matching the other criteria is kept. ```cf3 body process_count example { -in_range_define => { "class1", "class2" }; + in_range_define => { "class1", "class2" }; } ``` @@ -139,7 +139,7 @@ the promise is considered kept. ```cf3 body process_count example { -match_range => irange("10","50"); + match_range => irange("10", "50"); } ``` @@ -159,7 +159,7 @@ failure to be kept. ```cf3 body process_count example(s) { -out_of_range_define => { "process_anomaly", "anomaly_$(s)"}; + out_of_range_define => { "process_anomaly", "anomaly_$(s)" }; } ``` @@ -190,11 +190,9 @@ the end of line. ```cf3 body process_select example - { -command => "cf-.*"; - -process_result => "command"; + command => "cf-.*"; + process_result => "command"; } ``` @@ -211,8 +209,8 @@ process_result => "command"; ```cf3 body process_select example { -pid => irange("1","10"); -process_result => "pid"; + pid => irange("1", "10"); + process_result => "pid"; } ``` @@ -232,8 +230,8 @@ process ```cf3 body process_select example { -pgid => irange("1","10"); -process_result => "pgid"; + pgid => irange("1", "10"); + process_result => "pgid"; } ``` @@ -253,8 +251,8 @@ process ```cf3 body process_select example { -ppid => irange("407","511"); -process_result => "ppid"; + ppid => irange("407", "511"); + process_result => "ppid"; } ``` @@ -274,7 +272,7 @@ a process ```cf3 body process_select example { -priority => irange("-5","0"); + priority => irange("-5", "0"); } ``` @@ -314,13 +312,12 @@ together. ```cf3 body process_select proc_finder(p) - { -process_owner => { "avahi", "bin" }; -command => "$(p)"; -pid => irange("100","199"); -vsize => irange("0","1000"); -process_result => "command.(process_owner|vsize).!pid"; + process_owner => { "avahi", "bin" }; + command => "$(p)"; + pid => irange("100", "199"); + vsize => irange("0", "1000"); + process_result => "command.(process_owner|vsize).!pid"; } ``` @@ -340,7 +337,7 @@ process, in kilobytes ```cf3 body process_select example { - rsize => irange("4000","8000"); + rsize => irange("4000", "8000"); } ``` @@ -362,7 +359,7 @@ have status fields. ```cf3 body process_select example { -status => "Z"; + status => "Z"; } ``` @@ -383,7 +380,7 @@ hour off. This is for now a bug to be fixed. ```cf3 body process_select example { -stime_range => irange(ago(0,0,0,1,0,0),now); + stime_range => irange(ago(0, 0, 0, 1, 0, 0), now); } ``` @@ -405,7 +402,7 @@ This is total accumulated time for a process. ```cf3 body process_select example { -ttime_range => irange(0,accumulated(0,1,0,0,0,0)); + ttime_range => irange(0, accumulated(0, 1, 0, 0, 0, 0)); } ``` @@ -427,7 +424,7 @@ all have tty '?'. ```cf3 body process_select example { -tty => "pts/[0-9]+"; + tty => "pts/[0-9]+"; } ``` @@ -445,7 +442,7 @@ process ```cf3 body process_select example { -threads => irange(1,5); + threads => irange(1, 5); } ``` @@ -469,7 +466,7 @@ Size (Windows 2008), or VM Size (Windows XP). ```cf3 body process_select example { -vsize => irange("4000","9000"); + vsize => irange("4000", "9000"); } ``` diff --git a/content/reference/promise-types/reports.markdown b/content/reference/promise-types/reports.markdown index 44db4af9d..1692e755f 100644 --- a/content/reference/promise-types/reports.markdown +++ b/content/reference/promise-types/reports.markdown @@ -23,11 +23,8 @@ distinguish them from other output. bundle agent report { reports: - loadavg_high:: - - "Processes:" - printfile => cat("$(sys.statedir)/cf_procs"); + "Processes:" printfile => cat("$(sys.statedir)/cf_procs"); } ``` @@ -41,9 +38,7 @@ bundle agent report "classes" slist => classesmatching("report_.*"); reports: - "HI" - classes => scoped_classes_generic("bundle", "report"); - + "HI" classes => scoped_classes_generic("bundle", "report"); "found class: $(classes)"; } @@ -51,11 +46,40 @@ body classes scoped_classes_generic(scope, x) # Define x prefixed/suffixed with promise outcome { scope => "$(scope)"; - promise_repaired => { "promise_repaired_$(x)", "$(x)_repaired", "$(x)_ok", "$(x)_reached" }; - repair_failed => { "repair_failed_$(x)", "$(x)_failed", "$(x)_not_ok", "$(x)_not_kept", "$(x)_not_repaired", "$(x)_reached" }; - repair_denied => { "repair_denied_$(x)", "$(x)_denied", "$(x)_not_ok", "$(x)_not_kept", "$(x)_not_repaired", "$(x)_reached" }; - repair_timeout => { "repair_timeout_$(x)", "$(x)_timeout", "$(x)_not_ok", "$(x)_not_kept", "$(x)_not_repaired", "$(x)_reached" }; - promise_kept => { "promise_kept_$(x)", "$(x)_kept", "$(x)_ok", "$(x)_not_repaired", "$(x)_reached" }; + promise_repaired => { + "promise_repaired_$(x)", "$(x)_repaired", "$(x)_ok", "$(x)_reached" + }; + repair_failed => { + "repair_failed_$(x)", + "$(x)_failed", + "$(x)_not_ok", + "$(x)_not_kept", + "$(x)_not_repaired", + "$(x)_reached", + }; + repair_denied => { + "repair_denied_$(x)", + "$(x)_denied", + "$(x)_not_ok", + "$(x)_not_kept", + "$(x)_not_repaired", + "$(x)_reached", + }; + repair_timeout => { + "repair_timeout_$(x)", + "$(x)_timeout", + "$(x)_not_ok", + "$(x)_not_kept", + "$(x)_not_repaired", + "$(x)_reached", + }; + promise_kept => { + "promise_kept_$(x)", + "$(x)_kept", + "$(x)_ok", + "$(x)_not_repaired", + "$(x)_reached", + }; } ``` @@ -148,11 +172,9 @@ standard output. ```cf3 bundle agent main { - reports: - - "$(sys.date),This is a report from $(sys.host)" - report_to_file => "/tmp/test_log"; + "$(sys.date),This is a report from $(sys.host)" + report_to_file => "/tmp/test_log"; } ``` @@ -174,30 +196,23 @@ Return values are limited to scalars. bundle agent main { methods: - - "any" - usebundle => child, - useresult => "my_return_var"; + "any" + usebundle => child, + useresult => "my_return_var"; reports: - - "My return was: '$(my_return_var[1])' and '$(my_return_var[2])' and '$(my_return_var[named])'"; + "My return was: '$(my_return_var[1])' and '$(my_return_var[2])' and '$(my_return_var[named])'"; } bundle agent child { reports: + # Map these indices into the useresult namespace + "this is a return value" bundle_return_value_index => "1"; + "this is another return value" bundle_return_value_index => "2"; - # Map these indices into the useresult namespace - - "this is a return value" - bundle_return_value_index => "1"; - - "this is another return value" - bundle_return_value_index => "2"; - - "bundle_return_value_index is not required to be numerical" - bundle_return_value_index => "named"; + "bundle_return_value_index is not required to be numerical" + bundle_return_value_index => "named"; } ``` diff --git a/content/reference/promise-types/services.markdown b/content/reference/promise-types/services.markdown index 79b4598b1..be40d3e77 100644 --- a/content/reference/promise-types/services.markdown +++ b/content/reference/promise-types/services.markdown @@ -39,12 +39,11 @@ passed to services that are started by CFEngine. ```cf3 bundle agent example { -services: - - "Dhcp" - service_policy => "start", - service_dependencies => { "Alerter", "W32Time" }, - service_method => winmethod; + services: + "Dhcp" + service_policy => "start", + service_dependencies => { "Alerter", "W32Time" }, + service_method => winmethod; } body service_method winmethod @@ -77,9 +76,9 @@ systems and are merely a convenient front-end to `processes` and reserved agent bundle called ```cf3 -bundle agent standard_services(service,state) +bundle agent standard_services(service, state) { -# ... + # ... } ``` @@ -96,31 +95,31 @@ The standard bundle can be replaced with another, as follows: ```cf3 bundle agent test { -vars: - - "mail" slist => { "spamassassin", "postfix" }; + vars: + "mail" slist => { "spamassassin", "postfix" }; -services: - - "www" service_policy => "start", - service_method => service_test; + services: + "www" + service_policy => "start", + service_method => service_test; - "$(mail)" service_policy => "stop", - service_method => service_test; + "$(mail)" + service_policy => "stop", + service_method => service_test; } body service_method service_test { - service_bundle => non_standard_services("$(this.promiser)","$(this.service_policy)"); + service_bundle => non_standard_services( + "$(this.promiser)", "$(this.service_policy)" + ); } -bundle agent non_standard_services(service,state) +bundle agent non_standard_services(service, state) { -reports: - - !done:: - - "Test service promise for \"$(service)\" -> $(state)"; + reports: + !done:: + "Test service promise for \"$(service)\" -> $(state)"; } ``` @@ -171,79 +170,76 @@ standard library. bundle agent example { services: - redhat|centos:: - # Manage a service using the standard_services implementation from the # standard library. - - "httpd" - service_policy => "disable"; + "httpd" service_policy => "disable"; any:: - # Manage a custom service using custom service_method - "myservice" service_policy => "my_custom_state", service_method => "my_custom_service_method"; windows:: - - "AdobeARMservice" - service_policy => "stop", - comment => "Ensure the Adobe Acrobat Update Service is not running. It + "AdobeARMservice" + service_policy => "stop", + comment => "Ensure the Adobe Acrobat Update Service is not running. It may or may not be automatically started on the next boot depending on the configuration."; - "CfengineNovaExec" - service_policy => "enable", - service_method => bootstart, # Ref stdlib - comment => "Ensure cf-execd is running and configured to start on + "CfengineNovaExec" + service_policy => "enable", + service_method => bootstart, # Ref stdlib + comment => "Ensure cf-execd is running and configured to start on boot."; - "VBoxService" - service_policy => "start", - service_method => bootstart, # Ref stdlib - comment => "Ensure VirtualBox Guest Additions Service is running and + "VBoxService" + service_policy => "start", + service_method => bootstart, # Ref stdlib + comment => "Ensure VirtualBox Guest Additions Service is running and configured to start on boot."; - "Spooler" - service_policy => "disable", - comment => "Ensure the Print Spooler is not running and will not start + "Spooler" + service_policy => "disable", + comment => "Ensure the Print Spooler is not running and will not start automatically on boot. We do not want to kill any trees."; - "tzautoupdate" - service_policy => "start", - comment => "Ensure that the Auto Time Zone Updated is running, and set + "tzautoupdate" + service_policy => "start", + comment => "Ensure that the Auto Time Zone Updated is running, and set Startup Type to Manual."; - } body service_method my_custom_service_method { - windows:: - service_bundle => my_custom_service_method_windows( $(this.promiser), $(this.service_policy) ); + service_bundle => my_custom_service_method_windows( + $(this.promiser), $(this.service_policy) + ); redhat|centos:: - service_bundle => my_custom_service_method_rhel( $(this.promiser), $(this.service_policy) ); + service_bundle => my_custom_service_method_rhel( + $(this.promiser), $(this.service_policy) + ); debian|ubuntu:: - service_bundle => my_custom_service_method_deb( $(this.promiser), $(this.service_policy) ); + service_bundle => my_custom_service_method_deb( + $(this.promiser), $(this.service_policy) + ); } -bundle agent my_custom_service_method_windows( service_identifier, desired_service_state ) +bundle agent my_custom_service_method_windows(service_identifier, desired_service_state) { # Specific windows implementation } -bundle agent my_custom_service_method_rhel( service_identifier, desired_service_state ) +bundle agent my_custom_service_method_rhel(service_identifier, desired_service_state) { # Specific Redhat|Centos implementation } -bundle agent my_custom_service_method_deb( service_identifier, desired_service_state ) +bundle agent my_custom_service_method_deb(service_identifier, desired_service_state) { # Specific Debian|Ubuntu implementation } diff --git a/content/reference/promise-types/storage.markdown b/content/reference/promise-types/storage.markdown index 57f02c8bf..bc018eceb 100644 --- a/content/reference/promise-types/storage.markdown +++ b/content/reference/promise-types/storage.markdown @@ -20,23 +20,19 @@ storage: bundle agent storage { storage: - - "/usr" volume => mycheck("10%"); - "/mnt" mount => nfs("nfsserv.example.org","/home"); - + "/usr" volume => mycheck("10%"); + "/mnt" mount => nfs("nfsserv.example.org", "/home"); } -body volume mycheck(free) # reusable template - +body volume mycheck(free) # reusable template { - check_foreign => "false"; - freespace => "$(free)"; - sensible_size => "10000"; + check_foreign => "false"; + freespace => "$(free)"; + sensible_size => "10000"; sensible_count => "2"; } -body mount nfs(server,source) - +body mount nfs(server, source) { mount_type => "nfs"; mount_source => "$(source)"; @@ -172,7 +168,7 @@ body mount example ```cf3 body mount example { -unmount => "true"; + unmount => "true"; } ``` @@ -201,7 +197,7 @@ on other systems. ```cf3 body volume example { - check_foreign => "true"; + check_foreign => "true"; } ``` @@ -224,12 +220,12 @@ the results of this promise to control other promises. ```cf3 body volume example1 { -freespace => "10%"; + freespace => "10%"; } body volume example2 { -freespace => "50M"; + freespace => "50M"; } ``` @@ -247,7 +243,7 @@ sensible-looking storage device ```cf3 body volume example { -sensible_size => "20K"; + sensible_size => "20K"; } ``` @@ -268,7 +264,7 @@ the agent has privileges on volumes being checked. ```cf3 body volume example { -sensible_count => "20"; + sensible_count => "20"; } ``` diff --git a/content/reference/promise-types/users.markdown b/content/reference/promise-types/users.markdown index 8301162f2..731cb8739 100644 --- a/content/reference/promise-types/users.markdown +++ b/content/reference/promise-types/users.markdown @@ -144,24 +144,25 @@ in the current bundle are inherited by the bundle specified in the ```cf3 bundle agent main { - vars: - "user" string => "jack"; - classes: - "should_have_home_dir" expression => regcmp("j.*", "$(user)"); - users: - "$(user)" - policy => "present", - home_dir => "/home/$(user)", - home_bundle => setup_home_dir("$(user)"), - home_bundle_inherit => "true"; + vars: + "user" string => "jack"; + + classes: + "should_have_home_dir" expression => regcmp("j.*", "$(user)"); + + users: + "$(user)" + policy => "present", + home_dir => "/home/$(user)", + home_bundle => setup_home_dir("$(user)"), + home_bundle_inherit => "true"; } bundle agent setup_home_dir(user) { - files: - should_have_home_dir:: - "/home/$(user)/." - create => "true"; + files: + should_have_home_dir:: + "/home/$(user)/." create => "true"; } ``` @@ -200,8 +201,8 @@ that contains information about a user's password. ```cf3 body password user_password { - format => "hash"; - data => "jiJSlLSkZuVLE"; # "CFEngine" + format => "hash"; + data => "jiJSlLSkZuVLE"; # "CFEngine" } ``` @@ -233,8 +234,8 @@ hashed passwords. ```cf3 body password user_password { - format => "plaintext"; - data => "CFEngine"; + format => "plaintext"; + data => "CFEngine"; } ``` @@ -251,8 +252,8 @@ The format of the password data depends on the `format` attribute. ```cf3 body password user_password { - format => "plaintext"; - data => "CFEngine"; + format => "plaintext"; + data => "CFEngine"; } ``` diff --git a/content/reference/promise-types/vars.markdown b/content/reference/promise-types/vars.markdown index a7d1d1288..8532f1e1e 100644 --- a/content/reference/promise-types/vars.markdown +++ b/content/reference/promise-types/vars.markdown @@ -408,12 +408,16 @@ bundle agent example_meta_vars "myvar" string => "my value"; reports: - "$(with)" with => string_mustache( "{{%-top-}}", variablesmatching_as_data( ".*example_meta_vars.*" ) ); - + "$(with)" + with => string_mustache( + "{{%-top-}}", variablesmatching_as_data(".*example_meta_vars.*") + ); } + bundle agent __main__ { - methods: "example_meta_vars"; + methods: + "example_meta_vars"; } ``` @@ -442,17 +446,22 @@ bundle agent example_variable_injection "cant_push_this.myvar" string => "my value"; reports: - "$(with)" with => string_mustache( "{{%-top-}}", variablesmatching_as_data( ".*myvar.*" ) ); - + "$(with)" + with => string_mustache( + "{{%-top-}}", variablesmatching_as_data(".*myvar.*") + ); } + bundle agent cant_push_this { - # If a bundle is defined, you can't simply define a variable in it from - # another bundle, unless the variable is defined via the module protocol. + # If a bundle is defined, you can't simply define a variable in it from + # another bundle, unless the variable is defined via the module protocol. } + bundle agent __main__ { - methods: "example_variable_injection"; + methods: + "example_variable_injection"; } ``` @@ -507,20 +516,27 @@ bundle agent example_variable_injection_via_module { commands: "/bin/echo '^context=undefined$(const.n)=myvar=my value" module => "true"; - "/bin/echo '^context=cant_push_this$(const.n)=myvar=my value" module => "true"; - reports: - "$(with)" with => string_mustache( "{{%-top-}}", variablesmatching_as_data( ".*myvar.*" ) ); + "/bin/echo '^context=cant_push_this$(const.n)=myvar=my value" + module => "true"; + reports: + "$(with)" + with => string_mustache( + "{{%-top-}}", variablesmatching_as_data(".*myvar.*") + ); } + bundle agent cant_push_this { - # If a bundle is defined, you can't simply define a variable in it from - # another bundle, unless the variable is defined via the module protocol. + # If a bundle is defined, you can't simply define a variable in it from + # another bundle, unless the variable is defined via the module protocol. } + bundle agent __main__ { - methods: "example_variable_injection_via_module"; + methods: + "example_variable_injection_via_module"; } ``` @@ -551,14 +567,16 @@ This example policy illustrates how augments defines variables in the def bundle bundle common def { vars: - "some_var" - string => "My value for $(this.promiser) defined in Policy"; + "some_var" string => "My value for $(this.promiser) defined in Policy"; } + bundle agent __main__ { reports: "$(with)" - with => string_mustache( "{{%-top-}}", variablesmatching_as_data( "default:def.*") ); + with => string_mustache( + "{{%-top-}}", variablesmatching_as_data("default:def.*") + ); } ``` @@ -584,16 +602,17 @@ This example policy illustrates how policy will, by default, re-define variables bundle common def { vars: - "some_var" - string => "My value for $(this.promiser) defined in Policy"; - "my_var" - string => "My value for $(this.promiser) defined in Policy"; + "some_var" string => "My value for $(this.promiser) defined in Policy"; + "my_var" string => "My value for $(this.promiser) defined in Policy"; } + bundle agent __main__ { reports: "$(with)" - with => string_mustache( "{{%-top-}}", variablesmatching_as_data( "default:def.*") ); + with => string_mustache( + "{{%-top-}}", variablesmatching_as_data("default:def.*") + ); } ``` @@ -619,22 +638,22 @@ This example policy illustrates how policy can be instrumented to avoid re-defin bundle common def { vars: - "some_var" - string => "My value for $(this.promiser) defined in Policy"; + "some_var" string => "My value for $(this.promiser) defined in Policy"; # Here we set my_var if it has not yet been defined (as in the case where # augments would define it before the policy was evaluated). - "my_var" string => "My value for $(this.promiser) defined in Policy", - unless => isvariable( $(this.promiser) ); - + unless => isvariable($(this.promiser)); } + bundle agent __main__ { reports: "$(with)" - with => string_mustache( "{{%-top-}}", variablesmatching_as_data( "default:def.*") ); + with => string_mustache( + "{{%-top-}}", variablesmatching_as_data("default:def.*") + ); } ``` diff --git a/content/reference/special-variables/def.markdown b/content/reference/special-variables/def.markdown index 292eb8ea2..3bf8cfad6 100644 --- a/content/reference/special-variables/def.markdown +++ b/content/reference/special-variables/def.markdown @@ -19,16 +19,13 @@ augments file.: ```cf3 bundle common def { - vars: + # ... + "mailto" + string => "root@$(def.domain)", + if => not(isvariable("mailto")); - # ... - - "mailto" - string => "root@$(def.domain)", - if => not(isvariable("mailto")); - - # ... + # ... } ``` diff --git a/content/reference/special-variables/match.markdown b/content/reference/special-variables/match.markdown index 1c2f39518..861406ded 100644 --- a/content/reference/special-variables/match.markdown +++ b/content/reference/special-variables/match.markdown @@ -14,17 +14,15 @@ files. ```cf3 bundle agent testbundle { -files: + files: + "/home/mark/tmp/(cf[23])_(.*)" + create => "true", + edit_line => myedit("second $(match.2)"); - "/home/mark/tmp/(cf[23])_(.*)" - create => "true", - edit_line => myedit("second $(match.2)"); - - # but more specifically... - - "/home/mark/tmp/cf3_(test)" - create => "true", - edit_line => myedit("second $(match.1)"); + # but more specifically... + "/home/mark/tmp/cf3_(test)" + create => "true", + edit_line => myedit("second $(match.1)"); } ``` diff --git a/content/reference/special-variables/sys.markdown b/content/reference/special-variables/sys.markdown index be2fa849d..4602f205c 100644 --- a/content/reference/special-variables/sys.markdown +++ b/content/reference/special-variables/sys.markdown @@ -961,15 +961,12 @@ local variables can be iterated. ```cf3 bundle agent test { -vars: - - # To iterate, we need a local copy - - "i1" slist => { @(sys.ip_addresses)} ; - "i2" slist => { @(sys.interfaces)} ; - -reports: + vars: + # To iterate, we need a local copy + "i1" slist => { @(sys.ip_addresses) }; + "i2" slist => { @(sys.interfaces) }; + reports: "Addresses: $(i1)"; "Interfaces: $(i2)"; "Addresses of the interfaces: $(sys.ipv4[$(i2)])"; @@ -1175,7 +1172,7 @@ A human friendly version of the operating system that's running. ```cf3 bundle agent __main__ { - reports: + reports: "$(sys.os_name_human)"; } ``` @@ -1197,9 +1194,8 @@ Information parsed from `/etc/os-release` if present. ```cf3 bundle agent main { - reports: - "$(with)" - with => string_mustache("{{%-top-}}", @(sys.os_release) ); + reports: + "$(with)" with => string_mustache("{{%-top-}}", @(sys.os_release)); } ``` @@ -1235,7 +1231,7 @@ The major version of the operating system that's running. ```cf3 bundle agent __main__ { - reports: + reports: "$(sys.os_version_major)"; } ``` diff --git a/content/reference/special-variables/this.markdown b/content/reference/special-variables/this.markdown index fda83ade8..8cbc3ba13 100644 --- a/content/reference/special-variables/this.markdown +++ b/content/reference/special-variables/this.markdown @@ -12,13 +12,12 @@ or available, but provides a context for variables where one is needed `edit_line` promise from a `files` promise). ```cf3 -bundle agent resolver(s,n) +bundle agent resolver(s, n) { -files: - "$(sys.resolv)" - - create => "true", - edit_line => doresolv("@(this.s)","@(this.n)"), + files: + "$(sys.resolv)" + create => "true", + edit_line => doresolv("@(this.s)", "@(this.n)"), edit_defaults => reconstruct; } ``` @@ -48,20 +47,26 @@ This variable contains the name of the bundle from which the current bundle was bundle agent main { methods: - "two"; + "two"; reports: - "in bundle $(this.bundle), caller $(with)" - with => ifelse( isvariable( "this.calling_bundle" ), "$(this.calling_bundle)", - "bundlesequence" ); + "in bundle $(this.bundle), caller $(with)" + with => ifelse( + isvariable("this.calling_bundle"), + "$(this.calling_bundle)", + "bundlesequence" + ); } bundle agent two { reports: - "in bundle $(this.bundle), caller $(with)" - with => ifelse( isvariable( "this.calling_bundle" ), "$(this.calling_bundle)", - "bundlesequence" ); + "in bundle $(this.bundle), caller $(with)" + with => ifelse( + isvariable("this.calling_bundle"), + "$(this.calling_bundle)", + "bundlesequence" + ); } ``` @@ -121,15 +126,15 @@ For example: ```cf3 bundle agent find666 { -files: - "/home" - file_select => world_writeable, - transformer => "/bin/echo DETECTED $(this.promiser)", - depth_search => recurse("inf"); - - "/etc/.*" - file_select => world_writeable, - transformer => "/bin/echo DETECTED $(this.promiser)"; + files: + "/home" + file_select => world_writeable, + transformer => "/bin/echo DETECTED $(this.promiser)", + depth_search => recurse("inf"); + + "/etc/.*" + file_select => world_writeable, + transformer => "/bin/echo DETECTED $(this.promiser)"; } body file_select world_writeable @@ -175,15 +180,15 @@ the value of the `service_policy` promise attribute . For example: ```cf3 bundle agent example { - services: - - "www" - service_policy => "start", - service_method => non_standard_services; + services: + "www" + service_policy => "start", + service_method => non_standard_services; } + body service_method non_standard_services { - service_bundle => non_standard_services( $(this.service_policy) ); + service_bundle => non_standard_services($(this.service_policy)); } ``` diff --git a/content/resources/additional-topics/agility.markdown b/content/resources/additional-topics/agility.markdown index feb680965..a61852498 100644 --- a/content/resources/additional-topics/agility.markdown +++ b/content/resources/additional-topics/agility.markdown @@ -603,8 +603,7 @@ details are not hard-coded, and you can make your own custom version quickly. bundle agent example { packages: - "apache2" - package_method => my_special_package_manager_interface; + "apache2" package_method => my_special_package_manager_interface; } ``` diff --git a/content/resources/additional-topics/application-management.markdown b/content/resources/additional-topics/application-management.markdown index 8eaccdb12..7739811af 100644 --- a/content/resources/additional-topics/application-management.markdown +++ b/content/resources/additional-topics/application-management.markdown @@ -125,14 +125,13 @@ promise to subscribe to the data. bundle agent example { files: - "/software_repo" - - comment => "Copy app1 updates from software server", - copy_from => remote_cp("/master_software_repo/app1/$(sys.flavour)", - "server.example.org"), - depth_search => recurse("inf"), - classes => if_repaired("newpkg_app1"); + comment => "Copy app1 updates from software server", + copy_from => remote_cp( + "/master_software_repo/app1/$(sys.flavour)", "server.example.org" + ), + depth_search => recurse("inf"), + classes => if_repaired("newpkg_app1"); } ``` @@ -149,11 +148,9 @@ CFEngine can promise to enure that a program is stopped before update: ```cf3 bundle agent example { -processes: - - newpkg_app1:: - - "app1" signals => { "term", "kill" }; + processes: + newpkg_app1:: + "app1" signals => { "term", "kill" }; } ``` @@ -165,18 +162,15 @@ version greater than 1.0.0. ```cf3 bundle agent example { -packages: - - newpkg_app1:: - - "app1" - - package_policy => "update", - package_select => ">=", - package_architectures => { "i586" }, - package_version => "1.0.0", - package_method => rpm_version("/software_repo"), - classes => if_else("app1_update", "app1_noupdate"); + packages: + newpkg_app1:: + "app1" + package_policy => "update", + package_select => ">=", + package_architectures => { "i586" }, + package_version => "1.0.0", + package_method => rpm_version("/software_repo"), + classes => if_else("app1_update", "app1_noupdate"); } ``` @@ -258,12 +252,10 @@ configuration line to a file, you might so something like this: bundle agent my_application_customize { files: - "$(prefix)/config.cf" - - comment => "Set the permissions and add a line...", - perms => mo("0600","root"), - edit_line => append_if_no_line("My custom setting..."); + comment => "Set the permissions and add a line...", + perms => mo("0600", "root"), + edit_line => append_if_no_line("My custom setting..."); } ``` @@ -273,20 +265,15 @@ To set a number of variables inside a file, you might do something like this: bundle agent my_application_customize { vars: - # want to set these values by the names of their array keys - "rhs[serverhost]" string => "123.456.789.123"; "rhs[portnumber]" string => "1234"; - "rhs[admin]" string => "admin@example.org"; + "rhs[admin]" string => "admin@example.org"; files: - "$(prefix)/config.cf" - - comment => "Add new variables or set existing ones", - edit_line => set_variable_values("setvars.rhs"); - + comment => "Add new variables or set existing ones", + edit_line => set_variable_values("setvars.rhs"); } ``` @@ -304,17 +291,14 @@ To start a service, you might do something like this: ```cf3 bundle agent example { -processes: - - "myprocess" restart_class => "start_me"; - -commands: - - start_me:: - - "/path/to/software" + processes: + "myprocess" restart_class => "start_me"; - # ... many security options, etc + commands: + start_me:: + "/path/to/software" + # ... many security options, etc + } ``` @@ -323,14 +307,12 @@ or using services ```cf3 bundle agent example { -services: - - windows:: - - "Dhcp" - service_policy => "start", - service_dependencies => { "Alerter", "W32Time" }, - service_method => winmethod; + services: + windows:: + "Dhcp" + service_policy => "start", + service_dependencies => { "Alerter", "W32Time" }, + service_method => winmethod; } ``` @@ -340,12 +322,8 @@ To stop a service, you take one of these approaches: bundle agent example { processes: - - "badprocess" - signals => { "term", "kill" }; - - "snmp" - process_stop => "/etc/init.d/snmp stop"; + "badprocess" signals => { "term", "kill" }; + "snmp" process_stop => "/etc/init.d/snmp stop"; } ``` diff --git a/content/resources/additional-topics/change-management.markdown b/content/resources/additional-topics/change-management.markdown index bf275c814..b3604e648 100644 --- a/content/resources/additional-topics/change-management.markdown +++ b/content/resources/additional-topics/change-management.markdown @@ -214,19 +214,15 @@ You promise a desired state for your system (beacon). bundle agent example { packages: - - "apache" - - comment => "Ensure Apache webserver installed", - package_policy => "add", - package_method => yum; + "apache" + comment => "Ensure Apache webserver installed", + package_policy => "add", + package_method => yum; processes: - - "apache" - - comment => "Ensure apache webserver running", - restart_class => restart_apache; + "apache" + comment => "Ensure apache webserver running", + restart_class => restart_apache; } ``` @@ -240,12 +236,10 @@ that change. bundle agent example { packages: - - "apache" - - comment => "Ensure Apache webserver up to date", - package_policy => "update", - package_method => yum; + "apache" + comment => "Ensure Apache webserver up to date", + package_policy => "update", + package_method => yum; } ``` @@ -255,11 +249,9 @@ We promise to monitor unintended changes. bundle agent example { files: - "/usr" -> "Security team" - - changes => detect_all_change, - depth_search => recurse("inf"); + changes => detect_all_change, + depth_search => recurse("inf"); } ``` @@ -269,14 +261,12 @@ Conflicts of intention are easy to see when they are mediated by CFEngine. ```cf3 bundle agent example { + files: + "/etc/passwd" -> "Security team" + perms => owner("root"); - files: - - "/etc/passwd" -> "Security team" - perms => owner("root"); - - "/etc/passwd" -> "Security team" - perms => owner("mark"); + "/etc/passwd" -> "Security team" + perms => owner("mark"); } ``` diff --git a/content/resources/additional-topics/content-driven-policy.markdown b/content/resources/additional-topics/content-driven-policy.markdown index 4567c08e0..ef410bedb 100644 --- a/content/resources/additional-topics/content-driven-policy.markdown +++ b/content/resources/additional-topics/content-driven-policy.markdown @@ -46,30 +46,29 @@ the following equivalent in the CFEngine language. bundle agent service_example { services: - "Dnscache" - comment => "Check services status of Dnscache", - handle => "srv_Dnscache_windows", - service_policy => "stop", - service_method => force_deps, - action => policy("fix"), - if => "windows"; + comment => "Check services status of Dnscache", + handle => "srv_Dnscache_windows", + service_policy => "stop", + service_method => force_deps, + action => policy("fix"), + if => "windows"; "ALG" - comment => "Check services status of ALG", - handle => "srv_ALG_windows", - service_policy => "start", - service_method => force_deps, - action => policy("warn"), - if => "windows"; + comment => "Check services status of ALG", + handle => "srv_ALG_windows", + service_policy => "start", + service_method => force_deps, + action => policy("warn"), + if => "windows"; "RemoteRegistry" - comment => "Check services status of ALG", - handle => "srv_ALG_windows", - service_policy => "start", - service_method => force_deps, - action => policy("fix"), - if => "Windows_Server_2008"; + comment => "Check services status of ALG", + handle => "srv_ALG_windows", + service_policy => "start", + service_method => force_deps, + action => policy("fix"), + if => "Windows_Server_2008"; } ``` diff --git a/content/resources/additional-topics/devops.markdown b/content/resources/additional-topics/devops.markdown index d61b05d36..dd625abaf 100644 --- a/content/resources/additional-topics/devops.markdown +++ b/content/resources/additional-topics/devops.markdown @@ -131,6 +131,7 @@ bundle agent example "affected object" # ...details.... ; + processes: "affected object" # ...details.... @@ -148,8 +149,9 @@ bundle agent some_user_defined_name "affected object/promiser" # attributes of the promise/details ; + # More promises... - # More promise types... + # More promise types... } ``` @@ -166,6 +168,7 @@ bundle agent some_user_defined_name type_of_promise: property:: "make one promise..."; + !property:: "make a different promise..."; } @@ -182,11 +185,9 @@ like, as separate promises. ```cf3 bundle agent some_user_defined_name { - classes: - - "cached_result" expression => fileexists("/some/file"); - "bigger" and => { isgreaterthan("1","0"), "cached_result" }; - + classes: + "cached_result" expression => fileexists("/some/file"); + "bigger" and => { isgreaterthan("1", "0"), "cached_result" }; } ``` @@ -202,19 +203,17 @@ classes as booleans: bundle agent some_user_defined_name { classes: - - "cached_result" expression => fileexists("/some/file"); - "bigger" and => { isgreaterthan("1","0"), "cached_result" }; + "cached_result" expression => fileexists("/some/file"); + "bigger" and => { isgreaterthan("1", "0"), "cached_result" }; reports: - bigger:: "Bigger is true...."; cached_result&!bigger:: "Mathematics seems to be awry..."; - # may also be written cached_result.!bigger:: + # may also be written cached_result.!bigger:: } ``` @@ -242,11 +241,10 @@ over each case. bundle agent example { vars: - "my_list" slist => { "one", "two", "three" }; + "my_list" slist => { "one", "two", "three" }; files: - "/tmp/file_$(my_list)" - create => "true"; + "/tmp/file_$(my_list)" create => "true"; } ``` @@ -256,16 +254,10 @@ The above evaluates to three promises: bundle agent example { files: - - "/tmp/file_one" - create => "true"; - - "/tmp/file_two" - create => "true"; - - "/tmp/file_three" - create => "true"; - } + "/tmp/file_one" create => "true"; + "/tmp/file_two" create => "true"; + "/tmp/file_three" create => "true"; +} ``` Similarly the following @@ -274,14 +266,14 @@ Similarly the following bundle agent x { vars: - "hi" string => "Hello"; - "list1" slist => { "a", "b", "c" }; - "list2" slist => { "1", "2", "3", "4" }; - "list3" slist => { "x", "y", "z" }; + "hi" string => "Hello"; + "list1" slist => { "a", "b", "c" }; + "list2" slist => { "1", "2", "3", "4" }; + "list3" slist => { "x", "y", "z" }; reports: - !silly_non_existent_context:: - "$(hi) $(list1) $(list2) $(list3)"; + !silly_non_existent_context:: + "$(hi) $(list1) $(list2) $(list3)"; } ``` @@ -338,27 +330,25 @@ calling bundle. ```cf3 body common control { -# Master execution list -bundlesequence => { "testbundle" }; + # Master execution list + bundlesequence => { "testbundle" }; } ########################################### - bundle agent testbundle { -vars: - "userlist" slist => { "one", "two", "three" }; + vars: + "userlist" slist => { "one", "two", "three" }; -methods: - "any" usebundle => subtest("$(userlist)"); + methods: + "any" usebundle => subtest("$(userlist)"); } ########################################### - bundle agent subtest(user) { -commands: - "/bin/echo Fix $(user)"; + commands: + "/bin/echo Fix $(user)"; } ``` diff --git a/content/resources/additional-topics/distributed-scheduling.markdown b/content/resources/additional-topics/distributed-scheduling.markdown index d33015f18..4dafc1c8f 100644 --- a/content/resources/additional-topics/distributed-scheduling.markdown +++ b/content/resources/additional-topics/distributed-scheduling.markdown @@ -70,18 +70,13 @@ The simplest case is to schedule the exact times. ```cf3 bundle agent workflow_one { -methods: - - Host2.Day24.January.Year2012.Hr16.Min50_55:: - - "any" usebundle => do_my_job_bundle; - -commands: - - Host1.Day24.January.Year2012.Hr16.Min45_50:: - - "/usr/local/bin/my_job"; + methods: + Host2.Day24.January.Year2012.Hr16.Min50_55:: + "any" usebundle => do_my_job_bundle; + commands: + Host1.Day24.January.Year2012.Hr16.Min45_50:: + "/usr/local/bin/my_job"; } ``` @@ -101,29 +96,23 @@ of success if the job was carried out. ```cf3 bundle agent workflow_one { -classes: - - Host2:: - - "succeeded" expression => remoteclassesmatching - ( - "did.*", # get classes matching - "Host1", # from this server - "no", # encrypt comms? - "hostX" # prefix - ); -methods: + classes: + Host2:: + "succeeded" + expression => remoteclassesmatching( + "did.*", # get classes matching + "Host1", # from this server + "no", # encrypt comms? + "hostX" # prefix + ); - Host2.hostX_did_my_job:: - - "any" usebundle => do_my_job_bundle; - -commands: - - Host1.Day24.January.Year2012.Hr16.Min45_50:: + methods: + Host2.hostX_did_my_job:: + "any" usebundle => do_my_job_bundle; - "/usr/local/bin/my_job", - classes => state_repaired("did_my_job"); + commands: + Host1.Day24.January.Year2012.Hr16.Min45_50:: + "/usr/local/bin/my_job" classes => state_repaired("did_my_job"); } ``` @@ -144,12 +133,10 @@ server side to grant access to this context information: ```cf3 bundle server my_access_rules { -access: - - "did_my_job" - - resource_type => "context", - admit => { "Host2" }; + access: + "did_my_job" + resource_type => "context", + admit => { "Host2" }; } ``` @@ -183,28 +170,19 @@ day. ```cf3 bundle agent workflow_one { -classes: + classes: + Host2:: + "succeeded" + expression => remoteclassesmatching("did.*", "Host1", "no", "hostX"); - Host2:: - - "succeeded" expression => remoteclassesmatching( - "did.*", - "Host1", - "no", - "hostX" - ); -methods: - - Host2.hostX_did_my_job:: - - "any" usebundle => do_my_job_bundle; - -commands: - - Host1.Hr16:: + methods: + Host2.hostX_did_my_job:: + "any" usebundle => do_my_job_bundle; - "/usr/local/bin/my_job", - action => if_elapsed("100"), + commands: + Host1.Hr16:: + "/usr/local/bin/my_job", + action => if_elapsed("100"), classes => state_repaired("did_my_job"); ``` @@ -217,107 +195,86 @@ might proceed. ```cf3 body common control - { -bundlesequence => { job_chain("Hr16.Min10_15") }; + bundlesequence => { job_chain("Hr16.Min10_15") }; } ######################################################## - bundle common g { -vars: - - # Define the name of the signal passed between hosts - - "signal" string => "pack_a_name"; + vars: + # Define the name of the signal passed between hosts + "signal" string => "pack_a_name"; } ######################################################## - bundle agent job_chain(time) { -vars: - + vars: # Define the names of the two parties + "client" string => "downstream.exampe.org"; + "server" string => "upstream.example.org"; - "client" string => "downstream.exampe.org"; - "server" string => "upstream.example.org"; - -classes: - + classes: # derive some classes from the names defined in variables + "client_primed" + expression => classmatch(canonify("$(client)")), + if => "$(time)"; - "client_primed" expression => classmatch(canonify("$(client)")), - if => "$(time)"; - - "server_primed" expression => classmatch(canonify("$(server)")), - if => "$(time)"; + "server_primed" + expression => classmatch(canonify("$(server)")), + if => "$(time)"; - client_primed:: + client_primed:: + "succeeded" + expression => remoteclassesmatching( + "$(g.signal)", "$(server)", "yes", "hostX" + ); - "succeeded" expression => remoteclassesmatching( - "$(g.signal)", - "$(server)", - "yes", - "hostX" - ); -methods: - - client_primed:: - - "downstream" usebundle => do_job("Starting local follow-up job"), - action => if_elapsed("5"), - if => "hostX_$(g.signal)"; - - server_primed:: - - "upstream" usebundle => do_job("Starting remote job"), - action => if_elapsed("5"), - classes => state_repaired("$(g.signal)"); - -reports: - - !succeeded:: - - "Server communication failed", - - if => "$(time)"; + methods: + client_primed:: + "downstream" + usebundle => do_job("Starting local follow-up job"), + action => if_elapsed("5"), + if => "hostX_$(g.signal)"; + + server_primed:: + "upstream" + usebundle => do_job("Starting remote job"), + action => if_elapsed("5"), + classes => state_repaired("$(g.signal)"); + + reports: + !succeeded:: + "Server communication failed" if => "$(time)"; } ######################################################### - bundle agent do_job(job) { -commands: - - # do whatever... - - "/bin/echo $(job)"; + commands: + # do whatever... + "/bin/echo $(job)"; } ######################################################### # Server config ######################################################### - body server control { -allowconnects => { "127.0.0.1" , "::1" }; -allowallconnects => { "127.0.0.1" , "::1" }; -trustkeysfrom => { "127.0.0.1" , "::1" }; -allowusers => { "mark" }; + allowconnects => { "127.0.0.1", "::1" }; + allowallconnects => { "127.0.0.1", "::1" }; + trustkeysfrom => { "127.0.0.1", "::1" }; + allowusers => { "mark" }; } ######################################################### - bundle server my_access_rules() { -access: - - "$(g.signal)" - - resource_type => "context", - admit => { "127.0.0.1" }; + access: + "$(g.signal)" + resource_type => "context", + admit => { "127.0.0.1" }; } ``` @@ -348,31 +305,22 @@ prerequisites succeeded. ```cf3 bundle agent workflow_one { -vars: + vars: + "n" slist => { "2", "3", "4" }; - "n" slist => { "2", "3", "4" }; + classes: + "succeeded$(n)" + expression => remoteclassesmatching("did.*", "Host$(n)", "no", "hostX"), + if => "Host$(n)"; -classes: - - "succeeded$(n)" expression => remoteclassesmatching( - "did.*", - "Host$(n)", - "no", - "hostX" - ), - if => "Host$(n)"; -methods: - - Host2.Host3.Host4.hostX_did_my_job:: - - "any" usebundle => do_my_job_bundle; - -commands: - - Host1.Hr16:: + methods: + Host2.Host3.Host4.hostX_did_my_job:: + "any" usebundle => do_my_job_bundle; - "/usr/local/bin/my_job", - action => if_elapsed("100"), + commands: + Host1.Hr16:: + "/usr/local/bin/my_job", + action => if_elapsed("100"), classes => state_repaired("did_my_job"); } ``` @@ -388,9 +336,7 @@ we just have to change the class expression: bundle agent example { methods: - (Host2|Host3|Host4).hostX_did_my_job:: - "any" usebundle => do_my_job_bundle; } ``` @@ -404,30 +350,21 @@ classes. ```cf3 bundle agent workflow_one { -classes: - - Host2:: - - "succeeded" expression => remoteclassesmatching( - "did.*", - "Host1", - "no", - "hostX" - ); -methods: - - Host2.hostX_did_my_job:: + classes: + Host2:: + "succeeded" + expression => remoteclassesmatching("did.*", "Host1", "no", "hostX"); - "any" usebundle => do_my_job_bundle1; - "any" usebundle => do_my_job_bundle2; - "any" usebundle => do_my_job_bundle3; - -commands: - - Host1.Hr16:: - - "/usr/local/bin/my_job", - action => if_elapsed("100"), + methods: + Host2.hostX_did_my_job:: + "any" usebundle => do_my_job_bundle1; + "any" usebundle => do_my_job_bundle2; + "any" usebundle => do_my_job_bundle3; + + commands: + Host1.Hr16:: + "/usr/local/bin/my_job", + action => if_elapsed("100"), classes => state_repaired("did_my_job"); ``` diff --git a/content/resources/additional-topics/file-content.markdown b/content/resources/additional-topics/file-content.markdown index a632b2a2a..7e24daeba 100644 --- a/content/resources/additional-topics/file-content.markdown +++ b/content/resources/additional-topics/file-content.markdown @@ -102,11 +102,9 @@ contexts. ```cf3 bundle agent something { -files: - - "/important/file" - - copy_from => secure_cp("/repository/important_file_template","svn-host"); + files: + "/important/file" + copy_from => secure_cp("/repository/important_file_template", "svn-host"); } ``` @@ -134,12 +132,10 @@ To expand a template file on a local disk: ```cf3 bundle agent templating { -files: - - "/home/mark/tmp/file_based_on_template" - - create => "true", - edit_line => expand_template("/tmp/source_template"); + files: + "/home/mark/tmp/file_based_on_template" + create => "true", + edit_line => expand_template("/tmp/source_template"); } ``` @@ -149,12 +145,10 @@ write: ```cf3 bundle agent templating { -files: - - "/home/mark/tmp/file_based_on_template" - - create => "true", - edit_template => "/tmp/source_template"; + files: + "/home/mark/tmp/file_based_on_template" + create => "true", + edit_template => "/tmp/source_template"; } ``` @@ -201,12 +195,12 @@ For example: if we use this template in a promise: bundle agent test { vars: - "var" slist => { "1", "2", "3"}; + "var" slist => { "1", "2", "3" }; files: "/tmp/expander" - create => "true", - edit_template => "/templates/input.tmpl"; + create => "true", + edit_template => "/templates/input.tmpl"; } ``` @@ -308,43 +302,42 @@ promises. This is a powerful framework. ```cf3 # Resolve conf edit - body common control { -bundlesequence => { "g", resolver(@(g.searchlist),@(g.nameservers)) }; -inputs => { "cfengine_stdlib.cf" }; + bundlesequence => { "g", resolver(@(g.searchlist), @(g.nameservers)) }; + inputs => { "cfengine_stdlib.cf" }; } bundle common g # global { -vars: - "searchlist" slist => { "example.com", "cfengine.com" }; - "nameservers" slist => { "10.1.1.10", "10.3.2.16", "8.8.8.8" }; + vars: + "searchlist" slist => { "example.com", "cfengine.com" }; + "nameservers" slist => { "10.1.1.10", "10.3.2.16", "8.8.8.8" }; -classes: - "am_name_server" - expression => reglist("@(nameservers)","$(sys.ipv4[eth1])"); + classes: + "am_name_server" + expression => reglist("@(nameservers)", "$(sys.ipv4[eth1])"); } -bundle agent resolver(s,n) +bundle agent resolver(s, n) { -files: - "$(sys.resolv)" # test on "/tmp/resolv.conf" # - create => "true", - edit_line => doresolv("@(this.s)","@(this.n)"), + files: + "$(sys.resolv)" # test on "/tmp/resolv.conf" # + create => "true", + edit_line => doresolv("@(this.s)", "@(this.n)"), edit_defaults => empty; } # For your private library ...................... - -bundle edit_line doresolv(s,n) +bundle edit_line doresolv(s, n) { -insert_lines: - "search $(s)"; - "nameserver $(n)"; -delete_lines: - # To clean out junk - "nameserver .*| search .*" not_matching => "true"; + insert_lines: + "search $(s)"; + "nameserver $(n)"; + + delete_lines: + # To clean out junk + "nameserver .*| search .*" not_matching => "true"; } ``` @@ -367,32 +360,26 @@ you can store data and template components within a CFEngine configuration itself, or as a separate file. For example: ```cf3 -# - body common control { -bundlesequence => { "main" }; -inputs => { "LapTop/cfengine/copbl/cfengine_stdlib.cf" }; + bundlesequence => { "main" }; + inputs => { "LapTop/cfengine/copbl/cfengine_stdlib.cf" }; } -# - bundle common data { -vars: - "person" string => "Mary"; - "animal" string => "a little lamb"; + vars: + "person" string => "Mary"; + "animal" string => "a little lamb"; } -# - bundle agent main { -files: - "/tmp/my_result" - create => "true", - edit_line => expand_template("/tmp/my_template_source"), - edit_defaults => empty; + files: + "/tmp/my_result" + create => "true", + edit_line => expand_template("/tmp/my_template_source"), + edit_defaults => empty; } ``` @@ -421,34 +408,29 @@ template file: ```cf3 body common control { -bundlesequence => { "main" }; -inputs => { "LapTop/cfengine/copbl/cfengine_stdlib.cf" }; + bundlesequence => { "main" }; + inputs => { "LapTop/cfengine/copbl/cfengine_stdlib.cf" }; } -# - bundle common data { -vars: - "person" string => "Mary"; - "animal" string => "a little lamb"; + vars: + "person" string => "Mary"; + "animal" string => "a little lamb"; } -# - bundle agent main { -vars: - "content" string => - "This is a file template containing variables to expand + vars: + "content" + string => "This is a file template containing variables to expand e.g $(data.person) had $(data.animal)"; -files: - - "/tmp/my_result" - create => "true", - edit_line => append_if_no_line("$(content)"), - edit_defaults => empty; + files: + "/tmp/my_result" + create => "true", + edit_line => append_if_no_line("$(content)"), + edit_defaults => empty; } ``` @@ -461,73 +443,55 @@ to be anchored somehow. ```cf3 body common control { -bundlesequence => { "main" }; -inputs => { "LapTop/cfengine/copbl/cfengine_stdlib.cf" }; + bundlesequence => { "main" }; + inputs => { "LapTop/cfengine/copbl/cfengine_stdlib.cf" }; } -# - bundle common data { -vars: - - "person" string => "Mary"; - "animal" string => "a little lamb"; - - "mylist" slist => { "one", "two", "three" }; - "clocks" slist => { "five", "six", "seven" }; - - # or read the list from a file with readstringlist() + vars: + "person" string => "Mary"; + "animal" string => "a little lamb"; + "mylist" slist => { "one", "two", "three" }; + "clocks" slist => { "five", "six", "seven" }; + # or read the list from a file with readstringlist() } -# - bundle agent main { -files: - - "/tmp/my_result" - - create => "true", - edit_line => my_expand_template, - edit_defaults => empty; + files: + "/tmp/my_result" + create => "true", + edit_line => my_expand_template, + edit_defaults => empty; } -# - bundle edit_line my_expand_template { -vars: - - # import the lists, due to current limitation - - "mylist" slist => { @(data.mylist) }; - "clocks" string => join(", ","data.clocks"); - "other" string => "eight"; - -insert_lines: + vars: + # import the lists, due to current limitation + "mylist" slist => { @(data.mylist) }; + "clocks" string => join(", ", "data.clocks"); + "other" string => "eight"; - " + insert_lines: + " This is a file template containing variables to expand e.g $(data.person) had $(data.animal) and it said: "; - - " + " $(mylist) o'clock "; - " + " ROCK! $(clocks) o'clock, $(other) o'clock "; - - " ROCK! + " ROCK! The end. - " - - insert_type => "preserve_block"; # So we keep duplicate line + " insert_type => "preserve_block"; # So we keep duplicate line } ``` @@ -559,54 +523,40 @@ insert it as a single object: ```cf3 body common control { -bundlesequence => { "main" }; -inputs => { "LapTop/cfengine/copbl/cfengine_stdlib.cf" }; + bundlesequence => { "main" }; + inputs => { "LapTop/cfengine/copbl/cfengine_stdlib.cf" }; } -# - bundle common data { -vars: - - "person" string => "Mary"; - "animal" string => "a little lamb"; - - "mylist" slist => { "one", "two", "three", "" }; - "clocks" slist => { "five", "six", "seven" }; - - # or read the list from a file with readstringlist() + vars: + "person" string => "Mary"; + "animal" string => "a little lamb"; + "mylist" slist => { "one", "two", "three", "" }; + "clocks" slist => { "five", "six", "seven" }; + # or read the list from a file with readstringlist() } -# - bundle agent main { -files: - - "/tmp/my_result" - - create => "true", - edit_line => my_expand_template, - edit_defaults => empty; + files: + "/tmp/my_result" + create => "true", + edit_line => my_expand_template, + edit_defaults => empty; } -# - bundle edit_line my_expand_template { -vars: - - # import the lists, due to current limitation - - "mylist" string => join(" o'clock$(const.n) ","data.mylist"); - "clocks" string => join(", ","data.clocks"); - "other" string => "eight"; - -insert_lines: + vars: + # import the lists, due to current limitation + "mylist" string => join(" o'clock$(const.n) ", "data.mylist"); + "clocks" string => join(", ", "data.clocks"); + "other" string => "eight"; - " + insert_lines: + " This is a file template containing variables to expand e.g $(data.person) had $(data.animal) @@ -619,8 +569,7 @@ insert_lines: ROCK! The end. " - - insert_type => "preserve_block"; # So we keep duplicate line + insert_type => "preserve_block"; # So we keep duplicate line } ``` @@ -698,12 +647,10 @@ edit_line => or edit_xml => constraint1, for instance: bundle agent example { files: - "/etc/passwd" - - create => "true", - # other constraints on file container ... - edit_line => mybundle("one","two","three"); + create => "true", + # other constraints on file container ... + edit_line => mybundle("one", "two", "three"); } ``` @@ -712,12 +659,11 @@ have a type given by the left hand side of the constraint (just like body templates): ```cf3 -bundle edit_line mybundle(arg1,arg2,arg3) +bundle edit_line mybundle(arg1, arg2, arg3) { -insert_lines: - - "newuser:x:1111:110:A new user:/home/newuser:/bin/bash"; - "$(arg1):x:$(arg2):110:$(arg3):/home/$(arg1):/bin/bash"; + insert_lines: + "newuser:x:1111:110:A new user:/home/newuser:/bin/bash"; + "$(arg1):x:$(arg2):110:$(arg3):/home/$(arg1):/bin/bash"; } ``` @@ -738,12 +684,10 @@ insert hello into a file at the end once only: bundle agent example { files: - "/tmp/test_insert" - - create => "true", + create => "true", edit_line => append_if_no_line("hello"), - edit_defaults => empty; + edit_defaults => empty; } ``` @@ -753,10 +697,9 @@ Or to set the shell for a user bundle agent example { files: - "/etc/passwd" - create => "true", - edit_line => set_user_field("mark","7","/my/favourite/shell"); + create => "true", + edit_line => set_user_field("mark", "7", "/my/favourite/shell"); } ``` @@ -807,9 +750,9 @@ bundle agent example { files: "/tmp/expander" - create => "true", - edit_template => "/home/a10004/input.dat", - edit_defaults => empty; + create => "true", + edit_template => "/home/a10004/input.dat", + edit_defaults => empty; } ``` diff --git a/content/resources/additional-topics/hierarchies.markdown b/content/resources/additional-topics/hierarchies.markdown index 1a607e7c8..28ba32249 100644 --- a/content/resources/additional-topics/hierarchies.markdown +++ b/content/resources/additional-topics/hierarchies.markdown @@ -61,12 +61,10 @@ Consider this example of CFEngine classes. It expresses a tree structure. bundle agent example { classes: - # Conceptual hierarchy - - "top" or => { "middle_1", "middle_2", "middle_3" }; - "middle_1" or => { "slave_1", "slave_2", "slave_3" }; - "middle_2" or => { "slave_4", "slave_5", "slave_6" }; + "top" or => { "middle_1", "middle_2", "middle_3" }; + "middle_1" or => { "slave_1", "slave_2", "slave_3" }; + "middle_2" or => { "slave_4", "slave_5", "slave_6" }; } ``` @@ -81,8 +79,8 @@ finance, engineering and legal departments in three countries. bundle agent example { classes: - "headquarters" or => { "usa", "uk", "norway" }; - "department" or => { "finance", "engineering", "legal" }; + "headquarters" or => { "usa", "uk", "norway" }; + "department" or => { "finance", "engineering", "legal" }; } ``` @@ -166,13 +164,9 @@ set union (OR or '|') and intersection (AND or '.'): bundle agent example { classes: - "headquarters" - or => { "usa", "uk", "norway" }; - "department" - or => { "finance", "engineering", "legal"}; - "english_speaking" - expression => "(usa|uk).!legal"; - + "headquarters" or => { "usa", "uk", "norway" }; + "department" or => { "finance", "engineering", "legal" }; + "english_speaking" expression => "(usa|uk).!legal"; } ``` @@ -242,12 +236,7 @@ of class attributes): bundle agent example { classes: - "group_name" - or => { - "base_class_1", - "base_class_2", - "base_class_3", - }; + "group_name" or => { "base_class_1", "base_class_2", "base_class_3" }; } ``` @@ -277,7 +266,6 @@ bundle agent child_bundle(parameter) reports: "Inherit parameter value $(parameter)"; "Inherit foreign scalar value $(foreign.scalar)"; - } ``` @@ -294,8 +282,7 @@ use them. bundle agent child_bundle { methods: - "extend_method" - usebundle => base_bundle(parameter1,parameter2); + "extend_method" usebundle => base_bundle(parameter1, parameter2); } ``` @@ -348,11 +335,10 @@ the set of servers: bundle agent example { classes: - "servers" - or => { "host1", "host2" }; + "servers" or => { "host1", "host2" }; processes: - servers:: # the next rules `extend` or add to the class servers + servers:: # the next rules `extend` or add to the class servers "..."; } ``` @@ -396,31 +382,30 @@ For example: bundle agent maintain_servers { classes: - "has_dhcpd" - or => { classmatch("ipv4_10_\d+_\d+_1") }; - "has_httpd" - or => { "www_example_com" }; - "has_sshd" - or => { "any" }; + "has_dhcpd" or => { classmatch("ipv4_10_\d+_\d+_1") }; + "has_httpd" or => { "www_example_com" }; + "has_sshd" or => { "any" }; processes: has_dhcpd:: - "dhcpd" - restart_class => "start_dhcpd"; + "dhcpd" restart_class => "start_dhcpd"; + has_httpd:: - "httpd" - restart_class => "start_httpd"; + "httpd" restart_class => "start_httpd"; + has_sshd:: - "sshd" - restart_class => "start_sshd"; + "sshd" restart_class => "start_sshd"; commands: freebsd.start_dhcpd:: "/usr/local/etc/rc.d/isc-dhcpd.sh start"; + start_httpd:: "/usr/local/sbin/apachectl start"; + freebsd.start_sshd:: "/etc/rc.d/sshd start"; + linux.start_sshd:: "/etc/init.d/ssh start"; } @@ -441,24 +426,24 @@ like this: bundle agent example { files: - internal.has_httpd.nyc:: - # Files maintained for internal webserver in New York + # Files maintained for internal webserver in New York external.has_httpd.nyc:: - # Files maintained for external webserver in New York + # Files maintained for external webserver in New York internal.has_httpd.london:: - # Files maintained for internal webserver in London + # Files maintained for internal webserver in London external.has_httpd.london:: - # Files maintained for external webserver in London + # Files maintained for external webserver in London internal.has_httpd.tokyo:: - # Files maintained for internal webserver in Tokyo + # Files maintained for internal webserver in Tokyo external.has_httpd.tokyo:: - # Files maintained for external webserver in Tokyo + + # Files maintained for external webserver in Tokyo } ``` diff --git a/content/resources/additional-topics/iteration.markdown b/content/resources/additional-topics/iteration.markdown index b0074edab..d4d83d510 100644 --- a/content/resources/additional-topics/iteration.markdown +++ b/content/resources/additional-topics/iteration.markdown @@ -57,13 +57,7 @@ reports: bundle agent iteration1 { vars: - "monvars" - slist => { - "rootprocs", - "otherprocs", - "diskfree", - "loadavg" - }; + "monvars" slist => { "rootprocs", "otherprocs", "diskfree", "loadavg" }; reports: cfengine_3:: @@ -100,15 +94,8 @@ The answer is simply to do another iteration: bundle agent iteration2 { vars: - "stats" - slist => { "value", "av", "dev" }; - "monvars" - slist => { - "rootprocs", - "otherprocs", - "diskfree", - "loadavg" - }; + "stats" slist => { "value", "av", "dev" }; + "monvars" slist => { "rootprocs", "otherprocs", "diskfree", "loadavg" }; reports: cfengine_3:: @@ -139,15 +126,17 @@ bundle agent iteration3a vars: "stats" slist => { "value", "av", "dev" }; "inout" slist => { "in", "out" }; - "monvars" slist => { - "rootprocs", - "otherprocs", - "diskfree", - "loadavg", - "smtp_$(inout)", # - "www_$(inout)", # look here - "wwws_$(inout)" # - }; + + "monvars" + slist => { + "rootprocs", + "otherprocs", + "diskfree", + "loadavg", + "smtp_$(inout)", # + "www_$(inout)", # look here + "wwws_$(inout)", # + }; reports: cfengine_3:: @@ -174,8 +163,7 @@ example above is exactly the same as if we had said the following: bundle agent iteration3b { vars: - "stats" - slist => { "value", "av", "dev" }; + "stats" slist => { "value", "av", "dev" }; "monvars" slist => { @@ -185,7 +173,7 @@ bundle agent iteration3b "loadavg", "smtp_in", "www_in", - "wwws_in" + "wwws_in", }; "monvars" @@ -196,7 +184,7 @@ bundle agent iteration3b "loadavg", "smtp_out", "www_out", - "wwws_out" + "wwws_out", }; reports: @@ -218,22 +206,20 @@ the reports are the second definition of the monvars list. bundle agent iteration3c { vars: - "stats" - slist => { "value", "av", "dev" }; - "inout" - slist => { "in", "out" }; + "stats" slist => { "value", "av", "dev" }; + "inout" slist => { "in", "out" }; "monvars_$(inout)" slist => { - "smtp_$(inout)", # - "www_$(inout)", # look here - "wwws_$(inout)" # + "smtp_$(inout)", # + "www_$(inout)", # look here + "wwws_$(inout)", # }; -reports: - cfengine_3:: - "mon.$(stats)_$(monvars_in) is $(mon.$(stats)_$(monvars_in))"; - "mon.$(stats)_$(monvars_out) is $(mon.$(stats)_$(monvars_out))"; + reports: + cfengine_3:: + "mon.$(stats)_$(monvars_in) is $(mon.$(stats)_$(monvars_in))"; + "mon.$(stats)_$(monvars_out) is $(mon.$(stats)_$(monvars_out))"; } ``` @@ -261,12 +247,12 @@ left-hand side, and the symbols list is only referenced in the left-hand side: ```cf3 bundle agent iteration4a { -vars: + vars: "letters" slist => { "a", "b" }; - "digits" slist => { "1", "2" }; + "digits" slist => { "1", "2" }; "symbols" slist => { "@", "#" }; -commands: + commands: "/bin/echo ${letters}, ${digits}+${digits}, " args => "${letters} and ${symbols}'"; } @@ -310,21 +296,14 @@ solve the problem of listing the input and output packet counts: bundle agent iteration5a { vars: - "stats" - slist => { "value", "av", "dev" }; - "inout" - slist => { "in", "out" }; - "io_names" - slist => { "smtp", "www", "wwws" }; - "io_vars[$(io_names)_$(inout)]" - int => "0"; + "stats" slist => { "value", "av", "dev" }; + "inout" slist => { "in", "out" }; + "io_names" slist => { "smtp", "www", "wwws" }; + "io_vars[$(io_names)_$(inout)]" int => "0"; + "monvars" slist => { - "rootprocs", - "otherprocs", - "diskfree", - "loadavg", - getindices("io_vars") + "rootprocs", "otherprocs", "diskfree", "loadavg", getindices("io_vars") }; reports: @@ -385,22 +364,13 @@ following: bundle agent iteration5b { vars: - "stats" - slist => { "value", "av", "dev" }; - "inout" - slist => { "in", "out" }; - "io_names" - slist => { "smtp", "www", "wwws" }; - "io_vars[$(io_names)_$(inout)]" - string => "$(io_names)_$(inout)"; + "stats" slist => { "value", "av", "dev" }; + "inout" slist => { "in", "out" }; + "io_names" slist => { "smtp", "www", "wwws" }; + "io_vars[$(io_names)_$(inout)]" string => "$(io_names)_$(inout)"; + "monvars" - slist => { - "rootprocs", - "otherprocs", - "diskfree", - "loadavg", - @(io_vars) - }; + slist => { "rootprocs", "otherprocs", "diskfree", "loadavg", @(io_vars) }; reports: cfengine_3:: @@ -421,10 +391,9 @@ monitoring variables available to us in CFEngine: bundle agent iteration6 { vars: - "stats" - slist => {"value", "av", "dev"}; - "inout" - slist => {"in", "out"}; + "stats" slist => { "value", "av", "dev" }; + "inout" slist => { "in", "out" }; + "io_names" slist => { "netbiosns", @@ -444,19 +413,14 @@ bundle agent iteration6 "tcpsyn", "tcpack", "tcpfin", - "tcpmisc" - }; - "io_vars[$(io_names)_$(inout)]" - string => "$(io_names)_$(inout)"; - "n" - slist => {"0", "1", "2", "3"}; - "n_names" - slist => { - "temp", - "cpu" + "tcpmisc", }; - "n_vars[$(n_names)$(n)]" - string => "$(n_names)$(n)"; + + "io_vars[$(io_names)_$(inout)]" string => "$(io_names)_$(inout)"; + "n" slist => { "0", "1", "2", "3" }; + "n_names" slist => { "temp", "cpu" }; + "n_vars[$(n_names)$(n)]" string => "$(n_names)$(n)"; + "monvars" slist => { "rootprocs", @@ -468,12 +432,12 @@ bundle agent iteration6 "syslog", "messages", getindices("io_vars"), - getindices("n_vars") + getindices("n_vars"), }; -reports: - cfengine_3:: - "mon.$(stats)_$(monvars) is $(mon.$(stats)_$(monvars))"; + reports: + cfengine_3:: + "mon.$(stats)_$(monvars) is $(mon.$(stats)_$(monvars))"; } ``` diff --git a/content/resources/additional-topics/modularity.markdown b/content/resources/additional-topics/modularity.markdown index 828f50354..ec465a094 100644 --- a/content/resources/additional-topics/modularity.markdown +++ b/content/resources/additional-topics/modularity.markdown @@ -73,23 +73,28 @@ assigned certain parts to play. ```cf3 bundle agent service_catalogue # menu { -methods: - any:: # selected by everyone - "everyone" usebundle => time_management, - comment => "Ensure clocks are synchronized"; - "everyone" usebundle => garbage_collection, - comment => "Clear junk and rotate logs"; - - mailservers:: # selected by hosts in class - "mail server" -> { "goal_3", "goal_1", "goal_2" } - usebundle => app_mail_postfix, - comment => "The mail delivery agent"; - "mail server" -> goal_3, - usebundle => app_mail_imap, - comment => "The mail reading service"; - "mail server" -> goal_3, - usebundle => app_mail_mailman, - comment => "The mailing list handler"; + methods: + any:: # selected by everyone + "everyone" + usebundle => time_management, + comment => "Ensure clocks are synchronized"; + + "everyone" + usebundle => garbage_collection, + comment => "Clear junk and rotate logs"; + + mailservers:: # selected by hosts in class + "mail server" -> { "goal_3", "goal_1", "goal_2" } + usebundle => app_mail_postfix, + comment => "The mail delivery agent"; + + "mail server" -> goal_3, + usebundle => app_mail_imap, + comment => "The mail reading service"; + + "mail server" -> goal_3, + usebundle => app_mail_mailman, + comment => "The mailing list handler"; } ``` @@ -106,12 +111,9 @@ standard methods, e.g. for editing files: ```cf3 body common control { -bundlesequence => { - webserver("on"), - dns("on"), - security_set("on"), - ftp("off") - }; + bundlesequence => { + webserver("on"), dns("on"), security_set("on"), ftp("off") + }; } ``` @@ -127,22 +129,18 @@ bundles and methods from standard libraries, or creating your own. ```cf3 bundle agent addpasswd { -vars: - - # want to set these values by the names of their array keys - - "pwd[mark]" string => "mark:x:1000:100:Mark B:/home/mark:/bin/bash"; - "pwd[fred]" string => "fred:x:1001:100:Right Said:/home/fred:/bin/bash"; - "pwd[jane]" string => "jane:x:1002:100:Jane Doe:/home/jane:/bin/bash"; - -files: - - "/etc/passwd" # Use standard library functions - create => "true", - comment => "Ensure listed users are present", - perms => mog("644","root","root"), - edit_line => append_users_starting("addpasswd.pwd"); - + vars: + # want to set these values by the names of their array keys + "pwd[mark]" string => "mark:x:1000:100:Mark B:/home/mark:/bin/bash"; + "pwd[fred]" string => "fred:x:1001:100:Right Said:/home/fred:/bin/bash"; + "pwd[jane]" string => "jane:x:1002:100:Jane Doe:/home/jane:/bin/bash"; + + files: + "/etc/passwd" # Use standard library functions + create => "true", + comment => "Ensure listed users are present", + perms => mog("644", "root", "root"), + edit_line => append_users_starting("addpasswd.pwd"); } ``` @@ -187,12 +185,9 @@ and off on your basic "stem cell" machines. ```cf3 body agent control { -bundlesequence => { - webserver("on"), - dns("on"), - security_set("on"), - ftp("off") - }; + bundlesequence => { + webserver("on"), dns("on"), security_set("on"), ftp("off") + }; } ``` @@ -212,19 +207,16 @@ said process once its absence has been discovered and signalled. ```cf3 bundle agent application_services { -processes: - - "sshd" restart_class => "start_ssh"; - "httpd" restart_class => "start_spache"; - -commands: + processes: + "sshd" restart_class => "start_ssh"; + "httpd" restart_class => "start_spache"; - start_ssh:: - "/etc/init.d/sshd restart"; - - start_apache:: - "/etc/init.d/apache restart"; + commands: + start_ssh:: + "/etc/init.d/sshd restart"; + start_apache:: + "/etc/init.d/apache restart"; } ``` @@ -235,18 +227,12 @@ of transparency. However, this is the power of abstraction. ```cf3 bundle agent application_services { -vars: - - "service" slist => { "ssh", "apache", "mysql" }; - - # - # Apply the following promises to this list... - # - -services: - - "$(service)"; + vars: + "service" slist => { "ssh", "apache", "mysql" }; + # Apply the following promises to this list... + services: + "$(service)"; } ``` @@ -266,29 +252,24 @@ is simple. Elsewhere we have defined basic settings. ```cf3 bundle common res # abstraction layer { -vars: - - solaris:: - - "cfg_file[ssh]" string => "/etc/sshd_config"; - "daemon[ssh] " string => "sshd"; - "start[ssh] " string => "/etc/init.d/sshd restart"; - - linux.SuSE:: - - "cfg_file[ssh]" string => "/etc/ssh/sshd_config"; - "daemon[ssh] " string => "sshd"; - "start[ssh] " string => "/etc/init.d/sshd restart"; - - default:: - - "cfg_file[ssh]" string => "/etc/sshd_config"; - "daemon[ssh] " string => "sshd"; - "start[ssh] " string => "/etc/init.d/sshd restart"; - -classes: - - "default" and => { "!SuSE", "solaris" }; + vars: + solaris:: + "cfg_file[ssh]" string => "/etc/sshd_config"; + "daemon[ssh] " string => "sshd"; + "start[ssh] " string => "/etc/init.d/sshd restart"; + + linux.SuSE:: + "cfg_file[ssh]" string => "/etc/ssh/sshd_config"; + "daemon[ssh] " string => "sshd"; + "start[ssh] " string => "/etc/init.d/sshd restart"; + + default:: + "cfg_file[ssh]" string => "/etc/sshd_config"; + "daemon[ssh] " string => "sshd"; + "start[ssh] " string => "/etc/init.d/sshd restart"; + + classes: + "default" and => { "!SuSE", "solaris" }; } ``` @@ -308,11 +289,13 @@ things look simple. Using CFEngine, you can create convergent orchestration. ```cf3 bundle agent services { -vars: - "service" slist => { "dhcp", "ntp", "sshd" }; -methods: - "any" usebundle => fix_service("$(service)"), - comment => "Make sure the basic application services are running"; + vars: + "service" slist => { "dhcp", "ntp", "sshd" }; + + methods: + "any" + usebundle => fix_service("$(service)"), + comment => "Make sure the basic application services are running"; } ``` @@ -329,32 +312,23 @@ versions, you can trace these comments to see your process details. ```cf3 bundle agent fix_service(service) { -files: - - "$(res.cfg_file[$(service)])" - - # - # reserved_word => use std templates, e.g. cp(), p(), or roll your own - # - copy_from => cp("$(g.masterfiles)/$(service)","policy_host.mydomain"), - perms => p("0600","root","root"), - classes => define("$(service)_restart", "failed"), - comment => "Copy a stock configuration file template from repository"; - -processes: - - "$(res.daemon[$(service)])" - - restart_class => canonify("$(service)_restart"), - comment => "Check that the server process is running..."; - -commands: - - "$(res.start[$(service)])" - - comment => "Method for starting this service", - if => canonify("$(service)_restart"); - + files: + "$(res.cfg_file[$(service)])" + # reserved_word => use std templates, e.g. cp(), p(), or roll your own + copy_from => cp("$(g.masterfiles)/$(service)", "policy_host.mydomain"), + perms => p("0600", "root", "root"), + classes => define("$(service)_restart", "failed"), + comment => "Copy a stock configuration file template from repository"; + + processes: + "$(res.daemon[$(service)])" + restart_class => canonify("$(service)_restart"), + comment => "Check that the server process is running..."; + + commands: + "$(res.start[$(service)])" + comment => "Method for starting this service", + if => canonify("$(service)_restart"); } ``` @@ -366,32 +340,26 @@ can extend this kind of pattern to implement other interfaces, all without low level programming. ```cf3 -# # Remove certain services from xinetd - for system hardening -# - bundle agent linux_harden_methods { -vars: - - "services" slist => { - "chargen", - "chargen-udp", - "cups-lpd", - "finger", - "rlogin", - "rsh", - "talk", - "telnet", - "tftp" - }; -methods: - - # + vars: + "services" + slist => { + "chargen", + "chargen-udp", + "cups-lpd", + "finger", + "rlogin", + "rsh", + "talk", + "telnet", + "tftp", + }; + + methods: # for each $(services) in @(services) do disable_xinetd($(services)) - # - - "any" usebundle => disable_xinetd("$(services)"); + "any" usebundle => disable_xinetd("$(services)"); } ``` @@ -400,32 +368,26 @@ implementing service disablement. For example, this simple interface to Linux's chkconfig is one approach, which need not be hard-coded in Ruby using Cfeninge. ```cf3 -# # For the standard library -# - bundle agent disable_xinetd(name) { -vars: - "status" + vars: + "status" string => execresult("/sbin/chkconfig --list $(name)", "useshell"); - string => execresult("/sbin/chkconfig --list $(name)", "useshell"); + classes: + "on" expression => regcmp(".*on", "$(status)"); + "off" expression => regcmp(".*off", "$(status)"); -classes: - "on" expression => regcmp(".*on","$(status)"); - "off" expression => regcmp(".*off","$(status)"); + commands: + on:: + "/sbin/chkconfig $(name) off" comment => "disable $(name) service"; -commands: - on:: - "/sbin/chkconfig $(name) off", - comment => "disable $(name) service"; - -reports: - on:: + reports: + on:: "disable $(name) service."; - off:: - "$(name) has been already disabled. Don't need to perform the action."; + off:: + "$(name) has been already disabled. Don't need to perform the action."; } ``` @@ -460,7 +422,7 @@ is the master bundlesequence ```cf3 body common control { -bundlesequence => { "bundle_one", "bundle_two", "bundle_three" }; + bundlesequence => { "bundle_one", "bundle_two", "bundle_three" }; } ``` @@ -478,12 +440,11 @@ _execute_ these bundles in the assumed order: ```cf3 bundle agent a_bundle_subsequence { -methods: - classes:: - "any" usebundle => bundle_one("something"); - "any" usebundle => bundle_two("something"); - "any" usebundle => bundle_three("something"); - + methods: + classes:: + "any" usebundle => bundle_one("something"); + "any" usebundle => bundle_two("something"); + "any" usebundle => bundle_three("something"); } ``` @@ -492,12 +453,11 @@ Alternatively, the same effect can be achieved as follows. ```cf3 bundle agent a_bundle_subsequence { -methods: - classes:: - "any" usebundle => generic_bundle("something","one"); - "any" usebundle => generic_bundle("something","two"); - "any" usebundle => generic_bundle("something","three"); - + methods: + classes:: + "any" usebundle => generic_bundle("something", "one"); + "any" usebundle => generic_bundle("something", "two"); + "any" usebundle => generic_bundle("something", "three"); } ``` @@ -506,13 +466,12 @@ Or ultimately: ```cf3 bundle agent a_bundle_subsequence { -vars: - "list" slist => { "one", "two", "three"}; - -methods: - classes:: - "any" usebundle => generic_bundle("something","$(list)"); + vars: + "list" slist => { "one", "two", "three" }; + methods: + classes:: + "any" usebundle => generic_bundle("something", "$(list)"); } ``` @@ -526,23 +485,18 @@ humans, as in this example: ```cf3 bundle agent order - { -vars: - - "list" slist => { "three", "four" }; - -commands: - - ok_later:: - "/bin/echo five"; + vars: + "list" slist => { "three", "four" }; - any:: - - "/bin/echo one" classes => define("ok_later"); - "/bin/echo two"; - "/bin/echo $(list)"; + commands: + ok_later:: + "/bin/echo five"; + any:: + "/bin/echo one" classes => define("ok_later"); + "/bin/echo two"; + "/bin/echo $(list)"; } ``` @@ -585,61 +539,55 @@ remoteclassesmatching imports the classes, with a prefix to the local system. ```cf3 body common control { -bundlesequence => { "overture" }; -inputs => { "cfengine_stdlib.cf" }; + bundlesequence => { "overture" }; + inputs => { "cfengine_stdlib.cf" }; } body server control - { -allowconnects => { "127.0.0.1" , "::1",}; -allowallconnects => { "127.0.0.1" , "::1", }; -trustkeysfrom => { "127.0.0.1" , "::1",}; + allowconnects => { "127.0.0.1", "::1" }; + allowallconnects => { "127.0.0.1", "::1" }; + trustkeysfrom => { "127.0.0.1", "::1" }; } ####################################################### - bundle agent overture { -classes: - "extended_context" - expression => remoteclassesmatching(".*did.*","127.0.0.1","yes","got"); - -files: - - "/etc/passwd" - create => "true", - classes => set_outcome_classes; - -reports: + classes: + "extended_context" + expression => remoteclassesmatching(".*did.*", "127.0.0.1", "yes", "got"); - got_did_task_one:: - "task 1 complete"; + files: + "/etc/passwd" + create => "true", + classes => set_outcome_classes; - extended_context.got_did_task_two:: - "task 2 complete"; + reports: + got_did_task_one:: + "task 1 complete"; - extended_context.got_did_task_three:: - "task 3 complete"; + extended_context.got_did_task_two:: + "task 2 complete"; + extended_context.got_did_task_three:: + "task 3 complete"; } body classes set_outcome_classes { -promise_kept => { "did_task_one","did_task_two", "did_task_three" }; -promise_repaired => { "did_task_one","did_task_two", "did_task_three" }; -#cancel_kept => { "did_task_one" }; -persist_time => "10"; + promise_kept => { "did_task_one", "did_task_two", "did_task_three" }; + promise_repaired => { "did_task_one", "did_task_two", "did_task_three" }; + + #cancel_kept => { "did_task_one" }; + persist_time => "10"; } bundle server my_access_rules() { -access: - - "did.*" - resource_type => "context", - admit => { "127.0.0.1" }; - + access: + "did.*" + resource_type => "context", + admit => { "127.0.0.1" }; } ``` @@ -665,66 +613,52 @@ bundle with a handle that matches the requested object. ```cf3 body common control { -bundlesequence => { "overture" }; -inputs => { "cfengine_stdlib.cf" }; + bundlesequence => { "overture" }; + inputs => { "cfengine_stdlib.cf" }; } body server control - { -allowconnects => { "127.0.0.1" , "::1",}; -allowallconnects => { "127.0.0.1" , "::1", }; -trustkeysfrom => { "127.0.0.1" , "::1",}; + allowconnects => { "127.0.0.1", "::1" }; + allowallconnects => { "127.0.0.1", "::1" }; + trustkeysfrom => { "127.0.0.1", "::1" }; } ####################################################### - bundle agent overture { -vars: - - "remote" string => remotescalar("test_scalar","127.0.0.1","yes"); - - "know" string => hubknowledge("test_scalar"); - - "count_getty" string => hubknowledge("count_getty"); - -processes: - - # Use the enumerated library body to count hosts running getty - - "getty" - - comment => "Count this host if a job is matched", - classes => enumerate("count_getty"); - -reports: - - !elsewhere:: - - "GOT remote scalar $(remote)"; - "GOT knowedge scalar $(know)"; - "GOT persistent scalar $(xyz)"; - + vars: + "remote" string => remotescalar("test_scalar", "127.0.0.1", "yes"); + "know" string => hubknowledge("test_scalar"); + "count_getty" string => hubknowledge("count_getty"); + + processes: + # Use the enumerated library body to count hosts running getty + "getty" + comment => "Count this host if a job is matched", + classes => enumerate("count_getty"); + + reports: + !elsewhere:: + "GOT remote scalar $(remote)"; + "GOT knowedge scalar $(know)"; + "GOT persistent scalar $(xyz)"; } ####################################################### - bundle server my_access_rules() { -access: - - "value of my test_scalar, can expand variables here - $(sys.host)" - handle => "test_scalar", - comment => "Grant access to contents of test_scalar VAR", - resource_type => "literal", - admit => { "127.0.0.1" }; - - "XYZ" - resource_type => "variable", - handle => "XYZ", - admit => { "127.0.0.1" }; - + access: + "value of my test_scalar, can expand variables here - $(sys.host)" + handle => "test_scalar", + comment => "Grant access to contents of test_scalar VAR", + resource_type => "literal", + admit => { "127.0.0.1" }; + + "XYZ" + resource_type => "variable", + handle => "XYZ", + admit => { "127.0.0.1" }; } ``` @@ -771,55 +705,44 @@ of erring on the side of caution. # to add host1 host2 host3 host4 as aliases to localhost # ############################################################ - body common control { -bundlesequence => { "n_of_m_symphony" }; -inputs => { "cfengine_stdlib.cf" }; + bundlesequence => { "n_of_m_symphony" }; + inputs => { "cfengine_stdlib.cf" }; } ############################################################ - bundle agent n_of_m_symphony { -vars: - - "count_compliant_hosts" string => hubknowledge("running_myprocess"); - -classes: - - "reboot" expression => isgreaterthan("$(count_compliant_hosts)","20"); - -processes: + vars: + "count_compliant_hosts" string => hubknowledge("running_myprocess"); - "myprocess" + classes: + "reboot" expression => isgreaterthan("$(count_compliant_hosts)", "20"); - comment => "Count this host if a job is matched", - classes => enumerate("running_myprocess"); + processes: + "myprocess" + comment => "Count this host if a job is matched", + classes => enumerate("running_myprocess"); -commands: - - reboot:: - - "/bin/shutdown now"; + commands: + reboot:: + "/bin/shutdown now"; } ####################################################### - bundle server my_access_rules() { -access: - - "value of my test_scalar, can expand variables here - $(sys.host)" - handle => "test_scalar", - comment => "Grant access to contents of test_scalar VAR", - resource_type => "literal", - admit => { "127.0.0.1" }; - - "running_myprocess" - resource_type => "variable", - admit => { "127.0.0.1" }; - + access: + "value of my test_scalar, can expand variables here - $(sys.host)" + handle => "test_scalar", + comment => "Grant access to contents of test_scalar VAR", + resource_type => "literal", + admit => { "127.0.0.1" }; + + "running_myprocess" + resource_type => "variable", + admit => { "127.0.0.1" }; } ``` @@ -851,125 +774,111 @@ self-healing is optional if one trusts the underlying system. # to add host1 host2 host3 host4 as aliases to localhost # ############################################################ - body common control { -bundlesequence => { "weak_dependency_symphony" }; -inputs => { "cfengine_stdlib.cf" }; + bundlesequence => { "weak_dependency_symphony" }; + inputs => { "cfengine_stdlib.cf" }; } body server control { -allowconnects => { "127.0.0.1" , "::1", @(def.acl) }; -allowallconnects => { "127.0.0.1" , "::1", @(def.acl) }; + allowconnects => { "127.0.0.1", "::1", @(def.acl) }; + allowallconnects => { "127.0.0.1", "::1", @(def.acl) }; } ############################################################ - bundle agent weak_dependency_symphony { -methods: - - # We have to seed the beginning by creating the tower - # /tmp/tower_localhost - - host1:: - "tower" usebundle => tier1, - classes => publish_ok("ok_O"); - - host2:: - "tower" usebundle => tier2, - classes => publish_ok("ok_1"); - - host3:: - "tower" usebundle => tier3, - classes => publish_ok("ok_2"); - - host4:: - "tower" usebundle => tier4, - classes => publish_ok("ok_f"); - -classes: - - ok_O:: # Wait for the methods, report on host1 only - - "check1" expression => remoteclassesmatching("ok.*","host2","yes","a"); - "check2" expression => remoteclassesmatching("ok.*","host3","yes","a"); - "check3" expression => remoteclassesmatching("ok.*","host4","yes","a"); - -reports: - - ok_O:: - "tier 1 is ok"; - a_ok_1:: - "tier 2 is ok"; - a_ok_2:: - "tier 3 is ok"; - a_ok_f:: - "tier 4 is ok"; - - ok_O&a_ok_1&a_ok_2&a_ok_f:: - "The Tower is standing"; - - !(ok_O&a_ok_1&a_ok_2&a_ok_f):: - "The Tower is down"; + methods: + # We have to seed the beginning by creating the tower + # /tmp/tower_localhost + host1:: + "tower" + usebundle => tier1, + classes => publish_ok("ok_O"); + + host2:: + "tower" + usebundle => tier2, + classes => publish_ok("ok_1"); + + host3:: + "tower" + usebundle => tier3, + classes => publish_ok("ok_2"); + + host4:: + "tower" + usebundle => tier4, + classes => publish_ok("ok_f"); + + classes: + ok_O:: # Wait for the methods, report on host1 only + "check1" expression => remoteclassesmatching("ok.*", "host2", "yes", "a"); + "check2" expression => remoteclassesmatching("ok.*", "host3", "yes", "a"); + "check3" expression => remoteclassesmatching("ok.*", "host4", "yes", "a"); + + reports: + ok_O:: + "tier 1 is ok"; + + a_ok_1:: + "tier 2 is ok"; + + a_ok_2:: + "tier 3 is ok"; + + a_ok_f:: + "tier 4 is ok"; + + ok_O&a_ok_1&a_ok_2&a_ok_f:: + "The Tower is standing"; + + !(ok_O&a_ok_1&a_ok_2&a_ok_f):: + "The Tower is down"; } ############################################################ - bundle agent tier1 { -files: - - "/tmp/something_to_do_1" - create => "true"; + files: + "/tmp/something_to_do_1" create => "true"; } bundle agent tier2 { -files: - - "/tmp/something_to_do_2" - create => "true"; + files: + "/tmp/something_to_do_2" create => "true"; } bundle agent tier3 { -files: - - "/tmp/something_to_do_3" - create => "true"; - + files: + "/tmp/something_to_do_3" create => "true"; } bundle agent tier4 { -files: - - "/tmp/something_to_do_4" - create => "true"; + files: + "/tmp/something_to_do_4" create => "true"; } ############################################################ - bundle server my_access_rules() { -access: - - "ok.*" - resource_type => "context", - admit => { "127.0.0.1" }; - + access: + "ok.*" + resource_type => "context", + admit => { "127.0.0.1" }; } ############################################################ - body classes publish_ok(x) { -promise_repaired => { "$(x)" }; -promise_kept => { "$(x)" }; -cancel_notkept => { "$(x)" }; -persist_time => "2"; + promise_repaired => { "$(x)" }; + promise_kept => { "$(x)" }; + cancel_notkept => { "$(x)" }; + persist_time => "2"; } ``` @@ -1039,144 +948,112 @@ the example. # to add host1 host2 host3 host4 as aliases to localhost # ############################################################ - body common control { -bundlesequence => { "dominoes_symphony" }; -inputs => { "cfengine_stdlib.cf" }; + bundlesequence => { "dominoes_symphony" }; + inputs => { "cfengine_stdlib.cf" }; } ############################################################ - bundle agent dominoes_symphony { -methods: - - # We have to seed the beginning by creating the dominoes - # /tmp/dominoes_localhost - - host1:: - "dominoes" usebundle => hand_over("localhost","host1","overture"); - - host2:: - "dominoes" usebundle => hand_over("host1","host2","first_movement"); - - host3:: - "dominoes" usebundle => hand_over("host2","host3","second_movement"); - - host4:: - "dominoes" usebundle => hand_over("host3","host4","final_movement"), - classes => if_ok("finale"); - -reports: - - finale:: - - "The visitors book of the Dominoes method" - printfile => visitors_book("/tmp/dominoes_host4"); - + methods: + # We have to seed the beginning by creating the dominoes + # /tmp/dominoes_localhost + host1:: + "dominoes" usebundle => hand_over("localhost", "host1", "overture"); + + host2:: + "dominoes" usebundle => hand_over("host1", "host2", "first_movement"); + + host3:: + "dominoes" usebundle => hand_over("host2", "host3", "second_movement"); + + host4:: + "dominoes" + usebundle => hand_over("host3", "host4", "final_movement"), + classes => if_ok("finale"); + + reports: + finale:: + "The visitors book of the Dominoes method" + printfile => visitors_book("/tmp/dominoes_host4"); } ############################################################ - -bundle agent hand_over(predecessor,myalias,method) +bundle agent hand_over(predecessor, myalias, method) { - - # This is a wrapper for the orchestration - -files: - - "/tmp/tip_the_dominoes" - - comment => "Wait for our cue or relay/conductor baton", - copy_from => secure_cp("/tmp/dominoes_$(predecessor)","$(predecessor)"), - classes => if_repaired("cue_action"); - -methods: - - cue_action:: - - "the music happens" - - comment => "One off activity", - usebundle => $(method), - classes => if_ok("pass_the_stick"); - -files: - - pass_the_stick:: - - "/tmp/tip_the_dominoes" - comment => "Add our signature to the dominoes's tail", - edit_line => append_if_no_line("Knocked over $(myalias) and did: $(method)"); - - "/tmp/dominoes_$(myalias)" - - comment => "Dominoes in position to be beamed up by next agent", - copy_from => local_cp("/tmp/tip_the_dominoes"); - + # This is a wrapper for the orchestration + files: + "/tmp/tip_the_dominoes" + comment => "Wait for our cue or relay/conductor baton", + copy_from => secure_cp("/tmp/dominoes_$(predecessor)", "$(predecessor)"), + classes => if_repaired("cue_action"); + + methods: + cue_action:: + "the music happens" + comment => "One off activity", + usebundle => $(method), + classes => if_ok("pass_the_stick"); + + files: + pass_the_stick:: + "/tmp/tip_the_dominoes" + comment => "Add our signature to the dominoes's tail", + edit_line => append_if_no_line( + "Knocked over $(myalias) and did: $(method)" + ); + + "/tmp/dominoes_$(myalias)" + comment => "Dominoes in position to be beamed up by next agent", + copy_from => local_cp("/tmp/tip_the_dominoes"); } ############################################################ - bundle agent overture { -reports: - - !xyz:: - - "Singing the overture..."; + reports: + !xyz:: + "Singing the overture..."; } bundle agent first_movement { -reports: - - !xyz:: - - "Singing the first adagio..."; + reports: + !xyz:: + "Singing the first adagio..."; } bundle agent second_movement { -reports: - - !xyz:: - - "Singing second allegro..."; - + reports: + !xyz:: + "Singing second allegro..."; } bundle agent final_movement { -reports: - - !xyz:: - - "Trumpets for the finale"; - + reports: + !xyz:: + "Trumpets for the finale"; } ############################################################ - bundle server my_access_rules() { -access: - - "/tmp" - - admit => { "127.0.0.1" }; - - "did.*" - resource_type => "context", - admit => { "127.0.0.1" }; + access: + "/tmp" admit => { "127.0.0.1" }; + "did.*" + resource_type => "context", + admit => { "127.0.0.1" }; } body printfile visitors_book(file) { -file_to_print => "$(file)"; -number_of_lines => "10"; + file_to_print => "$(file)"; + number_of_lines => "10"; } ``` @@ -1229,225 +1106,179 @@ reinstating them and moving on to the next host. # to add host1 host2 host3 host4 as aliases to localhost # ############################################################ - body common control { -bundlesequence => { "dragon_symphony" }; -inputs => { "cfengine_stdlib.cf" }; + bundlesequence => { "dragon_symphony" }; + inputs => { "cfengine_stdlib.cf" }; } ############################################################ - bundle agent dragon_symphony { -methods: - - # We have to seed the beginning by creating the dragon - # /tmp/dragon_localhost - - "dragon" usebundle => visit("localhost","host1","chapter1"); - - "dragon" usebundle => visit("host1","host2","chapter2"); - - "dragon" usebundle => visit("host2","host3","chapter3"); - - "dragon" usebundle => visit("host3","host4","chapter4"), - classes => if_ok("finale"); - -reports: - - finale:: - - "The dragon is slain:" - printfile => visitors_book("/tmp/shoo_dragon_host4"); + methods: + # We have to seed the beginning by creating the dragon + # /tmp/dragon_localhost + "dragon" usebundle => visit("localhost", "host1", "chapter1"); + "dragon" usebundle => visit("host1", "host2", "chapter2"); + "dragon" usebundle => visit("host2", "host3", "chapter3"); + + "dragon" + usebundle => visit("host3", "host4", "chapter4"), + classes => if_ok("finale"); + + reports: + finale:: + "The dragon is slain:" + printfile => visitors_book("/tmp/shoo_dragon_host4"); } ############################################################ # Define the ############################################################ - bundle agent chapter1(x) { -# Do something significant here - -reports: - - host1:: - " ----> Breathing fire on $(x)"; + # Do something significant here + reports: + host1:: + " ----> Breathing fire on $(x)"; } ################################ - bundle agent chapter2(x) { -# Do something significant here - -reports: - - host2:: - " ----> Breathing fire on $(x)"; - + # Do something significant here + reports: + host2:: + " ----> Breathing fire on $(x)"; } ################################ - bundle agent chapter3(x) { -# Do something significant here - -reports: - - host3:: - " ----> Breathing fire on $(x)"; - + # Do something significant here + reports: + host3:: + " ----> Breathing fire on $(x)"; } ################################ - bundle agent chapter4(x) { -# Do something significant here - -reports: - - host4:: - " ----> Breathing fire on $(x)"; - + # Do something significant here + reports: + host4:: + " ----> Breathing fire on $(x)"; } ############################################################ # Orchestration wrappers ############################################################ - -bundle agent visit(predecessor,satellite,method) +bundle agent visit(predecessor, satellite, method) { - - # This is a wrapper for the orchestration will be acted on - # first by the dragon's lair and then by the satellite - -vars: - - "dragons_lair" string => "host0"; - -files: - - # We start in the dragon's lair .. - - "/tmp/unleash_dragon" - - comment => "Unleash the dragon", + # This is a wrapper for the orchestration will be acted on + # first by the dragon's lair and then by the satellite + vars: + "dragons_lair" string => "host0"; + + files: + # We start in the dragon's lair .. + "/tmp/unleash_dragon" + comment => "Unleash the dragon", rename => to("/tmp/enter_the_dragon"), - classes => if_repaired("dispatch_dragon_$(satellite)"), - if => "$(dragons_lair)"; - - # if we are the dragon's lair, welcome the dragon back, shooed from the satellite - - "/tmp/enter_the_dragon" - - comment => "Returning from a visit to a satellite", - copy_from => secure_cp("/tmp/shoo_dragon_$(predecessor)","$(predecessor)"), - classes => if_repaired("dispatch_dragon_$(satellite)"), - if => "$(dragons_lair)"; - - # If we are a satellite, receive the dragon from its lair - - "/tmp/enter_the_dragon" - comment => "Wait for our cue or relay/conductor baton", - copy_from => secure_cp("/tmp/dragon_$(satellite)","$(dragons_lair)"), - classes => if_repaired("cue_action_on_$(satellite)"), - if => "$(satellite)"; - -methods: - - "check in at home" - comment => "Edit the load balancer?", + classes => if_repaired("dispatch_dragon_$(satellite)"), + if => "$(dragons_lair)"; + + # if we are the dragon's lair, welcome the dragon back, shooed from the satellite + "/tmp/enter_the_dragon" + comment => "Returning from a visit to a satellite", + copy_from => secure_cp( + "/tmp/shoo_dragon_$(predecessor)", "$(predecessor)" + ), + classes => if_repaired("dispatch_dragon_$(satellite)"), + if => "$(dragons_lair)"; + + # If we are a satellite, receive the dragon from its lair + "/tmp/enter_the_dragon" + comment => "Wait for our cue or relay/conductor baton", + copy_from => secure_cp("/tmp/dragon_$(satellite)", "$(dragons_lair)"), + classes => if_repaired("cue_action_on_$(satellite)"), + if => "$(satellite)"; + + methods: + "check in at home" + comment => "Edit the load balancer?", usebundle => switch_satellite(" -> Send dragon to $(satellite)"), - classes => if_repaired("send_the_dragon_to_$(satellite)"), - if => "dispatch_dragon_$(satellite)"; + classes => if_repaired("send_the_dragon_to_$(satellite)"), + if => "dispatch_dragon_$(satellite)"; - "dragon visits" - comment => "One off activity that the nodes carry out while the dragon visits", + "dragon visits" + comment => "One off activity that the nodes carry out while the dragon visits", usebundle => $(method)("$(satellite)"), - classes => if_repaired("send_the_dragon_back_from_$(satellite)"), - if => "cue_action_on_$(satellite)"; - -files: - - # hub/lair hub signs the book too and schedules the dragon for next satellite - - "/tmp/dragon_$(satellite)" - create => "true", - comment => "Add our signature to the dragon's tail", + classes => if_repaired("send_the_dragon_back_from_$(satellite)"), + if => "cue_action_on_$(satellite)"; + + files: + # hub/lair hub signs the book too and schedules the dragon for next satellite + "/tmp/dragon_$(satellite)" + create => "true", + comment => "Add our signature to the dragon's tail", edit_line => sign_visitor_book("Dragon returned from $(predecessor)"), - if => "send_the_dragon_to_$(satellite)"; - - # Satellite signs the book and shoos dragon for hub to collect - - "/tmp/shoo_dragon_$(satellite)" - create => "true", - comment => "Add our signature to the dragon's tail", - edit_line => sign_visitor_book("Dragon visited $(satellite) and did: $(method)"), - if => "send_the_dragon_back_from_$(satellite)"; - -reports: - - !xyz:: - - "Done $(satellite)"; - + if => "send_the_dragon_to_$(satellite)"; + + # Satellite signs the book and shoos dragon for hub to collect + "/tmp/shoo_dragon_$(satellite)" + create => "true", + comment => "Add our signature to the dragon's tail", + edit_line => sign_visitor_book( + "Dragon visited $(satellite) and did: $(method)" + ), + if => "send_the_dragon_back_from_$(satellite)"; + + reports: + !xyz:: + "Done $(satellite)"; } ############################################################ - bundle agent switch_satellite(name) { -files: - - "/tmp/enter_the_dragon" - comment => "Add our signature to the dragon's tail", + files: + "/tmp/enter_the_dragon" + comment => "Add our signature to the dragon's tail", edit_line => append_if_no_line("Switch new dragon's target $(name)"); -reports: - - !xyz:: - " X Switching new dragon's target $(name)"; + reports: + !xyz:: + " X Switching new dragon's target $(name)"; } ############################################################ - bundle edit_line sign_visitor_book(s) { -insert_lines: + insert_lines: + "/tmp/enter_the_dragon" + comment => "Import the current visitor's book", + insert_type => "file"; - "/tmp/enter_the_dragon" - comment => "Import the current visitor's book", - insert_type => "file"; - - "$(s)" comment => "Append this string to the visitor's book"; + "$(s)" comment => "Append this string to the visitor's book"; } ############################################################ - bundle server my_access_rules() { -access: - - "/tmp" - - admit => { "127.0.0.1" }; - - "did.*" - resource_type => "context", - admit => { "127.0.0.1" }; + access: + "/tmp" admit => { "127.0.0.1" }; + "did.*" + resource_type => "context", + admit => { "127.0.0.1" }; } ############################################################ - body printfile visitors_book(file) { -file_to_print => "$(file)"; -number_of_lines => "100"; + file_to_print => "$(file)"; + number_of_lines => "100"; } ``` diff --git a/content/resources/additional-topics/orchestration.markdown b/content/resources/additional-topics/orchestration.markdown index 7ea53e356..2e5321072 100644 --- a/content/resources/additional-topics/orchestration.markdown +++ b/content/resources/additional-topics/orchestration.markdown @@ -203,22 +203,20 @@ by an enterprise-wide global infrastructure service. ![Independent configurations using a common baseline](./fed2.png) ```cf3 -# # Federated promises.cf -# - bundle agent main { files: "$(sys.workdir)/inputs/baseline.cf" copy_from => remote_cp( - "/masterfiles/baseline.cf", - "central_service.example.com", + "/masterfiles/baseline.cf", "central_service.example.com", ); + methods: # Inherit the baseline constitution "baseline" usebundle => company_baseline; - # All other local promises here .... + + # All other local promises here .... } ``` diff --git a/content/resources/additional-topics/security.markdown b/content/resources/additional-topics/security.markdown index 4accf9f34..65939367c 100644 --- a/content/resources/additional-topics/security.markdown +++ b/content/resources/additional-topics/security.markdown @@ -429,15 +429,10 @@ bundle agent change_management { vars: "watch_files" - slist => { - "/etc/passwd", - "/etc/shadow", - "/etc/group", - "/etc/services" - }; + slist => { "/etc/passwd", "/etc/shadow", "/etc/group", "/etc/services" }; "neighbours" - slist => peers("/var/cfengine/inputs/hostlist","#.*",4), + slist => peers("/var/cfengine/inputs/hostlist", "#.*", 4), comment => "Partition the network into groups"; files: @@ -445,13 +440,14 @@ bundle agent change_management comment => "Change detection on the above", changes => detect_diff_content; -####################################################################### -# Redundant cross monitoring ....................................... -####################################################################### - + ####################################################################### + # Redundant cross monitoring ....................................... + ####################################################################### "$(sys.workdir)/nw/$(neighbours)_checksum_digests.db" comment => "Watching our peers remote hash tables for changes - cross check", - copy_from => remote_cp("$(sys.workdir)/checksum_digests.db", "$(neighbours)"), + copy_from => remote_cp( + "$(sys.workdir)/checksum_digests.db", "$(neighbours)" + ), depends_on => { "grant_hash_tables" }, action => neighbourwatch("File changes observed on $(neighbours)"); ``` diff --git a/content/resources/faq/enterprise-report-filtering.markdown b/content/resources/faq/enterprise-report-filtering.markdown index 78199fd53..b71ddf80a 100644 --- a/content/resources/faq/enterprise-report-filtering.markdown +++ b/content/resources/faq/enterprise-report-filtering.markdown @@ -22,15 +22,15 @@ bundle agent example "tags" slist => { "autorun" }; vars: - - !host_001:: - "slist" slist => { "common", "one", "four" }, - meta => { "inventory", "attribute_name=My Inventory" }; - - host_001:: - "slist" slist => { "common", "two", "three" }, - meta => { "inventory", "attribute_name=My Inventory" }; - + !host_001:: + "slist" + slist => { "common", "one", "four" }, + meta => { "inventory", "attribute_name=My Inventory" }; + + host_001:: + "slist" + slist => { "common", "two", "three" }, + meta => { "inventory", "attribute_name=My Inventory" }; } ``` diff --git a/content/resources/faq/fix-undefined-body-error.markdown b/content/resources/faq/fix-undefined-body-error.markdown index bb5fe9297..8fdcbf54c 100644 --- a/content/resources/faq/fix-undefined-body-error.markdown +++ b/content/resources/faq/fix-undefined-body-error.markdown @@ -25,8 +25,8 @@ or [body file control inputs][file control#inputs]. ```cf3 body common control { - bundlesequence => { "file_remover" }; - inputs => { "$(sys.libdir)/stdlib.cf" }; + bundlesequence => { "file_remover" }; + inputs => { "$(sys.libdir)/stdlib.cf" }; } ``` @@ -39,11 +39,12 @@ are typically relative to the policy file itself. bundle common file_remover_control { vars: - "inputs" slist => { - "$(sys.libdir)/stdlib.cf", - "$(this.promise_dirname)/custom_policy.cf", - }; + "inputs" + slist => { + "$(sys.libdir)/stdlib.cf", "$(this.promise_dirname)/custom_policy.cf", + }; } + body file control { inputs => { @(file_remover_control.inputs) }; diff --git a/content/resources/faq/integrate-custom-policy.markdown b/content/resources/faq/integrate-custom-policy.markdown index e102076d5..7645c10da 100644 --- a/content/resources/faq/integrate-custom-policy.markdown +++ b/content/resources/faq/integrate-custom-policy.markdown @@ -76,11 +76,9 @@ body file control ```cf3 bundle common example_file_control { - vars: - "policy[stdlib]" - string => "$(this.policy_dirname)/../my_other_policy.cf"; - - "inputs" slist => getvalues( policy ); + vars: + "policy[stdlib]" string => "$(this.policy_dirname)/../my_other_policy.cf"; + "inputs" slist => getvalues(policy); } body file control diff --git a/content/resources/faq/variables.markdown b/content/resources/faq/variables.markdown index 1d0989398..10ee4f333 100644 --- a/content/resources/faq/variables.markdown +++ b/content/resources/faq/variables.markdown @@ -18,8 +18,7 @@ bundle agent example "data" data => parsejson('[ { "x": 1 }, { "y": 2 } ]'); methods: - "use data" - usebundle => use_data(@(data)); + "use data" usebundle => use_data(@(data)); } bundle agent use_data(dc) @@ -35,6 +34,7 @@ bundle agent use_data(dc) reports: "CFEngine version '$(sys.cf_version)'"; + have_x:: "Index '$(dc_index)' has key for x"; diff --git a/content/resources/faq/what-did-cfengine-change.markdown b/content/resources/faq/what-did-cfengine-change.markdown index b81d950be..c147ee82d 100644 --- a/content/resources/faq/what-did-cfengine-change.markdown +++ b/content/resources/faq/what-did-cfengine-change.markdown @@ -19,13 +19,11 @@ Example Policy (`/tmp/example.cf`): ```cf3 bundle agent main { - files: - - "/tmp/example" - handle => "example_file_exists_and_contains_date", - create => "true", - edit_line => lines_present( $(sys.date) ); + "/tmp/example" + handle => "example_file_exists_and_contains_date", + create => "true", + edit_line => lines_present($(sys.date)); } bundle edit_line lines_present(lines) @@ -48,9 +46,7 @@ bundle edit_line lines_present(lines) # } { insert_lines: - - "$(lines)" - comment => "Append lines if they don't exist"; + "$(lines)" comment => "Append lines if they don't exist"; } ``` @@ -148,18 +144,16 @@ body file control bundle agent main { commands: - "/bin/true" - action => log_my_repairs( '/tmp/repaired.log' ); + "/bin/true" action => log_my_repairs('/tmp/repaired.log'); reports: - "/tmp/repaired.log" - printfile => cat( $(this.promiser) ); + "/tmp/repaired.log" printfile => cat($(this.promiser)); } -body action log_my_repairs( file ) +body action log_my_repairs(file) { - log_repaired => "$(file)"; - log_string => "$(sys.date) REPAIRED $(this.promiser)"; + log_repaired => "$(file)"; + log_string => "$(sys.date) REPAIRED $(this.promiser)"; } ``` diff --git a/content/web-ui/hub_administration/audit-log-retention.markdown b/content/web-ui/hub_administration/audit-log-retention.markdown index 28ef7b068..d1f09210e 100644 --- a/content/web-ui/hub_administration/audit-log-retention.markdown +++ b/content/web-ui/hub_administration/audit-log-retention.markdown @@ -55,16 +55,16 @@ bundle agent audit_log_retention # @brief Prune Mission Portal audit_log entries older than $(days) days { vars: - "days" string => "365"; + "days" string => "365"; commands: policy_server:: "$(sys.bindir)/psql" - args => "cfsettings -c \"DELETE FROM audit_log WHERE time < NOW() - INTERVAL '$(days) day';\"", - contain => in_shell_and_silent, - action => if_elapsed_day, - handle => "audit_log_retention_prune", - comment => "Prune Mission Portal audit_log entries older than $(days) days"; + args => "cfsettings -c \"DELETE FROM audit_log WHERE time < NOW() - INTERVAL '$(days) day';\"", + contain => in_shell_and_silent, + action => if_elapsed_day, + handle => "audit_log_retention_prune", + comment => "Prune Mission Portal audit_log entries older than $(days) days"; } ``` diff --git a/content/web-ui/hub_administration/policy-deployment.markdown b/content/web-ui/hub_administration/policy-deployment.markdown index cd7b49199..3026f4c97 100644 --- a/content/web-ui/hub_administration/policy-deployment.markdown +++ b/content/web-ui/hub_administration/policy-deployment.markdown @@ -117,12 +117,12 @@ Simply edit `bundle common update_def` in `controls/update_def.cf`. ```cf3 {file="update_def.cf"} bundle common update_def { -# ... + # ... classes: -# ... - + # ... "cfengine_internal_masterfiles_update" expression => "policy_server"; -# ... + + # ... } ``` diff --git a/content/web-ui/hub_administration/public-key-distribution.markdown b/content/web-ui/hub_administration/public-key-distribution.markdown index c9112bced..d2d88ffa8 100644 --- a/content/web-ui/hub_administration/public-key-distribution.markdown +++ b/content/web-ui/hub_administration/public-key-distribution.markdown @@ -32,60 +32,56 @@ bundle agent trust_distkeys #@ brief Example public key distribution { meta: - - "tags" slist => { "autorun" }; + "tags" slist => { "autorun" }; vars: - - "keystore" - comment => "We want all hosts to trust these hosts because they perform + "keystore" + comment => "We want all hosts to trust these hosts because they perform critical functions like policy serving.", - string => ifelse( isvariable( "def.trustkeys[keystore])" ), "$(def.trustkeys[keystore])", - "distkeys"); + string => ifelse( + isvariable("def.trustkeys[keystore])"), + "$(def.trustkeys[keystore])", + "distkeys" + ); files: - - "$(sys.workdir)/ppkeys/." - handle => "trust_distkeys", - comment => "We need trust all the keys stored in `$(keystore)` on + "$(sys.workdir)/ppkeys/." + handle => "trust_distkeys", + comment => "We need trust all the keys stored in `$(keystore)` on `$(sys.policy_hub)` so that we can communicate with them using the CFEngine protocol.", - copy_from => remote_dcp( $(keystore), $(sys.policy_hub) ), - depth_search => basedir, - file_select => public_keys, - perms => mog( 644, root, root ); + copy_from => remote_dcp($(keystore), $(sys.policy_hub)), + depth_search => basedir, + file_select => public_keys, + perms => mog(644, root, root); } bundle server share_distkeys #@ brief Share the directory containing public keys we need to distribute { access: - (policy_server|am_policy_hub):: - "/var/cfengine/distkeys/" admit_ips => { "0.0.0.0/0" }, shortcut => "distkeys", handle => "access_share_distkeys", comment => "This directory contains public keys of hosts that should be trusted by everyone."; - } body depth_search basedir #@ brief Search the files in the top level of the source directory { - include_basedir => "true"; - depth => "1"; + include_basedir => "true"; + depth => "1"; } body file_select public_keys #@ brief Select plain files matching public key file naming patterns { - # root-SHA=abc123.pub - leaf_name => { "\w+-(SHA|MD5)=[[:alnum:]]+\.pub" }; - file_types => { "plain" }; - - file_result => "leaf_name.file_types"; + # root-SHA=abc123.pub + leaf_name => { "\w+-(SHA|MD5)=[[:alnum:]]+\.pub" }; + file_types => { "plain" }; + file_result => "leaf_name.file_types"; } ```