diff --git a/contrib/masterfiles/git-failsafe.cf b/contrib/masterfiles/git-failsafe.cf index 672a3e0301..a03600493f 100644 --- a/contrib/masterfiles/git-failsafe.cf +++ b/contrib/masterfiles/git-failsafe.cf @@ -247,7 +247,7 @@ bundle agent git_update perms => u_m("755"), depth_search => u_recurse_basedir("inf"), action => u_immediate, - ifvarclass => "hpux"; + if => "hpux"; "/usr/local/bin" comment => "Ensure cfengine binaries were copied to /usr/local/bin", diff --git a/examples/abort.cf b/examples/abort.cf index 2c5063af32..15573adca6 100644 --- a/examples/abort.cf +++ b/examples/abort.cf @@ -1,59 +1,47 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - #[%+%] body common control - { - bundlesequence => { "example" }; + bundlesequence => { "example" }; } body agent control - { - abortbundleclasses => { "invalid" }; + abortbundleclasses => { "invalid" }; } #[%-%] - ########################################### #[%+%] - bundle agent example - { vars: - - #"userlist" slist => { "mark", "john" }; # contains all valid entries - "userlist" slist => { "mark", "john", "thomas" }; # contains one invalid entry - + #"userlist" slist => { "mark", "john" }; # contains all valid entries + "userlist" slist => { "mark", "john", "thomas" }; + # contains one invalid entry classes: - - "invalid" not => regcmp("[a-z][a-z][a-z][a-z]","$(userlist)"); # The class 'invalid' is set if the user name does not - # contain exactly four un-capitalized letters (bundle - # execution will be aborted if set) - + "invalid" not => regcmp("[a-z][a-z][a-z][a-z]", "$(userlist)"); + # The class 'invalid' is set if the user name does not + # contain exactly four un-capitalized letters (bundle + # execution will be aborted if set) reports: - !invalid:: - "User name $(userlist) is valid at 4 letters"; } diff --git a/examples/accessed_before.cf b/examples/accessed_before.cf index 87487282f4..3c869d2505 100644 --- a/examples/accessed_before.cf +++ b/examples/accessed_before.cf @@ -1,51 +1,35 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - # # Show the definition of classes by comparing timestamps -# - body common control - { - bundlesequence => { "example" }; + bundlesequence => { "example" }; } - ########################################################### - bundle agent example - -{ +{ classes: - - "do_it" and => { - accessedbefore("/tmp/earlier","/tmp/later") - }; + "do_it" and => { accessedbefore("/tmp/earlier", "/tmp/later") }; reports: - do_it:: - "The earlier file has been accessed before the later"; - } - diff --git a/examples/accessedbefore.cf b/examples/accessedbefore.cf index c2569581e7..6fdf719c4c 100644 --- a/examples/accessedbefore.cf +++ b/examples/accessedbefore.cf @@ -1,25 +1,22 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - #+begin_src prep #@ ``` #@ touch -a -t '200102031234.56' /tmp/earlier @@ -30,13 +27,13 @@ #+begin_src cfengine3 body common control { - bundlesequence => { "example" }; + bundlesequence => { "example" }; } bundle agent example { classes: - "do_it" expression => accessedbefore("/tmp/earlier","/tmp/later"); + "do_it" expression => accessedbefore("/tmp/earlier", "/tmp/later"); reports: do_it:: diff --git a/examples/accumulated_time.cf b/examples/accumulated_time.cf index 49bc874475..26bcf421ba 100644 --- a/examples/accumulated_time.cf +++ b/examples/accumulated_time.cf @@ -1,71 +1,54 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - ######################################################## # # Simple test processes # ######################################################## - body common control - { - bundlesequence => { "example" }; + bundlesequence => { "example" }; } - ######################################################## - bundle agent example - { processes: - - ".*" - - process_count => anyprocs, - process_select => proc_finder; + ".*" + process_count => anyprocs, + process_select => proc_finder; reports: - 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)); - process_result => "ttime"; + ttime_range => irange( + accumulated(0, 0, 0, 0, 2, 0), accumulated(0, 0, 0, 0, 20, 0) + ); + process_result => "ttime"; } - ######################################################## - body process_count anyprocs - { - match_range => "0,0"; - out_of_range_define => { "any_procs" }; + match_range => "0,0"; + out_of_range_define => { "any_procs" }; } - diff --git a/examples/acl.cf b/examples/acl.cf index 271b73d25f..268894eb85 100644 --- a/examples/acl.cf +++ b/examples/acl.cf @@ -1,70 +1,54 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - - body common control { - bundlesequence => { "acls" }; + bundlesequence => { "acls" }; } - ######################################### - bundle agent acls - { files: - - "/media/flash/acl/test_dir" - + "/media/flash/acl/test_dir" depth_search => include_base, acl => template; } - ######################################### - 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" + }; } - ######################################### - body acl win - { - acl_method => "overwrite"; - acl_type => "ntfs"; - acl_default => "nochange"; - aces => { "user:Administrator:rw", "group:Bad:rwx(Dpo):deny" }; + acl_method => "overwrite"; + acl_type => "ntfs"; + acl_default => "nochange"; + aces => { "user:Administrator:rw", "group:Bad:rwx(Dpo):deny" }; } - ######################################### - body depth_search include_base - { - include_basedir => "true"; + include_basedir => "true"; } diff --git a/examples/acl_generic.cf b/examples/acl_generic.cf index 68b030d7a8..67d11617cb 100644 --- a/examples/acl_generic.cf +++ b/examples/acl_generic.cf @@ -1,57 +1,42 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - - body common control { - bundlesequence => { "acls" }; + bundlesequence => { "acls" }; } - ######################################### - bundle agent acls - { files: - - "/media/flash/acl/test_dir" - + "/media/flash/acl/test_dir" depth_search => include_base, acl => test; } - ######################################### - body acl test - { - acl_type => "generic"; - aces => {"user:bob:rwx", "group:staff:rx", "all:r"}; + acl_type => "generic"; + aces => { "user:bob:rwx", "group:staff:rx", "all:r" }; } - ######################################### - body depth_search include_base - { - include_basedir => "true"; + include_basedir => "true"; } diff --git a/examples/acl_ntfs.cf b/examples/acl_ntfs.cf index a9649a9622..66dc319a11 100644 --- a/examples/acl_ntfs.cf +++ b/examples/acl_ntfs.cf @@ -1,26 +1,27 @@ -body common control -{ - inputs => { "$(sys.libdir)/stdlib.cf" }; - bundlesequence => { "example" }; -} - +body common control +{ + inputs => { "$(sys.libdir)/stdlib.cf" }; + bundlesequence => { "example" }; +} ### - -bundle agent example -{ - vars: - "acl_secret_dir" slist => { "user:Administrator:rwx:allow", "group:Administrators:rx:allow" }; - "acl_secret_file" slist => { "user:Administrator:rw:allow" }; - - files: - - windows:: - "C:\Secret" - acl => ntfs( "@(acl_secret_dir)" ), - depth_search => include_base, - perms => owner( "Administrator" ); - - "C:\Secret\file.txt" - acl => ntfs( "@(acl_secret_file)" ), - perms => owner( "Administrator" ); -} +bundle agent example +{ + vars: + "acl_secret_dir" + slist => { + "user:Administrator:rwx:allow", "group:Administrators:rx:allow" + }; + + "acl_secret_file" slist => { "user:Administrator:rw:allow" }; + + files: + windows:: + "C:\Secret" + acl => ntfs("@(acl_secret_dir)"), + depth_search => include_base, + perms => owner("Administrator"); + + "C:\Secret\file.txt" + acl => ntfs("@(acl_secret_file)"), + perms => owner("Administrator"); +} diff --git a/examples/acl_secret.cf b/examples/acl_secret.cf index 0bab7c4c97..eab482d953 100644 --- a/examples/acl_secret.cf +++ b/examples/acl_secret.cf @@ -1,56 +1,40 @@ # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - body common control { - bundlesequence => { "acls" }; + bundlesequence => { "acls" }; } - ######################################### - bundle agent acls - { files: - windows:: - "c:\Secret" - acl => win, - depth_search => include_base, - comment => "Secure the secret directory from unauthorized access"; + acl => win, + depth_search => include_base, + comment => "Secure the secret directory from unauthorized access"; } - ######################################### - body acl win - { - acl_method => "overwrite"; - aces => { "user:Administrator:rwx" }; + acl_method => "overwrite"; + aces => { "user:Administrator:rwx" }; } - ######################################### - body depth_search include_base - { - include_basedir => "true"; + include_basedir => "true"; } diff --git a/examples/action_policy.cf b/examples/action_policy.cf index 422063b190..2b0d93a3c2 100755 --- a/examples/action_policy.cf +++ b/examples/action_policy.cf @@ -1,97 +1,92 @@ #!/var/cfengine/bin/cf-agent -f- # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - #+begin_src cfengine3 body file control { - # Include the stdlib for local_dcp, policy, delete_lines - inputs => { "$(sys.libdir)/stdlib.cf" }; + # Include the stdlib for local_dcp, policy, delete_lines + inputs => { "$(sys.libdir)/stdlib.cf" }; } + bundle agent example_action_policy # @brief Example illustrating how action_policy in action bodies control promise actuation and outcomes { files: - - # We make sure there is some files to operate on, so we simply make a copy - # of ourselves - - "$(this.promise_filename).nop" - copy_from => local_dcp( $(this.promise_filename) ); - - "$(this.promise_filename).warn" - copy_from => local_dcp( $(this.promise_filename) ); - - "$(this.promise_filename).fix" - copy_from => local_dcp( $(this.promise_filename) ); - - # We exercise each valid value of action_policy (nop, fix, warn) defining - # classes named for the action_policy - - "$(this.promise_filename).nop" - handle => "delete_lines_action_nop", - edit_line => delete_lines_matching ( ".*" ), - action => policy( "nop" ), - classes => results( "namespace", "MY_files_promise_nop" ); - - "$(this.promise_filename).warn" - handle => "delete_lines_action_warn", - edit_line => delete_lines_matching ( ".*" ), - action => policy( "warn" ), - classes => results( "namespace", "MY_files_promise_warn" ); - - "$(this.promise_filename).fix" - handle => "delete_lines_action_fix", - edit_line => delete_lines_matching ( ".*" ), - action => policy( "fix" ), - classes => results( "namespace", "MY_files_promise_fix" ); + # We make sure there is some files to operate on, so we simply make a copy + # of ourselves + "$(this.promise_filename).nop" + copy_from => local_dcp($(this.promise_filename)); + + "$(this.promise_filename).warn" + copy_from => local_dcp($(this.promise_filename)); + + "$(this.promise_filename).fix" + copy_from => local_dcp($(this.promise_filename)); + + # We exercise each valid value of action_policy (nop, fix, warn) defining + # classes named for the action_policy + "$(this.promise_filename).nop" + handle => "delete_lines_action_nop", + edit_line => delete_lines_matching(".*"), + action => policy("nop"), + classes => results("namespace", "MY_files_promise_nop"); + + "$(this.promise_filename).warn" + handle => "delete_lines_action_warn", + edit_line => delete_lines_matching(".*"), + action => policy("warn"), + classes => results("namespace", "MY_files_promise_warn"); + + "$(this.promise_filename).fix" + handle => "delete_lines_action_fix", + edit_line => delete_lines_matching(".*"), + action => policy("fix"), + classes => results("namespace", "MY_files_promise_fix"); commands: + "/bin/echo Running Command nop" + handle => "command_nop", + action => policy("nop"), + classes => results("namespace", "MY_commands_promise_nop"); - "/bin/echo Running Command nop" - handle => "command_nop", - action => policy( "nop" ), - classes => results( "namespace", "MY_commands_promise_nop" ); + "/bin/echo Running Command warn" + handle => "command_warn", + action => policy("warn"), + classes => results("namespace", "MY_commands_promise_warn"); - "/bin/echo Running Command warn" - handle => "command_warn", - action => policy( "warn" ), - classes => results( "namespace", "MY_commands_promise_warn" ); - - "/bin/echo Running Command fix" - handle => "command_fix", - action => policy( "fix" ), - classes => results( "namespace", "MY_commands_promise_fix" ); + "/bin/echo Running Command fix" + handle => "command_fix", + action => policy("fix"), + classes => results("namespace", "MY_commands_promise_fix"); reports: - - "MY classes:$(const.n)$(const.t)$(with)" - with => join( "$(const.n)$(const.t)", sort( classesmatching( "MY_.*" ), "lex" )); - + "MY classes:$(const.n)$(const.t)$(with)" + with => join( + "$(const.n)$(const.t)", sort(classesmatching("MY_.*"), "lex") + ); } + bundle agent __main__ { methods: - "example_action_policy"; + "example_action_policy"; } #+end_src ############################################################################### diff --git a/examples/active_directory.cf b/examples/active_directory.cf index f0d1491bdb..d9d9c7e82e 100644 --- a/examples/active_directory.cf +++ b/examples/active_directory.cf @@ -1,23 +1,18 @@ # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - ######################################################################### # active_directory.cf - Extract Data From Windows Domain Controllers # @@ -27,47 +22,43 @@ # to the resources we want to read. # ######################################################################### - -bundle agent active_directory -{ - vars: - # NOTE: Edit this to your domain, e.g. "corp", may also need more DC's after it - "domain_name" string => "cftesting"; - "user_name" string => "Guest"; - - - # NOTE: We can also extract data from remote Domain Controllers - - dummy.DomainController:: - "domain_controller" string => "localhost"; - - "userlist" slist => ldaplist( - "ldap://$(domain_controller)", - "CN=Users,DC=$(domain_name),DC=com", - "(objectClass=user)", - "sAMAccountName", - "subtree", - "none"); - - classes: - - dummy.DomainController:: - - "gotuser" expression => ldaparray( - "userinfo", - "ldap://$(domain_controller)", - "CN=$(user_name),CN=Users,DC=$(domain_name),DC=com", - "(name=*)", - "subtree", - "none"); - - - reports: - dummy.DomainController:: - "Username is \"$(userlist)\""; - - dummy.gotuser:: - "Got user data; $(userinfo[name]) has logged on $(userinfo[logonCount]) times"; - -} - +bundle agent active_directory +{ + vars: + # NOTE: Edit this to your domain, e.g. "corp", may also need more DC's after it + "domain_name" string => "cftesting"; + "user_name" string => "Guest"; + + # NOTE: We can also extract data from remote Domain Controllers + dummy.DomainController:: + "domain_controller" string => "localhost"; + + "userlist" + slist => ldaplist( + "ldap://$(domain_controller)", + "CN=Users,DC=$(domain_name),DC=com", + "(objectClass=user)", + "sAMAccountName", + "subtree", + "none" + ); + + classes: + dummy.DomainController:: + "gotuser" + expression => ldaparray( + "userinfo", + "ldap://$(domain_controller)", + "CN=$(user_name),CN=Users,DC=$(domain_name),DC=com", + "(name=*)", + "subtree", + "none" + ); + + reports: + dummy.DomainController:: + "Username is \"$(userlist)\""; + + dummy.gotuser:: + "Got user data; $(userinfo[name]) has logged on $(userinfo[logonCount]) times"; +} diff --git a/examples/activedirectory_listusers.cf b/examples/activedirectory_listusers.cf index dc86612f3e..0d7693f692 100644 --- a/examples/activedirectory_listusers.cf +++ b/examples/activedirectory_listusers.cf @@ -1,38 +1,34 @@ # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - # List users from Active Directory through LDAP # Note: Anonymous LDAP binding must be allowed, and the Anonymous user # must have read access to CN=Users - bundle agent ldap { vars: - "userlist" slist => ldaplist( - "ldap://cf-win2003", - "CN=Users,DC=domain,DC=cf-win2003", - "(objectClass=user)", - "sAMAccountName", - "subtree", - "none"); + "userlist" + slist => ldaplist( + "ldap://cf-win2003", + "CN=Users,DC=domain,DC=cf-win2003", + "(objectClass=user)", + "sAMAccountName", + "subtree", + "none" + ); + reports: - "Username: \"$(userlist)\""; + "Username: \"$(userlist)\""; } - diff --git a/examples/activedirectory_showuser.cf b/examples/activedirectory_showuser.cf index 77959ddcd6..6fa8c90ac8 100644 --- a/examples/activedirectory_showuser.cf +++ b/examples/activedirectory_showuser.cf @@ -1,41 +1,39 @@ # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - # List users from Active Directory through LDAP # Note: Anonymous LDAP binding must be allowed, and the Anonymous user # must have read access to CN=Users and CN=theusername # Run the agent in verbose mode to see the data - bundle agent ldap { classes: - "gotdata" expression => ldaparray( - "myarray", - "ldap://cf-win2003", - "CN=Test Pilot,CN=Users,DC=domain,DC=cf-win2003", - "(name=*)", - "subtree", - "none"); + "gotdata" + expression => ldaparray( + "myarray", + "ldap://cf-win2003", + "CN=Test Pilot,CN=Users,DC=domain,DC=cf-win2003", + "(name=*)", + "subtree", + "none" + ); + reports: gotdata:: "Got user data"; + !gotdata:: "Did not get user data"; } diff --git a/examples/ago.cf b/examples/ago.cf index 07710f9a9f..f39a8b1624 100644 --- a/examples/ago.cf +++ b/examples/ago.cf @@ -1,61 +1,51 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - #+begin_src cfengine3 body common control { - bundlesequence => { "testbundle" }; + bundlesequence => { "testbundle" }; } bundle agent testbundle { processes: - - ".*" - - process_count => anyprocs, - process_select => proc_finder; + ".*" + process_count => anyprocs, + process_select => proc_finder; reports: - any_procs:: - "Found processes out of range"; } - body process_select proc_finder - { - # Processes started between 100 years + 5.5 hours and 1 minute ago - stime_range => irange(ago(100,0,0,5,30,0),ago(0,0,0,0,1,0)); - process_result => "stime"; + # Processes started between 100 years + 5.5 hours and 1 minute ago + stime_range => irange(ago(100, 0, 0, 5, 30, 0), ago(0, 0, 0, 0, 1, 0)); + process_result => "stime"; } body process_count anyprocs - { - match_range => "0,0"; - out_of_range_define => { "any_procs" }; + match_range => "0,0"; + out_of_range_define => { "any_procs" }; } #+end_src ############################################################################### diff --git a/examples/app_baseline.cf b/examples/app_baseline.cf index 0afcda60d7..f956fa6a0d 100644 --- a/examples/app_baseline.cf +++ b/examples/app_baseline.cf @@ -1,23 +1,18 @@ # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - ######################################################################### # # app_baseline.cf - Verify Existence of Applications @@ -28,39 +23,45 @@ # and act upon or report any anomalies. # ######################################################################### - - -bundle agent app_baseline -{ - - methods: - windows:: - "any" usebundle => detect_adobereader; - -} - +bundle agent app_baseline +{ + methods: + windows:: + "any" usebundle => detect_adobereader; +} ### - -bundle agent detect_adobereader -{ - vars: - - windows:: - "value1" string => registryvalue("HKEY_LOCAL_MACHINE\SOFTWARE\Adobe\Acrobat Reader\9.0\Installer", "ENU_GUID"); - "value2" string => registryvalue("HKEY_LOCAL_MACHINE\SOFTWARE\Adobe\Acrobat Reader\9.0\Installer", "VersionMax"); - "value3" string => registryvalue("HKEY_LOCAL_MACHINE\SOFTWARE\Adobe\Acrobat Reader\9.0\Installer", "VersionMin"); - - classes: - - windows:: - "is_correct" and => { - strcmp("$(value1)", "{AC76BA86-7AD7-1033-7B44-A93000000001}"), - strcmp("$(value2)", "90003"), - islessthan("$(value3)", "10001" ) - }; - - reports: - - windows.!is_correct:: - "Adobe Reader is not correctly deployed - got \"$(value1)\", \"$(value2)\", \"$(value3)\""; -} +bundle agent detect_adobereader +{ + vars: + windows:: + "value1" + string => registryvalue( + "HKEY_LOCAL_MACHINE\SOFTWARE\Adobe\Acrobat Reader\9.0\Installer", + "ENU_GUID" + ); + + "value2" + string => registryvalue( + "HKEY_LOCAL_MACHINE\SOFTWARE\Adobe\Acrobat Reader\9.0\Installer", + "VersionMax" + ); + + "value3" + string => registryvalue( + "HKEY_LOCAL_MACHINE\SOFTWARE\Adobe\Acrobat Reader\9.0\Installer", + "VersionMin" + ); + + classes: + windows:: + "is_correct" + and => { + strcmp("$(value1)", "{AC76BA86-7AD7-1033-7B44-A93000000001}"), + strcmp("$(value2)", "90003"), + islessthan("$(value3)", "10001"), + }; + + reports: + windows.!is_correct:: + "Adobe Reader is not correctly deployed - got \"$(value1)\", \"$(value2)\", \"$(value3)\""; +} diff --git a/examples/appgroups.cf b/examples/appgroups.cf index d2b38f9bf2..8cb3663dd0 100644 --- a/examples/appgroups.cf +++ b/examples/appgroups.cf @@ -1,36 +1,35 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - #+begin_src cfengine3 body common control { - bundlesequence => { run }; + bundlesequence => { run }; } bundle agent run { vars: - # you can also readjson() from a file - "groups" data => parsejson('{ + # you can also readjson() from a file + "groups" + data => parsejson( + '{ "ByGroup": { "App1": @@ -61,70 +60,72 @@ bundle agent run "Host3" ] } -}'); +}' + ); methods: - # use the first one on the client - #"go" usebundle => appgroups($(sys.uqhost), @(groups)); - "go" usebundle => appgroups("Host1", @(groups)); - "go" usebundle => appgroups("Host2", @(groups)); + # use the first one on the client + #"go" usebundle => appgroups($(sys.uqhost), @(groups)); + "go" usebundle => appgroups("Host1", @(groups)); + "go" usebundle => appgroups("Host2", @(groups)); } bundle agent appgroups(name, g) { classes: - # stage (3) now for each APP, define have_app_APP if the host is in APP's host list - "have_app_$(apps)" expression => strcmp($(name), "$(hosts_$(apps))"); + # stage (3) now for each APP, define have_app_APP if the host is in APP's host list + "have_app_$(apps)" expression => strcmp($(name), "$(hosts_$(apps))"); - # stage (4) define the class have_group_GROUP for every GROUP belonging to APP - "have_group_$(groups_$(apps))" expression => "have_app_$(apps)"; + # stage (4) define the class have_group_GROUP for every GROUP belonging to APP + "have_group_$(groups_$(apps))" expression => "have_app_$(apps)"; - # stage (5) define the class have_group if we found any groups - "have_group" not => strcmp("0", length("$(cname)_list")); + # stage (5) define the class have_group if we found any groups + "have_group" not => strcmp("0", length("$(cname)_list")); vars: - # stage (1) start here: we get the apps from the list of "by app" keys - "apps" slist => getindices("g[ByApp]"); - "apps_str" string => format("%S", "apps"); - # stage (2) now for each app, we collect the hosts assigned to it - "hosts_$(apps)" slist => getvalues("g[ByApp][$(apps)]"); - "hosts_$(apps)_str" string => format("%S", "hosts_$(apps)"); + # stage (1) start here: we get the apps from the list of "by app" keys + "apps" slist => getindices("g[ByApp]"); + "apps_str" string => format("%S", "apps"); - # stage (2) now for each app, we collect the groups assigned to it - "groups_$(apps)" slist => getvalues("g[ByGroup][$(apps)]"); - "groups_$(apps)_str" string => format("%S", "groups_$(apps)"); + # stage (2) now for each app, we collect the hosts assigned to it + "hosts_$(apps)" slist => getvalues("g[ByApp][$(apps)]"); + "hosts_$(apps)_str" string => format("%S", "hosts_$(apps)"); - # stage (5) collect the space-separated group names from an intermediate array - "cname" string => canonify($(name)); + # stage (2) now for each app, we collect the groups assigned to it + "groups_$(apps)" slist => getvalues("g[ByGroup][$(apps)]"); + "groups_$(apps)_str" string => format("%S", "groups_$(apps)"); - "$(cname)_grouplist[$(groups_$(apps))]" string => "1", + # stage (5) collect the space-separated group names from an intermediate array + "cname" string => canonify($(name)); + + "$(cname)_grouplist[$(groups_$(apps))]" + string => "1", if => "have_app_$(apps)"; - "$(cname)_grouplist_slist" slist => getvalues("$(cname)_grouplist"); + "$(cname)_grouplist_slist" slist => getvalues("$(cname)_grouplist"); - # get the keys of the array and sort them, then join with spaces - "$(cname)_list" slist => getindices("$(cname)_grouplist"); - "$(cname)_list_sorted" slist => sort("$(cname)_list", "lex"); - "$(cname)_list_spaces" string => join(" ", "$(cname)_list_sorted"); + # get the keys of the array and sort them, then join with spaces + "$(cname)_list" slist => getindices("$(cname)_grouplist"); + "$(cname)_list_sorted" slist => sort("$(cname)_list", "lex"); + "$(cname)_list_spaces" string => join(" ", "$(cname)_list_sorted"); reports: - # stage (1) - "$(this.bundle): looking for $(name)"; + # stage (1) + "$(this.bundle): looking for $(name)"; + "$(this.bundle): apps: $(apps_str)"; - "$(this.bundle): apps: $(apps_str)"; - # stage (2) - "$(this.bundle): hosts for $(apps): $(hosts_$(apps)_str)"; - "$(this.bundle): groups for $(apps): $(groups_$(apps)_str)"; + # stage (2) + "$(this.bundle): hosts for $(apps): $(hosts_$(apps)_str)"; + "$(this.bundle): groups for $(apps): $(groups_$(apps)_str)"; - # stage (3) - "$(this.bundle): $(name) is assigned $(apps)" - if => "have_app_$(apps)"; + # stage (3) + "$(this.bundle): $(name) is assigned $(apps)" if => "have_app_$(apps)"; - # stage (4) - "$(this.bundle): all groups for $(name) = $(groups_$(apps))" - if => "have_group_$(groups_$(apps))"; + # stage (4) + "$(this.bundle): all groups for $(name) = $(groups_$(apps))" + if => "have_group_$(groups_$(apps))"; - # stage (5) + # stage (5) have_group:: "$(this.bundle): space-separated groups for $(name) = $($(cname)_list_spaces)"; } diff --git a/examples/arrays.cf b/examples/arrays.cf index 09ce51d9c1..9eb6f8192c 100644 --- a/examples/arrays.cf +++ b/examples/arrays.cf @@ -2,31 +2,27 @@ bundle common g { vars: - - "array[key1]" string => "one"; - "array[key2]" string => "two"; + "array[key1]" string => "one"; + "array[key2]" string => "two"; } bundle agent __main__ { vars: - "thing[1][color]" string => "red"; - "thing[1][name]" string => "one"; - "thing[2][color]" string => "blue"; - "thing[2][name]" string => "two"; - - "_thing_idx" - slist => sort( getindices( thing ), lex ); + "thing[1][color]" string => "red"; + "thing[1][name]" string => "one"; + "thing[2][color]" string => "blue"; + "thing[2][name]" string => "two"; + "_thing_idx" slist => sort(getindices(thing), lex); reports: + "Keys in default:g.array = $(with)" + with => join(", ", sort(getindices("default:g.array"), lex)); - "Keys in default:g.array = $(with)" - with => join( ", ", sort( getindices( "default:g.array" ), lex)); - - "Keys of default:main.thing[1] = $(with)" - with => join( ", ", sort( getindices( "default:main.thing[1]" ), lex)); + "Keys of default:main.thing[1] = $(with)" + with => join(", ", sort(getindices("default:main.thing[1]"), lex)); - "Thing $(thing[$(_thing_idx)][name]) is $(thing[$(_thing_idx)][color])"; + "Thing $(thing[$(_thing_idx)][name]) is $(thing[$(_thing_idx)][color])"; } #+end_src ############################################################################### diff --git a/examples/augment.cf b/examples/augment.cf index 87a476e956..bbd42acd03 100644 --- a/examples/augment.cf +++ b/examples/augment.cf @@ -2,32 +2,32 @@ bundle common def { vars: # Only define this variable if it is not yet defined. - "example_augment_string_override" - unless => isvariable("example_augment_string_override"); + "example_augment_string" + string => "fallback value when not defined in def.json", + unless => isvariable("example_augment_string"); # Define this variable regardless if it has been set in def.json "example_augment_list_override" slist => { "defined", "in", "bundle", "common", "def" }; } + bundle agent main { vars: - "def_vars" - slist => variablesmatching("default\:def\..*"); + "def_vars" slist => variablesmatching("default\:def\..*"); reports: "Def var: '$(def_vars)'"; - - "def.example_augment_string_override = '$(def.example_augment_string_override)'"; + "def.example_augment_string = '$(def.example_augment_string)'"; "def.example_augment_list_override = '$(def.example_augment_list_override)'"; "def.example_augment_structured_override[key1] = '$(def.example_augment_structured_override[key1])'"; } #+begin_src example_output #@ ``` #@ R: Def var: 'default:def.example_augment_structured_override' -#@ R: Def var: 'default:def.example_augment_string_override' +#@ R: Def var: 'default:def.example_augment_string' #@ R: Def var: 'default:def.example_augment_list_override' -#@ R: def.example_augment_string_override = 'defined in def.json' +#@ R: def.example_augment_string = 'defined in def.json' #@ R: def.example_augment_list_override = 'defined' #@ R: def.example_augment_list_override = 'in' #@ R: def.example_augment_list_override = 'bundle' diff --git a/examples/backreferences_files.cf b/examples/backreferences_files.cf index f73b12f020..6a8b368bbf 100644 --- a/examples/backreferences_files.cf +++ b/examples/backreferences_files.cf @@ -1,74 +1,50 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - ###################################################################### # # File editing - back reference # ###################################################################### - - body common control - { - version => "1.2.3"; - bundlesequence => { "example" }; + version => "1.2.3"; + bundlesequence => { "example" }; } - ######################################################## - bundle agent example - { files: - - # The back reference in a path only applies to the last link - # of the pathname, so the (tmp) gets ignored - - "/tmp/(cf3)_(.*)" - - edit_line => myedit("second $(match.2)"); - - - # but ... - - # "/tmp/cf3_test" - # create => "true", - # edit_line => myedit("second $(match.1)"); - - + # The back reference in a path only applies to the last link + # of the pathname, so the (tmp) gets ignored + "/tmp/(cf3)_(.*)" edit_line => myedit("second $(match.2)"); + # but ... + # "/tmp/cf3_test" + # create => "true", + # edit_line => myedit("second $(match.1)"); } - ######################################################## - 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)"; } - diff --git a/examples/basename.cf b/examples/basename.cf index 23ab6504f9..a38b812899 100644 --- a/examples/basename.cf +++ b/examples/basename.cf @@ -4,15 +4,15 @@ bundle agent main # @brief Example illustrating the behavior of basename() { vars: - "basename" -> { "CFE-3196" } - string => basename( $(this.promise_filename) ); + "basename" -> { "CFE-3196" } + string => basename($(this.promise_filename)); - "basename_wo_extension" -> { "CFE-3196" } - string => basename( $(this.promise_filename), ".cf" ); - reports: + "basename_wo_extension" -> { "CFE-3196" } + string => basename($(this.promise_filename), ".cf"); - "basename = '$(basename)'"; - "basename without '.cf' extension = '$(basename_wo_extension)'"; + reports: + "basename = '$(basename)'"; + "basename without '.cf' extension = '$(basename_wo_extension)'"; } #+end_src ############################################################################### diff --git a/examples/bsdflags.cf b/examples/bsdflags.cf index 1119407e17..5b5428efc3 100644 --- a/examples/bsdflags.cf +++ b/examples/bsdflags.cf @@ -1,47 +1,37 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - - body common control { - bundlesequence => { "example" }; + bundlesequence => { "example" }; } bundle agent example { files: - freebsd:: - "/tmp/newfile" - - create => "true", - perms => setbsd; - + create => "true", + perms => setbsd; } - body perms setbsd { - bsdflags => { "+uappnd","+uchg", "+uunlnk", "-nodump" }; + bsdflags => { "+uappnd", "+uchg", "+uunlnk", "-nodump" }; } - diff --git a/examples/buggy/namespaces.cf b/examples/buggy/namespaces.cf index 692b2b0170..d1a27fb9ee 100644 --- a/examples/buggy/namespaces.cf +++ b/examples/buggy/namespaces.cf @@ -1,60 +1,45 @@ - body common control { - bundlesequence => { "main" }; - inputs => { "namespaces/1.cf", "namespaces/2.cf", "namespaces/3.cf" }; + bundlesequence => { "main" }; + inputs => { "namespaces/1.cf", "namespaces/2.cf", "namespaces/3.cf" }; } - bundle agent main { vars: - - "alien_list" slist => { getindices("name1:mymethod.array")}; - - "local_list" slist => { getindices("example.array") }; + "alien_list" slist => { getindices("name1:mymethod.array") }; + "local_list" slist => { getindices("example.array") }; files: - - "/tmp/bla" - + "/tmp/bla" create => "true", perms => zub("700"); - # or perms => default:zub("700"); - + # or perms => default:zub("700"); methods: + "namespace demo" usebundle => name1:mymethod("arg1"); + "namespace demo" usebundle => name2:mymethod("arg1", "arg2"); + "namespace demo" usebundle => example; - "namespace demo" usebundle => name1:mymethod("arg1"); - - "namespace demo" usebundle => name2:mymethod("arg1","arg2"); - - "namespace demo" usebundle => example; - # Or "namespace demo" usebundle => default:example; - - "namespace demo" usebundle => test_in_last_file; + # Or "namespace demo" usebundle => default:example; + "namespace demo" usebundle => test_in_last_file; reports: - - "Foreign namespace index list: $(alien_list)"; - "Local index list: $(local_list)"; + "Foreign namespace index list: $(alien_list)"; + "Local index list: $(local_list)"; } - body perms zub(x) { - mode => "$(x)"; + mode => "$(x)"; } - bundle agent example { vars: - - "array[one]" string => "text one"; - "array[two]" string => "text two"; - "array[three]" string => "text three"; + "array[one]" string => "text one"; + "array[two]" string => "text two"; + "array[three]" string => "text three"; reports: - - "TEST OK in no namespace"; + "TEST OK in no namespace"; } diff --git a/examples/buggy/namespaces/1.cf b/examples/buggy/namespaces/1.cf index 33c7b534e4..9113689d36 100644 --- a/examples/buggy/namespaces/1.cf +++ b/examples/buggy/namespaces/1.cf @@ -1,42 +1,35 @@ body file control { - namespace => "name1"; + namespace => "name1"; } - bundle agent mymethod(one) { vars: - - "array[one]" string => "text one"; - "array[two]" string => "text two"; - "array[three]" string => "text three"; + "array[one]" string => "text one"; + "array[two]" string => "text two"; + "array[three]" string => "text three"; files: - - "/tmp/$(one)" - + "/tmp/$(one)" create => "true", edit_line => makefile, perms => name2:settings; reports: - - "test $(one) in $(this.namespace)_$(this.bundle)"; + "test $(one) in $(this.namespace)_$(this.bundle)"; } - bundle edit_line makefile { insert_lines: - - "THIS IS NAME1"; + "THIS IS NAME1"; reports: - "makefile in name 1"; + "makefile in name 1"; } body perms settings { - mode => "600"; + mode => "600"; } diff --git a/examples/buggy/namespaces/2.cf b/examples/buggy/namespaces/2.cf index facaf8aa63..bb4a7b954d 100644 --- a/examples/buggy/namespaces/2.cf +++ b/examples/buggy/namespaces/2.cf @@ -1,38 +1,30 @@ - body file control { - namespace => "name2"; + namespace => "name2"; } - -bundle agent mymethod(one,two) +bundle agent mymethod(one, two) { files: - - "/tmp/$(one)$(two)" - + "/tmp/$(one)$(two)" create => "true", edit_line => makefile, perms => name1:settings; reports: - "test $(one) $(two) in $(this.namespace)_$(this.bundle)"; - + "test $(one) $(two) in $(this.namespace)_$(this.bundle)"; } bundle edit_line makefile { insert_lines: - - "THIS IS NAME2"; + "THIS IS NAME2"; reports: - - "makefile in name 2"; + "makefile in name 2"; } - body perms settings { - mode => "666"; + mode => "666"; } diff --git a/examples/buggy/namespaces/3.cf b/examples/buggy/namespaces/3.cf index 077a92237a..6e662cffb4 100644 --- a/examples/buggy/namespaces/3.cf +++ b/examples/buggy/namespaces/3.cf @@ -1,9 +1,5 @@ - - bundle agent test_in_last_file { reports: - - "Final namespace is the default"; - + "Final namespace is the default"; } diff --git a/examples/bundle_return_values.cf b/examples/bundle_return_values.cf index 4c53048301..72cb84e26d 100644 --- a/examples/bundle_return_values.cf +++ b/examples/bundle_return_values.cf @@ -1,34 +1,23 @@ - body common control { - bundlesequence => { "example" }; + bundlesequence => { "example" }; } - bundle agent example { methods: - - "any" usebundle => child, + "any" + usebundle => child, useresult => "my_return_var"; - reports: - - "My return was: \"$(my_return_var[1])\" and \"$(my_return_var[2])\""; - + "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"; - + # 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/examples/bundlesequence.cf b/examples/bundlesequence.cf index ca28033932..a0fbbd8829 100644 --- a/examples/bundlesequence.cf +++ b/examples/bundlesequence.cf @@ -1,18 +1,16 @@ # Example showing how to override the default bundlesequence body common control { - bundlesequence => { "hello" }; + bundlesequence => { "hello" }; } bundle agent hello # @brief say hello and report my bundle name { reports: - "Hello, $(this.bundle) bundle."; + "Hello, $(this.bundle) bundle."; } - #@ The policy promises to report the name of the current bundle, and produces this output: - #+begin_src example_output #@ ``` #@ R: Hello, hello bundle. diff --git a/examples/bundlesmatching.cf b/examples/bundlesmatching.cf index 910f13af5e..4d3b8e00b5 100644 --- a/examples/bundlesmatching.cf +++ b/examples/bundlesmatching.cf @@ -1,75 +1,68 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - #+begin_src cfengine3 body common control { - bundlesequence => { mefirst }; + bundlesequence => { mefirst }; } bundle common g { vars: - - # Here we find all bundles in the default namespace whos name starts with - # run. - - "todo" slist => bundlesmatching("default:run.*"); + # Here we find all bundles in the default namespace whos name starts with + # run. + "todo" slist => bundlesmatching("default:run.*"); } bundle agent mefirst { methods: - - # Here, we actuate each of the bundles that were found using - # bundlesmatching in bundle common g. - - "" usebundle => $(g.todo); + # Here, we actuate each of the bundles that were found using + # bundlesmatching in bundle common g. + "" usebundle => $(g.todo); } bundle agent run_deprecated { meta: - # This bundle is tagged with deprecated - "tags" slist => { "deprecated" }; + # This bundle is tagged with deprecated + "tags" slist => { "deprecated" }; } bundle agent run_123_456 { vars: - # Here we find all bundles in our policy. - "bundles" slist => bundlesmatching(".*"); + # Here we find all bundles in our policy. + "bundles" slist => bundlesmatching(".*"); - # Here we find all the bundles that are tagged as deprecated. - "deprecated_bundles" slist => bundlesmatching(".*", "deprecated"); + # Here we find all the bundles that are tagged as deprecated. + "deprecated_bundles" slist => bundlesmatching(".*", "deprecated"); - # Here we find all bundles that match 891 (none will). - "no_bundles" slist => bundlesmatching("891"); + # Here we find all bundles that match 891 (none will). + "no_bundles" slist => bundlesmatching("891"); reports: - # Here we report on our findings: - "bundles = $(bundles)"; - "deprecated bundles = $(deprecated_bundles)"; - "no bundles = $(no_bundles)"; + # Here we report on our findings: + "bundles = $(bundles)"; + "deprecated bundles = $(deprecated_bundles)"; + "no bundles = $(no_bundles)"; } #+end_src ############################################################################### diff --git a/examples/bundlestate.cf b/examples/bundlestate.cf index 9efde97e23..1df2b0fd7b 100644 --- a/examples/bundlestate.cf +++ b/examples/bundlestate.cf @@ -1,52 +1,49 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - #+begin_src cfengine3 body common control { - bundlesequence => { holder, test }; + bundlesequence => { holder, test }; } bundle common holder { classes: - "holderclass" expression => "any"; # will be global - + "holderclass" expression => "any"; + # will be global vars: - "s" string => "Hello!"; - "d" data => parsejson('[4,5,6]'); - "list" slist => { "element1", "element2" }; + "s" string => "Hello!"; + "d" data => parsejson('[4,5,6]'); + "list" slist => { "element1", "element2" }; } bundle agent test { vars: - "bundle_state" data => bundlestate("holder"); + "bundle_state" data => bundlestate("holder"); - # all the variables in bundle "holder" defined as of the execution of bundlestate() will be here - "holderstate" string => format("%S", "bundle_state"); + # all the variables in bundle "holder" defined as of the execution of bundlestate() will be here + "holderstate" string => format("%S", "bundle_state"); reports: - "holder vars = $(holderstate)"; + "holder vars = $(holderstate)"; } #+end_src ############################################################################### diff --git a/examples/canonify.cf b/examples/canonify.cf index 22166e35d7..53e6d1039f 100644 --- a/examples/canonify.cf +++ b/examples/canonify.cf @@ -1,41 +1,37 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - #+begin_src cfengine3 body common control { - bundlesequence => { "example" }; + bundlesequence => { "example" }; } bundle agent example { vars: - "component" string => "/var/cfengine/bin/cf-serverd"; - "canon" string => canonify("$(component)"); + "component" string => "/var/cfengine/bin/cf-serverd"; + "canon" string => canonify("$(component)"); reports: - "canonified component == $(canon)"; + "canonified component == $(canon)"; } - #+end_src ############################################################################### #+begin_src example_output diff --git a/examples/cf-secret.cf b/examples/cf-secret.cf index 0f610c57ce..d4c7a12c99 100644 --- a/examples/cf-secret.cf +++ b/examples/cf-secret.cf @@ -1,57 +1,50 @@ # Copyright (C) Cfengine AS - # This file is part of CFEngine 3 - written and maintained by Cfengine AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - ############################################################################### #+begin_src cfengine3 bundle agent main { vars: + "private_key" + comment => "The decryption key", + string => "$(this.promise_filename).priv"; - "private_key" - comment => "The decryption key", - string => "$(this.promise_filename).priv"; - - "encrypted_file" string => "$(this.promise_filename).cfcrypt"; + "encrypted_file" string => "$(this.promise_filename).cfcrypt"; - "secret" - comment => "We decrypt the encrypted file directly into a variable.", - string => execresult("$(sys.cf_secret) -d $(private_key) -i $(encrypted_file) -o -", noshell); + "secret" + comment => "We decrypt the encrypted file directly into a variable.", + string => execresult( + "$(sys.cf_secret) -d $(private_key) -i $(encrypted_file) -o -", + noshell + ); reports: - "Encrypted file content:" - printfile => cat( $(encrypted_file) ); - - "Decrypted content:$(const.n)$(secret)"; + "Encrypted file content:" printfile => cat($(encrypted_file)); + "Decrypted content:$(const.n)$(secret)"; } body printfile cat(file) # @brief Report the contents of a file # @param file The full path of the file to report { - file_to_print => "$(file)"; - number_of_lines => "inf"; + file_to_print => "$(file)"; + number_of_lines => "inf"; } #+end_src - ############################################################################### #+begin_src static_example_output #@ ``` diff --git a/examples/cf2_integration.cf b/examples/cf2_integration.cf index 2a71a55474..ed060796e7 100644 --- a/examples/cf2_integration.cf +++ b/examples/cf2_integration.cf @@ -1,62 +1,45 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - # # Cfagent 2 can be run as a command within cfengine 3 # so that cfagent 2 AND cfagent 3 can coexist # # It does not matter which versions of the daemons are run # but you must choose version 2 XOR version 3 -# - body common control - { - - # Reads default - # /var/cfengine/inputs/promises.cf - # /var/cfengine/inputs/failsafe.cf - bundlesequence => { "cfengine3", "cfengine2" }; + # Reads default + # /var/cfengine/inputs/promises.cf + # /var/cfengine/inputs/failsafe.cf + bundlesequence => { "cfengine3", "cfengine2" }; } - ########################################### - bundle agent cfengine2 - { commands: - - "/var/cfengine/bin/cfagent"; - + "/var/cfengine/bin/cfagent"; } - ########################################### - bundle agent cfengine3 - { - - # Stuff + # Stuff commands: - - "/var/cfengine/bin/cf-agent"; + "/var/cfengine/bin/cf-agent"; } diff --git a/examples/cf_version_after.cf b/examples/cf_version_after.cf index 8e007a2100..e7c6ad40c3 100644 --- a/examples/cf_version_after.cf +++ b/examples/cf_version_after.cf @@ -4,8 +4,8 @@ bundle agent __main__ reports: "This will be skipped on older or equal versions" if => cf_version_after("3.15"); - "This will be skipped on newer versions" - unless => cf_version_after("3.15"); + + "This will be skipped on newer versions" unless => cf_version_after("3.15"); } #+end_src ############################################################################### diff --git a/examples/cf_version_at.cf b/examples/cf_version_at.cf index 74ce09d047..1e6fa8a9ab 100644 --- a/examples/cf_version_at.cf +++ b/examples/cf_version_at.cf @@ -2,10 +2,8 @@ bundle agent __main__ { reports: - "This will be skipped if version is not the same" - if => cf_version_at("3"); - "This will be skipped if version is the same" - unless => cf_version_at("3"); + "This will be skipped if version is not the same" if => cf_version_at("3"); + "This will be skipped if version is the same" unless => cf_version_at("3"); } #+end_src ############################################################################### diff --git a/examples/cf_version_before.cf b/examples/cf_version_before.cf index eb5691a65f..d627ffbc6e 100644 --- a/examples/cf_version_before.cf +++ b/examples/cf_version_before.cf @@ -4,6 +4,7 @@ bundle agent __main__ reports: "This will be skipped on newer or equal versions" if => cf_version_before("3.15"); + "This will be skipped on older versions" unless => cf_version_before("3.15"); } diff --git a/examples/cf_version_between.cf b/examples/cf_version_between.cf index 5e06afeb14..d3e43ac0b3 100644 --- a/examples/cf_version_between.cf +++ b/examples/cf_version_between.cf @@ -4,6 +4,7 @@ bundle agent __main__ reports: "This will be skipped on versions outside this inclusive range" if => cf_version_between("3.15", "4"); + "This will be skipped if version is within this inclusive range" unless => cf_version_between("3.15", "4"); } diff --git a/examples/cf_version_maximum.cf b/examples/cf_version_maximum.cf index 5daf1ec059..7e13b60408 100644 --- a/examples/cf_version_maximum.cf +++ b/examples/cf_version_maximum.cf @@ -2,8 +2,8 @@ bundle agent __main__ { reports: - "This will be skipped on newer versions" - if => cf_version_maximum("3.15"); + "This will be skipped on newer versions" if => cf_version_maximum("3.15"); + "This will be skipped on older or equal versions" unless => cf_version_maximum("3.15"); } diff --git a/examples/cf_version_minimum.cf b/examples/cf_version_minimum.cf index 429f183c71..ecec9de8df 100644 --- a/examples/cf_version_minimum.cf +++ b/examples/cf_version_minimum.cf @@ -2,8 +2,8 @@ bundle agent __main__ { reports: - "This will be skipped on older versions" - if => cf_version_minimum("3.15"); + "This will be skipped on older versions" if => cf_version_minimum("3.15"); + "This will be skipped on newer or equal versions" unless => cf_version_minimum("3.15"); } diff --git a/examples/change_detect.cf b/examples/change_detect.cf index fb1de041c2..bc54557cb5 100644 --- a/examples/change_detect.cf +++ b/examples/change_detect.cf @@ -1,65 +1,49 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - ######################################################## # # Change detect # ######################################################## - #[%+%] - body common control - { - bundlesequence => { "example" }; + bundlesequence => { "example" }; } - ######################################################## - bundle agent example - { files: - - "/home/mark/tmp/web" # Directory to monitor for changes. - - changes => detect_all_change, + "/home/mark/tmp/web" + # Directory to monitor for changes. + changes => detect_all_change, depth_search => recurse("inf"); } - ######################################################### - body changes detect_all_change - { - report_changes => "all"; - update_hashes => "true"; + report_changes => "all"; + update_hashes => "true"; } - ######################################################### - body depth_search recurse(d) - { - depth => "$(d)"; + depth => "$(d)"; } diff --git a/examples/changedbefore.cf b/examples/changedbefore.cf index 11dadc2640..fd1f61690d 100644 --- a/examples/changedbefore.cf +++ b/examples/changedbefore.cf @@ -1,46 +1,33 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - - body common control - { - bundlesequence => { "example" }; + bundlesequence => { "example" }; } - ########################################################### - bundle agent example - -{ +{ classes: - - "do_it" and => { changedbefore("/tmp/earlier","/tmp/later") }; + "do_it" and => { changedbefore("/tmp/earlier", "/tmp/later") }; reports: - do_it:: - "Earlier than later!"; - } - diff --git a/examples/chdir.cf b/examples/chdir.cf index 3a31b14335..a41d53349e 100644 --- a/examples/chdir.cf +++ b/examples/chdir.cf @@ -1,46 +1,35 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - - - body common control - { - bundlesequence => { "example" }; + bundlesequence => { "example" }; } - ########################################################### - -body contain cd(dir) +body contain cd(dir) { - chdir => "${dir}"; - useshell => "useshell"; + chdir => "${dir}"; + useshell => "useshell"; } -bundle agent example +bundle agent example { commands: - - "/bin/pwd" - contain => cd("/tmp"); + "/bin/pwd" contain => cd("/tmp"); } - diff --git a/examples/class-automatic-canonificiation.cf b/examples/class-automatic-canonificiation.cf index f4cde2cc8c..cbc01aecdd 100644 --- a/examples/class-automatic-canonificiation.cf +++ b/examples/class-automatic-canonificiation.cf @@ -1,38 +1,31 @@ # This example shows how classes are automatically canonified when they are # defined and that you must explicitly canonify when verifying classes. - #+begin_src cfengine3 bundle agent main { classes: - - "my-illegal-class"; + "my-illegal-class"; reports: - - # We search to see what class was defined: - "$(with)" with => join( " ", classesmatching( "my.illegal.class" ) ); - - # We see that the illegal class is explicitly not defined. - "my-illegal-class is NOT defined (as expected, its invalid)" - unless => "my-illegal-class"; - - # We see the canonified form of the illegal class is defined. - "my_illegal_class is defined" - if => canonify("my-illegal-class"); - - # Note, if takes expressisons, you couldn't do that if it were - # automatically canonified. Here I canonify the string using with, and use - # it as part of the expression which contains an invalid classcharacter, but - # its desireable for constructing expressions. - - "Slice and dice using `with`" - with => canonify( "my-illegal-class" ), - if => "linux|$(with)"; - + # We search to see what class was defined: + "$(with)" with => join(" ", classesmatching("my.illegal.class")); + + # We see that the illegal class is explicitly not defined. + "my-illegal-class is NOT defined (as expected, its invalid)" + unless => "my-illegal-class"; + + # We see the canonified form of the illegal class is defined. + "my_illegal_class is defined" if => canonify("my-illegal-class"); + + # Note, if takes expressisons, you couldn't do that if it were + # automatically canonified. Here I canonify the string using with, and use + # it as part of the expression which contains an invalid classcharacter, but + # its desireable for constructing expressions. + "Slice and dice using `with`" + with => canonify("my-illegal-class"), + if => "linux|$(with)"; } #+end_src - #+begin_src policy_description #@ First we promise to define `my-illegal-class`. When the promise is actuated #@ it is automatically canonified and defined. This automatic canonification is @@ -41,7 +34,6 @@ bundle agent main #@ report shows how `if` takes a class expression, and if you are checking a class #@ that contains invalid characters you must canonify it. #+end_src - #+begin_src example_output #@ ``` #@ R: my_illegal_class diff --git a/examples/classes_context_applies_multiple_promises.cf b/examples/classes_context_applies_multiple_promises.cf index 6f1cbdcad6..7f0562bb2d 100644 --- a/examples/classes_context_applies_multiple_promises.cf +++ b/examples/classes_context_applies_multiple_promises.cf @@ -2,14 +2,13 @@ bundle agent __main__ { reports: - "This promise is not restricted."; + "This promise is not restricted."; any:: "Neither is this promise restricted, 'any' is always defined."; linux:: "This promise is restricted to hosts that have the class 'linux' defined."; - "This promise is also restricted to hosts that have the class 'linux' defined."; linux.cfengine_4:: @@ -19,10 +18,10 @@ bundle agent __main__ "This promise will never be actuated."; vars: - "Message" string => "Hello World!"; + "Message" string => "Hello World!"; reports: - "And this promise is again unrestricted"; + "And this promise is again unrestricted"; } #+end_src #+begin_src example_output diff --git a/examples/classes_global.cf b/examples/classes_global.cf index a1395d4233..9cbbf9b24f 100644 --- a/examples/classes_global.cf +++ b/examples/classes_global.cf @@ -1,66 +1,47 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - - body common control { - bundlesequence => { "g","tryclasses_1", "tryclasses_2" }; - + bundlesequence => { "g", "tryclasses_1", "tryclasses_2" }; } - ################################# - bundle common g { classes: - - "one" expression => "any"; - - "client_network" expression => iprange("128.39.89.0/24"); + "one" expression => "any"; + "client_network" expression => iprange("128.39.89.0/24"); } - ################################# - bundle agent tryclasses_1 { classes: - - "two" expression => "any"; + "two" expression => "any"; } - ################################# - bundle agent tryclasses_2 { classes: - - "three" expression => "any"; + "three" expression => "any"; reports: - one.three.!two:: - "Success"; } - - ################################# diff --git a/examples/classesmatching.cf b/examples/classesmatching.cf index 4f9564f345..87e80cc487 100644 --- a/examples/classesmatching.cf +++ b/examples/classesmatching.cf @@ -1,53 +1,45 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - #+begin_src cfengine3 bundle agent main { classes: - "example_one"; - "example_two" - meta => { "plus", "defined_from=$(this.bundle)" }; - "example_three" - meta => { "plus", "defined_from=$(this.bundle)" }; + "example_one"; + "example_two" meta => { "plus", "defined_from=$(this.bundle)" }; + "example_three" meta => { "plus", "defined_from=$(this.bundle)" }; vars: - "cfengine_classes" - slist => sort( classesmatching("cfengine"), lex); + "cfengine_classes" slist => sort(classesmatching("cfengine"), lex); - "example_with_plus" - slist => sort( classesmatching("example.*", "plus"), lex); + "example_with_plus" + slist => sort(classesmatching("example.*", "plus"), lex); reports: - # you may find this list of all classes interesting but it - # produces different output every time, so it's commented out here - # "All classes = '$(all)'"; + # you may find this list of all classes interesting but it + # produces different output every time, so it's commented out here + # "All classes = '$(all)'"; + "Classes matching 'cfengine' = '$(cfengine_classes)'"; - "Classes matching 'cfengine' = '$(cfengine_classes)'"; - - # this should produce no output - "Classes matching 'example.*' with the 'plus' tag = $(example_with_plus)"; + # this should produce no output + "Classes matching 'example.*' with the 'plus' tag = $(example_with_plus)"; } - #+end_src ############################################################################### #+begin_src example_output diff --git a/examples/classfiltercsv.cf b/examples/classfiltercsv.cf index 8fc0a90e81..90c15874b8 100644 --- a/examples/classfiltercsv.cf +++ b/examples/classfiltercsv.cf @@ -1,25 +1,22 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - #+begin_src prep #@ ``` #@ echo 'ClassExpr,Sort,Token,Value' > /tmp/classfiltercsv.csv @@ -33,28 +30,27 @@ #@ sed -i 's/$/\r/' /tmp/classfiltercsv.csv #@ ``` #+end_src - ############################################################################### - #+begin_src cfengine3 bundle agent example_classfiltercsv { classes: - "example_class1"; - "example_class2"; - "example_class3"; + "example_class1"; + "example_class2"; + "example_class3"; vars: - "data_file" string => "/tmp/classfiltercsv.csv"; - "d" data => classfiltercsv($(data_file), "true", 0, 1); + "data_file" string => "/tmp/classfiltercsv.csv"; + "d" data => classfiltercsv($(data_file), "true", 0, 1); reports: - "Filtered data: $(with)" with => string_mustache("{{%-top-}}", d); + "Filtered data: $(with)" with => string_mustache("{{%-top-}}", d); } + bundle agent __main__ { methods: - "example_classfiltercsv"; + "example_classfiltercsv"; } #+end_src #+begin_src example_output diff --git a/examples/classfilterdata_array_of_arrays.cf b/examples/classfilterdata_array_of_arrays.cf index 5c0786c313..fe9609e081 100644 --- a/examples/classfilterdata_array_of_arrays.cf +++ b/examples/classfilterdata_array_of_arrays.cf @@ -2,25 +2,22 @@ bundle agent __main__ { classes: - "role_2"; + "role_2"; vars: - "original" - data => '[ + "original" + data => '[ [ "role_1", "alice", 32 ], [ "!role_1", "bob", 24 ], [ "role_2", "malcom", 27 ] ]'; - "filtered" - data => classfilterdata("original", "array_of_arrays", "0"); + "filtered" data => classfilterdata("original", "array_of_arrays", "0"); reports: - "Filtered data: $(with)" - with => storejson("filtered"); + "Filtered data: $(with)" with => storejson("filtered"); } #+end_src - #+begin_src example_output #@ ``` #@ R: Filtered data: [ diff --git a/examples/classfilterdata_array_of_objects.cf b/examples/classfilterdata_array_of_objects.cf index 224cde4924..7c4594480e 100644 --- a/examples/classfilterdata_array_of_objects.cf +++ b/examples/classfilterdata_array_of_objects.cf @@ -2,35 +2,32 @@ bundle agent __main__ { classes: - "role_2"; + "role_2"; vars: - "original" - data => '[ - { "file": "/tmp/foo", "ifvarclass": "role_1" }, - { "file": "/tmp/bar", "ifvarclass": "role_2" }, - { "file": "/tmp/baz", "ifvarclass": "(role_1|role_2)" } + "original" + data => '[ + { "file": "/tmp/foo", "if": "role_1" }, + { "file": "/tmp/bar", "if": "role_2" }, + { "file": "/tmp/baz", "if": "(role_1|role_2)" } ]'; - "filtered" - data => classfilterdata("original", "array_of_objects", "ifvarclass"); + "filtered" data => classfilterdata("original", "array_of_objects", "if"); reports: - "Filtered data: $(with)" - with => storejson("filtered"); + "Filtered data: $(with)" with => storejson("filtered"); } #+end_src - #+begin_src example_output #@ ``` #@ R: Filtered data: [ #@ { #@ "file": "/tmp/bar", -#@ "ifvarclass": "role_2" +#@ "if": "role_2" #@ }, #@ { #@ "file": "/tmp/baz", -#@ "ifvarclass": "(role_1|role_2)" +#@ "if": "(role_1|role_2)" #@ } #@ ] #@ ``` diff --git a/examples/classfilterdata_object_of_arrays.cf b/examples/classfilterdata_object_of_arrays.cf index 725b289cc5..cff9952506 100644 --- a/examples/classfilterdata_object_of_arrays.cf +++ b/examples/classfilterdata_object_of_arrays.cf @@ -2,25 +2,22 @@ bundle agent __main__ { classes: - "role_2"; + "role_2"; vars: - "original" - data => '{ + "original" + data => '{ "alice": [ "role_1", 32 ], "bob": [ "!role_1", 24 ], "malcom": [ "role_2", 27 ] }'; - "filtered" - data => classfilterdata("original", "object_of_arrays", "0"); + "filtered" data => classfilterdata("original", "object_of_arrays", "0"); reports: - "Filtered data: $(with)" - with => storejson("filtered"); + "Filtered data: $(with)" with => storejson("filtered"); } #+end_src - #+begin_src example_output #@ ``` #@ R: Filtered data: { diff --git a/examples/classfilterdata_object_of_arrays_key_to_obj.cf b/examples/classfilterdata_object_of_arrays_key_to_obj.cf index 23b3f7ac2e..e884ab60f2 100644 --- a/examples/classfilterdata_object_of_arrays_key_to_obj.cf +++ b/examples/classfilterdata_object_of_arrays_key_to_obj.cf @@ -2,26 +2,23 @@ bundle agent __main__ { classes: - "role_2"; + "role_2"; vars: - "original" - data => '{ + "original" + data => '{ "role_1" : [ "alice", 32 ], "!role_1" : [ "bob", 24 ], "role_2" : [ "malcom", 27 ] }'; - # Using exogenous key (i.e., the key of the child array within the parent object) - "filtered" - data => classfilterdata("original", "object_of_arrays"); + # Using exogenous key (i.e., the key of the child array within the parent object) + "filtered" data => classfilterdata("original", "object_of_arrays"); reports: - "Filtered data: $(with)" - with => storejson("filtered"); + "Filtered data: $(with)" with => storejson("filtered"); } #+end_src - #+begin_src example_output #@ ``` #@ R: Filtered data: { diff --git a/examples/classfilterdata_object_of_objects.cf b/examples/classfilterdata_object_of_objects.cf index 69ea750dc9..b527888d07 100644 --- a/examples/classfilterdata_object_of_objects.cf +++ b/examples/classfilterdata_object_of_objects.cf @@ -2,33 +2,30 @@ bundle agent __main__ { classes: - "role_2"; + "role_2"; vars: - "original" - data => '{ - "/tmp/foo": { "ifvarclass": "role_1" }, - "/tmp/bar": { "ifvarclass": "role_2" }, - "/tmp/baz": { "ifvarclass": "(role_1|role_2)" } + "original" + data => '{ + "/tmp/foo": { "if": "role_1" }, + "/tmp/bar": { "if": "role_2" }, + "/tmp/baz": { "if": "(role_1|role_2)" } }'; - "filtered" - data => classfilterdata("original", "object_of_objects", "ifvarclass"); + "filtered" data => classfilterdata("original", "object_of_objects", "if"); reports: - "Filtered data: $(with)" - with => storejson("filtered"); + "Filtered data: $(with)" with => storejson("filtered"); } #+end_src - #+begin_src example_output #@ ``` #@ R: Filtered data: { #@ "/tmp/bar": { -#@ "ifvarclass": "role_2" +#@ "if": "role_2" #@ }, #@ "/tmp/baz": { -#@ "ifvarclass": "(role_1|role_2)" +#@ "if": "(role_1|role_2)" #@ } #@ } #@ ``` diff --git a/examples/classfilterdata_object_of_objects_key_to_obj.cf b/examples/classfilterdata_object_of_objects_key_to_obj.cf index 3d4b96b2c3..bdc63499e6 100644 --- a/examples/classfilterdata_object_of_objects_key_to_obj.cf +++ b/examples/classfilterdata_object_of_objects_key_to_obj.cf @@ -2,26 +2,23 @@ bundle agent __main__ { classes: - "role_2"; + "role_2"; vars: - "original" - data => '{ + "original" + data => '{ "role_1": { "file": "/tmp/foo" }, "role_2": { "file": "/tmp/bar" }, "(role_1|role_2)": { "file": "/tmp/baz" } }'; - # Using exogenous key (i.e., the key of the child object within the parent object) - "filtered" - data => classfilterdata("original", "object_of_objects"); + # Using exogenous key (i.e., the key of the child object within the parent object) + "filtered" data => classfilterdata("original", "object_of_objects"); reports: - "Filtered data: $(with)" - with => storejson("filtered"); + "Filtered data: $(with)" with => storejson("filtered"); } #+end_src - #+begin_src example_output #@ ``` #@ R: Filtered data: { diff --git a/examples/classmatch.cf b/examples/classmatch.cf index 98286e6d64..13db45c1c7 100644 --- a/examples/classmatch.cf +++ b/examples/classmatch.cf @@ -1,45 +1,41 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - #+begin_src cfengine3 body common control { - bundlesequence => { "example" }; + bundlesequence => { "example" }; } bundle agent example { classes: + "do_it" and => { classmatch("cfengine_3.*"), "any" }; - "do_it" and => { classmatch("cfengine_3.*"), "any" }; - "have_hardclass_nonesuch" expression => classmatch("nonesuchclass_sodonttryit", hardclass); - reports: + "have_hardclass_nonesuch" + expression => classmatch("nonesuchclass_sodonttryit", hardclass); + reports: do_it:: - "Host matches pattern"; have_hardclass_nonesuch:: - "Host has that really weird hardclass"; } #+end_src diff --git a/examples/classvar_convergence.cf b/examples/classvar_convergence.cf index a63d3a88b6..0271d32486 100644 --- a/examples/classvar_convergence.cf +++ b/examples/classvar_convergence.cf @@ -1,61 +1,44 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - - body common control { - bundlesequence => { "tryclasses_1" }; + bundlesequence => { "tryclasses_1" }; } - ################################# - bundle agent tryclasses_1 { vars: - - "x" string => "one"; - - "y" slist => { "linux", "Friday" }; + "x" string => "one"; + "y" slist => { "linux", "Friday" }; classes: - - "three" and => { "$(x)", "two" }; - - "four" or => { @(y) }; - - "one" expression => "any"; - "two" expression => "any"; + "three" and => { "$(x)", "two" }; + "four" or => { @(y) }; + "one" expression => "any"; + "two" expression => "any"; reports: - three:: - "Evaluated true"; four:: - "List substitution works"; - } - - ################################# diff --git a/examples/commands.cf b/examples/commands.cf index d5671945de..97c581232e 100644 --- a/examples/commands.cf +++ b/examples/commands.cf @@ -1,47 +1,34 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - - body common control { - bundlesequence => { "my_commands" }; - inputs => { "$(sys.libdir)/stdlib.cf" }; + bundlesequence => { "my_commands" }; + inputs => { "$(sys.libdir)/stdlib.cf" }; } - bundle agent my_commands { commands: - Sunday.Hr04.Min05_10.myhost:: - "/usr/bin/update_db"; any:: - - "/etc/mysql/start" - - contain => setuid("mysql"); - + "/etc/mysql/start" contain => setuid("mysql"); } - - diff --git a/examples/compare.cf b/examples/compare.cf index a6f624d1c5..ced4bd6515 100644 --- a/examples/compare.cf +++ b/examples/compare.cf @@ -1,58 +1,43 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - # # Testing some variable/class definitions - note scope # # Use browser -f promise_output_agent.html to view -# - body common control - { - bundlesequence => { "test" }; + bundlesequence => { "test" }; } - ########################################################### - bundle agent test - { classes: - - "ok" expression => isgreaterthan("1","0"); + "ok" expression => isgreaterthan("1", "0"); reports: - ok:: - "Assertion is true"; !ok:: - "Assertion is false"; - } - #+begin_src example_output #@ ``` #@ R: Assertion is true diff --git a/examples/complicated_cpu_bound_benchmark.cf b/examples/complicated_cpu_bound_benchmark.cf index 222f2dc103..a4b7995f27 100644 --- a/examples/complicated_cpu_bound_benchmark.cf +++ b/examples/complicated_cpu_bound_benchmark.cf @@ -1,1293 +1,1201 @@ body common control { - bundlesequence => { "benchmark" }; + bundlesequence => { "benchmark" }; } bundle agent benchmark { vars: # Determines how many times each example is run - "n" int => "10"; + "n" int => "10"; # Range: 1, 2, 3, ..., n - "i" slist => { expandrange("[1-$(n)]", "1") }; + "i" slist => { expandrange("[1-$(n)]", "1") }; methods: - "accumulated" - usebundle => accumulated_bench("$(i)"); - "ago" - usebundle => ago_bench("$(i)"); - "and" - usebundle => and_bench("$(i)"); - "basename" - usebundle => basename_bench("$(i)"); - "bundlesmatching" - usebundle => bundlesmatching_bench("$(i)"); - "bundlestate" - usebundle => bundlestate_bench("$(i)"); - "callstack_callers" - usebundle => callstack_callers_bench("$(i)"); - "callstack_promisers" - usebundle => callstack_promisers_bench("$(i)"); - "canonify" - usebundle => canonify_bench("$(i)"); - "canonifyuniquely" - usebundle => canonifyuniquely_bench("$(i)"); - "cf_version_after" - usebundle => cf_version_after_bench("$(i)"); - "cf_version_at" - usebundle => cf_version_at_bench("$(i)"); - "cf_version_before" - usebundle => cf_version_before_bench("$(i)"); - "cf_version_between" - usebundle => cf_version_between_bench("$(i)"); - "cf_version_maximum" - usebundle => cf_version_maximum_bench("$(i)"); - "cf_version_minimum" - usebundle => cf_version_minimum_bench("$(i)"); - "classesmatching" - usebundle => classesmatching_bench("$(i)"); - "classify" - usebundle => classify_bench("$(i)"); - "classmatch" - usebundle => classmatch_bench("$(i)"); - "concat" - usebundle => concat_bench("$(i)"); - "countclassesmatching" - usebundle => countclassesmatching_bench("$(i)"); - "data_expand" - usebundle => data_expand_bench("$(i)"); - "data_regextract" - usebundle => data_regextract_bench("$(i)"); - "difference" - usebundle => difference_bench("$(i)"); - "dirname" - usebundle => dirname_bench("$(i)"); - "escape" - usebundle => escape_bench("$(i)"); - "eval" - usebundle => eval_bench("$(i)"); - "every" - usebundle => every_bench("$(i)"); - "expandrange" - usebundle => expandrange_bench("$(i)"); - "filter" - usebundle => filter_bench("$(i)"); - "format" - usebundle => format_bench("$(i)"); - "getclassmetatags" - usebundle => getclassmetatags_bench("$(i)"); - "getindices" - usebundle => getindices_bench("$(i)"); - "getvalues" - usebundle => getvalues_bench("$(i)"); - "getvariablemetatags" - usebundle => getvariablemetatags_bench("$(i)"); - "grep" - usebundle => grep_bench("$(i)"); - "hash" - usebundle => hash_bench("$(i)"); - "hash_to_int" - usebundle => hash_to_int_bench("$(i)"); - "ifelse" - usebundle => ifelse_bench("$(i)"); - "intersection" - usebundle => intersection_bench("$(i)"); - "isgreaterthan" - usebundle => isgreaterthan_bench("$(i)"); - "islessthan" - usebundle => islessthan_bench("$(i)"); - "isvariable" - usebundle => isvariable_bench("$(i)"); - "join" - usebundle => join_bench("$(i)"); - "laterthan" - usebundle => laterthan_bench("$(i)"); - "length" - usebundle => length_bench("$(i)"); - "maparray" - usebundle => maparray_bench("$(i)"); - "mapdata" - usebundle => mapdata_bench("$(i)"); - "maplist" - usebundle => maplist_bench("$(i)"); - "max" - usebundle => max_bench("$(i)"); - "mean" - usebundle => mean_bench("$(i)"); - "mergedata" - usebundle => mergedata_bench("$(i)"); - "min" - usebundle => min_bench("$(i)"); - "none" - usebundle => none_bench("$(i)"); - "not" - usebundle => not_bench("$(i)"); - "now" - usebundle => now_bench("$(i)"); - "nth" - usebundle => nth_bench("$(i)"); - "on" - usebundle => on_bench("$(i)"); - "or" - usebundle => or_bench("$(i)"); - "parseintarray" - usebundle => parseintarray_bench("$(i)"); - "parsejson" - usebundle => parsejson_bench("$(i)"); - "parserealarray" - usebundle => parserealarray_bench("$(i)"); - "parsestringarray" - usebundle => parsestringarray_bench("$(i)"); - "parsestringarrayidx" - usebundle => parsestringarrayidx_bench("$(i)"); - "product" - usebundle => product_bench("$(i)"); - "random" - usebundle => randomint_bench("$(i)"); - "regarray" - usebundle => regarray_bench("$(i)"); - "regcmp" - usebundle => regcmp_bench("$(i)"); - "regex_replace" - usebundle => regex_replace_bench("$(i)"); - "regextract" - usebundle => regextract_bench("$(i)"); - "reglist" - usebundle => reglist_bench("$(i)"); - "reverse" - usebundle => reverse_bench("$(i)"); - "shuffle" - usebundle => shuffle_bench("$(i)"); - "some" - usebundle => some_bench("$(i)"); - "sort" - usebundle => sort_bench("$(i)"); - "splitstring" - usebundle => splitstring_bench("$(i)"); - "storejson" - usebundle => storejson_bench("$(i)"); - "strcmp" - usebundle => strcmp_bench("$(i)"); - "strftime" - usebundle => strftime_bench("$(i)"); - "string_downcase" - usebundle => string_downcase_bench("$(i)"); - "string_head" - usebundle => string_head_bench("$(i)"); - "string_length" - usebundle => string_length_bench("$(i)"); - "string_mustache" - usebundle => string_mustache_bench("$(i)"); - "string_replace" - usebundle => string_replace_bench("$(i)"); - "string_reverse" - usebundle => string_reverse_bench("$(i)"); - "string_split" - usebundle => string_split_bench("$(i)"); - "string_tail" - usebundle => string_tail_bench("$(i)"); - "string_upcase" - usebundle => string_upcase_bench("$(i)"); - "sublist" - usebundle => sublist_bench("$(i)"); - "sum" - usebundle => sum_bench("$(i)"); - "translatepath" - usebundle => translatepath_bench("$(i)"); - "unique" - usebundle => unique_bench("$(i)"); - "validdata" - usebundle => validdata_bench("$(i)"); - "validjson" - usebundle => validjson_bench("$(i)"); - "variablesmatching" - usebundle => variablesmatching_bench("$(i)"); - "variablesmatching_as_data" - usebundle => variablesmatching_as_data_bench("$(i)"); - "variance" - usebundle => variance_bench("$(i)"); - "done" - usebundle => print_benchmark_done_msg(); + "accumulated" usebundle => accumulated_bench("$(i)"); + "ago" usebundle => ago_bench("$(i)"); + "and" usebundle => and_bench("$(i)"); + "basename" usebundle => basename_bench("$(i)"); + "bundlesmatching" usebundle => bundlesmatching_bench("$(i)"); + "bundlestate" usebundle => bundlestate_bench("$(i)"); + "callstack_callers" usebundle => callstack_callers_bench("$(i)"); + "callstack_promisers" usebundle => callstack_promisers_bench("$(i)"); + "canonify" usebundle => canonify_bench("$(i)"); + "canonifyuniquely" usebundle => canonifyuniquely_bench("$(i)"); + "cf_version_after" usebundle => cf_version_after_bench("$(i)"); + "cf_version_at" usebundle => cf_version_at_bench("$(i)"); + "cf_version_before" usebundle => cf_version_before_bench("$(i)"); + "cf_version_between" usebundle => cf_version_between_bench("$(i)"); + "cf_version_maximum" usebundle => cf_version_maximum_bench("$(i)"); + "cf_version_minimum" usebundle => cf_version_minimum_bench("$(i)"); + "classesmatching" usebundle => classesmatching_bench("$(i)"); + "classify" usebundle => classify_bench("$(i)"); + "classmatch" usebundle => classmatch_bench("$(i)"); + "concat" usebundle => concat_bench("$(i)"); + "countclassesmatching" usebundle => countclassesmatching_bench("$(i)"); + "data_expand" usebundle => data_expand_bench("$(i)"); + "data_regextract" usebundle => data_regextract_bench("$(i)"); + "difference" usebundle => difference_bench("$(i)"); + "dirname" usebundle => dirname_bench("$(i)"); + "escape" usebundle => escape_bench("$(i)"); + "eval" usebundle => eval_bench("$(i)"); + "every" usebundle => every_bench("$(i)"); + "expandrange" usebundle => expandrange_bench("$(i)"); + "filter" usebundle => filter_bench("$(i)"); + "format" usebundle => format_bench("$(i)"); + "getclassmetatags" usebundle => getclassmetatags_bench("$(i)"); + "getindices" usebundle => getindices_bench("$(i)"); + "getvalues" usebundle => getvalues_bench("$(i)"); + "getvariablemetatags" usebundle => getvariablemetatags_bench("$(i)"); + "grep" usebundle => grep_bench("$(i)"); + "hash" usebundle => hash_bench("$(i)"); + "hash_to_int" usebundle => hash_to_int_bench("$(i)"); + "ifelse" usebundle => ifelse_bench("$(i)"); + "intersection" usebundle => intersection_bench("$(i)"); + "isgreaterthan" usebundle => isgreaterthan_bench("$(i)"); + "islessthan" usebundle => islessthan_bench("$(i)"); + "isvariable" usebundle => isvariable_bench("$(i)"); + "join" usebundle => join_bench("$(i)"); + "laterthan" usebundle => laterthan_bench("$(i)"); + "length" usebundle => length_bench("$(i)"); + "maparray" usebundle => maparray_bench("$(i)"); + "mapdata" usebundle => mapdata_bench("$(i)"); + "maplist" usebundle => maplist_bench("$(i)"); + "max" usebundle => max_bench("$(i)"); + "mean" usebundle => mean_bench("$(i)"); + "mergedata" usebundle => mergedata_bench("$(i)"); + "min" usebundle => min_bench("$(i)"); + "none" usebundle => none_bench("$(i)"); + "not" usebundle => not_bench("$(i)"); + "now" usebundle => now_bench("$(i)"); + "nth" usebundle => nth_bench("$(i)"); + "on" usebundle => on_bench("$(i)"); + "or" usebundle => or_bench("$(i)"); + "parseintarray" usebundle => parseintarray_bench("$(i)"); + "parsejson" usebundle => parsejson_bench("$(i)"); + "parserealarray" usebundle => parserealarray_bench("$(i)"); + "parsestringarray" usebundle => parsestringarray_bench("$(i)"); + "parsestringarrayidx" usebundle => parsestringarrayidx_bench("$(i)"); + "product" usebundle => product_bench("$(i)"); + "random" usebundle => randomint_bench("$(i)"); + "regarray" usebundle => regarray_bench("$(i)"); + "regcmp" usebundle => regcmp_bench("$(i)"); + "regex_replace" usebundle => regex_replace_bench("$(i)"); + "regextract" usebundle => regextract_bench("$(i)"); + "reglist" usebundle => reglist_bench("$(i)"); + "reverse" usebundle => reverse_bench("$(i)"); + "shuffle" usebundle => shuffle_bench("$(i)"); + "some" usebundle => some_bench("$(i)"); + "sort" usebundle => sort_bench("$(i)"); + "splitstring" usebundle => splitstring_bench("$(i)"); + "storejson" usebundle => storejson_bench("$(i)"); + "strcmp" usebundle => strcmp_bench("$(i)"); + "strftime" usebundle => strftime_bench("$(i)"); + "string_downcase" usebundle => string_downcase_bench("$(i)"); + "string_head" usebundle => string_head_bench("$(i)"); + "string_length" usebundle => string_length_bench("$(i)"); + "string_mustache" usebundle => string_mustache_bench("$(i)"); + "string_replace" usebundle => string_replace_bench("$(i)"); + "string_reverse" usebundle => string_reverse_bench("$(i)"); + "string_split" usebundle => string_split_bench("$(i)"); + "string_tail" usebundle => string_tail_bench("$(i)"); + "string_upcase" usebundle => string_upcase_bench("$(i)"); + "sublist" usebundle => sublist_bench("$(i)"); + "sum" usebundle => sum_bench("$(i)"); + "translatepath" usebundle => translatepath_bench("$(i)"); + "unique" usebundle => unique_bench("$(i)"); + "validdata" usebundle => validdata_bench("$(i)"); + "validjson" usebundle => validjson_bench("$(i)"); + "variablesmatching" usebundle => variablesmatching_bench("$(i)"); + + "variablesmatching_as_data" + usebundle => variablesmatching_as_data_bench("$(i)"); + + "variance" usebundle => variance_bench("$(i)"); + "done" usebundle => print_benchmark_done_msg(); } bundle agent accumulated_bench(i) { vars: - "test" - int => accumulated("$(i)", "$(i)", "$(i)", "$(i)", "$(i)", "$(i)"); + "test" int => accumulated("$(i)", "$(i)", "$(i)", "$(i)", "$(i)", "$(i)"); + reports: - "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; + "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; } bundle agent ago_bench(i) { vars: - "test" - int => ago("$(i)", "$(i)", "$(i)", "$(i)", "$(i)", "$(i)"); + "test" int => ago("$(i)", "$(i)", "$(i)", "$(i)", "$(i)", "$(i)"); + reports: - "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; + "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; } bundle agent and_bench(i) { classes: - "test_1" - expression => and("any_$(i)", "any_$(i)"); - "test_2" - expression => and("any_$(i)", "!any_$(i)"); - "test_3" - expression => and("!any_$(i)", "any_$(i)"); - "test_4" - expression => and("!any_$(i)", "!any_$(i)"); + "test_1" expression => and("any_$(i)", "any_$(i)"); + "test_2" expression => and("any_$(i)", "!any_$(i)"); + "test_3" expression => and("!any_$(i)", "any_$(i)"); + "test_4" expression => and("!any_$(i)", "!any_$(i)"); + reports: - "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; + "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; } bundle agent basename_bench(i) { vars: - "test_1" - string => basename("/tmp/test_$(i).txt"); - "test_2" - string => basename("/tmp/test_$(i).txt", ".txt"); + "test_1" string => basename("/tmp/test_$(i).txt"); + "test_2" string => basename("/tmp/test_$(i).txt", ".txt"); + reports: - "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; + "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; } bundle agent bundlesmatching_bench(i) { vars: - "test" - slist => bundlesmatching(".*"); + "test" slist => bundlesmatching(".*"); + reports: - "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; + "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; } bundle agent bundlestate_bench(i) { vars: - "test" - data => bundlestate("benchmark"); + "test" data => bundlestate("benchmark"); + reports: - "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; + "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; } bundle agent callstack_callers_bench(i) { vars: - "test" - data => callstack_callers(); + "test" data => callstack_callers(); + reports: - "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; + "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; } bundle agent callstack_promisers_bench(i) { vars: - "test" - slist => callstack_promisers(); + "test" slist => callstack_promisers(); + reports: - "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; + "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; } bundle agent canonify_bench(i) { vars: - "test" - string => canonify("/home/root/test-$(i).txt"); + "test" string => canonify("/home/root/test-$(i).txt"); + reports: - "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; + "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; } bundle agent canonifyuniquely_bench(i) { vars: - "test" - string => canonifyuniquely("/home/root/test-$(i).txt"); + "test" string => canonifyuniquely("/home/root/test-$(i).txt"); + reports: - "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; + "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; } bundle agent cf_version_after_bench(i) { classes: - "test" - expression => cf_version_after("3.$(i)"); + "test" expression => cf_version_after("3.$(i)"); + reports: - "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; + "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; } bundle agent cf_version_at_bench(i) { classes: - "test" - expression => cf_version_at("3.$(i)"); + "test" expression => cf_version_at("3.$(i)"); + reports: - "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; + "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; } bundle agent cf_version_before_bench(i) { classes: - "test" - expression => cf_version_before("3.$(i)"); + "test" expression => cf_version_before("3.$(i)"); + reports: - "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; + "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; } bundle agent cf_version_between_bench(i) { classes: - "test" - expression => cf_version_between("3.$(i)", "4"); + "test" expression => cf_version_between("3.$(i)", "4"); + reports: - "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; + "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; } bundle agent cf_version_maximum_bench(i) { classes: - "test" - expression => cf_version_maximum("3.$(i)"); + "test" expression => cf_version_maximum("3.$(i)"); + reports: - "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; + "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; } bundle agent cf_version_minimum_bench(i) { classes: - "test" - expression => cf_version_minimum("3.$(i)"); + "test" expression => cf_version_minimum("3.$(i)"); + reports: - "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; + "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; } bundle agent classesmatching_bench(i) { vars: - "test" - slist => classesmatching(".*$(i).*"); + "test" slist => classesmatching(".*$(i).*"); + reports: - "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; + "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; } bundle agent classify_bench(i) { classes: - "test" - expression => classify("/home/root/test-$(i).txt"); + "test" expression => classify("/home/root/test-$(i).txt"); + reports: - "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; + "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; } bundle agent classmatch_bench(i) { classes: - "test" - expression => classmatch(".*$(i).*", "hardclass"); + "test" expression => classmatch(".*$(i).*", "hardclass"); + reports: - "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; + "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; } bundle agent concat_bench(i) { vars: - "test" - string => concat("file", "_$(i)", ".txt"); + "test" string => concat("file", "_$(i)", ".txt"); + reports: - "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; + "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; } bundle agent countclassesmatching_bench(i) { vars: - "test" - int => countclassesmatching(".*$(i).*"); + "test" int => countclassesmatching(".*$(i).*"); + reports: - "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; + "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; } bundle agent data_expand_bench(i) { vars: - "json" - data => '{ "i": $(i) }'; - "expanded" - data => data_expand("json"); + "json" data => '{ "i": $(i) }'; + "expanded" data => data_expand("json"); + reports: - "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; + "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; } bundle agent data_regextract_bench(i) { vars: - "parsed" - data => data_regextract("^(?...)(...)(..)-(?...)-(..).*", - "abcdef12-345-$(i)andsoon"); + "parsed" + data => data_regextract( + "^(?...)(...)(..)-(?...)-(..).*", + "abcdef12-345-$(i)andsoon" + ); + reports: - "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; + "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; } bundle agent difference_bench(i) { vars: - "a" - slist => { "a", "b", "c", "d", "e", "f", "$(i)" }; - "b" - slist => { "a", "c", "e", "g", "i", "k" }; - "diff" - slist => difference(a, b); + "a" slist => { "a", "b", "c", "d", "e", "f", "$(i)" }; + "b" slist => { "a", "c", "e", "g", "i", "k" }; + "diff" slist => difference(a, b); + reports: - "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; + "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; } bundle agent dirname_bench(i) { vars: - "dir" - string => dirname("/dir/dir_$(i)/file"); + "dir" string => dirname("/dir/dir_$(i)/file"); + reports: - "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; + "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; } bundle agent escape_bench(i) { vars: - "node" - string => format("%d", eval("($(i) - 1) % 256")); - "ip" - string => "192.168.1.$(node)"; - "escaped" - string => escape("$(ip)"); + "node" string => format("%d", eval("($(i) - 1) % 256")); + "ip" string => "192.168.1.$(node)"; + "escaped" string => escape("$(ip)"); + reports: - "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; + "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; } bundle agent eval_bench(i) { vars: - "hyp" - string => eval("sqrt( ( ($(i) * $(i)) + ($(i) * $(i)) ) )", "math", "infix"); - "same" - string => eval("$(i) == sqrt($(i) * $(i))", "class", "infix"); + "hyp" + string => eval( + "sqrt( ( ($(i) * $(i)) + ($(i) * $(i)) ) )", "math", "infix" + ); + + "same" string => eval("$(i) == sqrt($(i) * $(i))", "class", "infix"); + reports: - "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; + "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; } bundle agent every_bench(i) { vars: - "test" - slist => { "/var/cfengine/bin/cf-agent", "/var/cfengine/bin/cf-execd", "/var/cfengine/bin/rpmvercmp", "/var/cfengine/bin/cf-$(i)" }; + "test" + slist => { + "/var/cfengine/bin/cf-agent", + "/var/cfengine/bin/cf-execd", + "/var/cfengine/bin/rpmvercmp", + "/var/cfengine/bin/cf-$(i)", + }; + classes: - "yes" - expression => every("/var/cfengine/bin/.*", test); - "no" - expression => every("/var/cfengine/bin/cf-.*", test); + "yes" expression => every("/var/cfengine/bin/.*", test); + "no" expression => every("/var/cfengine/bin/cf-.*", test); + reports: - "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; + "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; } bundle agent expandrange_bench(i) { vars: - "range" - slist=> { expandrange("[0-$(i)]", "1") }; + "range" slist => { expandrange("[0-$(i)]", "1") }; + reports: - "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; + "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; } bundle agent filter_bench(i) { vars: - "natural" - slist => { expandrange("[0-$(i)]", "1") }; - "odd" - slist => filter("[0-9]*[02468]", natural, "true", "false", "inf"); + "natural" slist => { expandrange("[0-$(i)]", "1") }; + "odd" slist => filter("[0-9]*[02468]", natural, "true", "false", "inf"); + reports: - "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; + "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; } bundle agent format_bench(i) { vars: - "formatted" - string => format("num: %s", "$(i)"); + "formatted" string => format("num: %s", "$(i)"); + reports: - "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; + "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; } bundle agent getclassmetatags_bench(i) { classes: - "myclass" - expression => "any", - meta => { "tag_$(i)" }; + "myclass" + expression => "any", + meta => { "tag_$(i)" }; + vars: - "metatags" - slist => getclassmetatags("myclass"); + "metatags" slist => getclassmetatags("myclass"); + reports: - "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; + "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; } bundle agent getindices_bench(i) { vars: - "test[i$(i)]" - string => "v$(i)"; - "indices" - slist => getindices(test); + "test[i$(i)]" string => "v$(i)"; + "indices" slist => getindices(test); + reports: - "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; + "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; } bundle agent getvalues_bench(i) { vars: - "test[i$(i)]" - string => "v$(i)"; - "values" - slist => getvalues(test); + "test[i$(i)]" string => "v$(i)"; + "values" slist => getvalues(test); + reports: - "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; + "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; } bundle agent getvariablemetatags_bench(i) { vars: - "myvar" - string => "hello", - meta => { "tag_$(i)" }; - "metatags" - slist => getvariablemetatags(myvar); + "myvar" + string => "hello", + meta => { "tag_$(i)" }; + + "metatags" slist => getvariablemetatags(myvar); + reports: - "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; + "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; } bundle agent grep_bench(i) { vars: - "mylist" - slist => { "One", "Two", "Three", "Four", "Five", "T$(i)" }; - "tlist" - slist => grep("T.*", mylist); + "mylist" slist => { "One", "Two", "Three", "Four", "Five", "T$(i)" }; + "tlist" slist => grep("T.*", mylist); + reports: - "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; + "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; } bundle agent hash_bench(i) { vars: - "md5" string => hash("Cfengine $(i) is not cryptic","md5"); - "sha256" string => hash("Cfengine $(i) is not cryptic","sha256"); - "sha384" string => hash("Cfengine $(i) is not cryptic","sha384"); - "sha512" string => hash("Cfengine $(i) is not cryptic","sha512"); + "md5" string => hash("Cfengine $(i) is not cryptic", "md5"); + "sha256" string => hash("Cfengine $(i) is not cryptic", "sha256"); + "sha384" string => hash("Cfengine $(i) is not cryptic", "sha384"); + "sha512" string => hash("Cfengine $(i) is not cryptic", "sha512"); + reports: - "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; + "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; } bundle agent hash_to_int_bench(i) { vars: - "a" int => hash_to_int(0, "$(i)", "hello"); - "b" int => hash_to_int(0, "$(i)", "world"); - "c" int => hash_to_int(0, "$(i)", "$(sys.key_digest)"); - "d" int => hash_to_int(0, "$(i)", "$(sys.policy_hub)"); + "a" int => hash_to_int(0, "$(i)", "hello"); + "b" int => hash_to_int(0, "$(i)", "world"); + "c" int => hash_to_int(0, "$(i)", "$(sys.key_digest)"); + "d" int => hash_to_int(0, "$(i)", "$(sys.policy_hub)"); + reports: - "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; + "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; } bundle agent ifelse_bench(i) { vars: - "outcome" - string => ifelse(regcmp("[0-9]*[02468]", "$(i)"), "is odd", - regcmp("[0-9]", "$(i)"), "is less than 10", - "is even"); + "outcome" + string => ifelse( + regcmp("[0-9]*[02468]", "$(i)"), + "is odd", + regcmp("[0-9]", "$(i)"), + "is less than 10", + "is even" + ); + reports: - "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; + "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; } bundle agent intersection_bench(i) { vars: - "a" - slist => { "a", "b", "c", "d", "e", "f", "$(i)" }; - "b" - slist => { "a", "c", "e", "g", "i", "k", "$(i)" }; - "inter" - slist => intersection(a, b); + "a" slist => { "a", "b", "c", "d", "e", "f", "$(i)" }; + "b" slist => { "a", "c", "e", "g", "i", "k", "$(i)" }; + "inter" slist => intersection(a, b); + reports: - "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; + "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; } bundle agent isgreaterthan_bench(i) { classes: - "indeed" - expression => isgreaterthan("5", "$(i)"); + "indeed" expression => isgreaterthan("5", "$(i)"); + reports: - "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; + "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; } bundle agent islessthan_bench(i) { classes: - "indeed" - expression => islessthan("5", "$(i)"); + "indeed" expression => islessthan("5", "$(i)"); + reports: - "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; + "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; } bundle agent isvariable_bench(i) { vars: - "defined_$(i)" - string => "this var is defined"; + "defined_$(i)" string => "this var is defined"; + classes: - "test_1" - expression => isvariable("defined_$(i)"); - "test_2" - expression => isvariable("undefined_$(i)"); + "test_1" expression => isvariable("defined_$(i)"); + "test_2" expression => isvariable("undefined_$(i)"); + reports: - "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; + "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; } bundle agent join_bench(i) { vars: - "list" - slist => { "a", "b", "c", "d", "e", "$(i)" }; - "joined_list" - string => join(", ", list); - "dat" - data => '[ "a", "b", "c", "d", "e", "$(i)" ]'; - "joined_data" - string => join("->", dat); + "list" slist => { "a", "b", "c", "d", "e", "$(i)" }; + "joined_list" string => join(", ", list); + "dat" data => '[ "a", "b", "c", "d", "e", "$(i)" ]'; + "joined_data" string => join("->", dat); + reports: - "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; + "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; } bundle agent laterthan_bench(i) { classes: - "test" - expression => laterthan("$(i)", "$(i)", "$(i)", "$(i)", "$(i)", "$(i)"); + "test" + expression => laterthan("$(i)", "$(i)", "$(i)", "$(i)", "$(i)", "$(i)"); + reports: - "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; + "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; } bundle agent length_bench(i) { vars: - "list" - slist => { expandrange("[0-$(i)]", "1") }; - "len" - int => length(list); + "list" slist => { expandrange("[0-$(i)]", "1") }; + "len" int => length(list); + reports: - "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; + "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; } bundle agent maparray_bench(i) { vars: - "arr[0]" - string => "a"; - "arr[1]" - string => "b"; - "arr[2]" - string => "c"; - "arr[3]" - string => "d"; - "arr[4]" - string => "e"; - "arr[5]" - string => "$(i)"; - "mapped" - slist => maparray("key=$(this.k), val=$(this.v)", arr); + "arr[0]" string => "a"; + "arr[1]" string => "b"; + "arr[2]" string => "c"; + "arr[3]" string => "d"; + "arr[4]" string => "e"; + "arr[5]" string => "$(i)"; + "mapped" slist => maparray("key=$(this.k), val=$(this.v)", arr); + reports: - "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; + "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; } bundle agent mapdata_bench(i) { vars: - "dat" - data => '{ "name": "alice", "age": $(i) }'; - "map_json" - data => mapdata("json", '{ "key": "$(this.k)", "value": "$(this.v)" }', dat); + "dat" data => '{ "name": "alice", "age": $(i) }'; + + "map_json" + data => mapdata( + "json", '{ "key": "$(this.k)", "value": "$(this.v)" }', dat + ); + reports: - "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; + "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; } bundle agent maplist_bench(i) { vars: - "list" - slist => { "a", "b", "c", "d", "e", "$(i)" }; - "mapped" - slist => maplist("Element: $(this)", list); + "list" slist => { "a", "b", "c", "d", "e", "$(i)" }; + "mapped" slist => maplist("Element: $(this)", list); + reports: - "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; + "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; } bundle agent max_bench(i) { vars: - "alpha" - slist => { "a", "c", "b", "d", "f", "$(i)" }; - "numer" - ilist => { 1, 3, 2, 4, 6, "$(i)" }; - "alpha_max" - string => max(alpha, "lex"); - "numer_max" - string => max(numer, "int"); + "alpha" slist => { "a", "c", "b", "d", "f", "$(i)" }; + "numer" ilist => { 1, 3, 2, 4, 6, "$(i)" }; + "alpha_max" string => max(alpha, "lex"); + "numer_max" string => max(numer, "int"); + reports: - "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; + "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; } bundle agent mean_bench(i) { vars: - "list" - slist => { "a", "1", "b", "2", "f", "$(i)" }; - "mean" - real => mean(list); + "list" slist => { "a", "1", "b", "2", "f", "$(i)" }; + "mean" real => mean(list); + reports: - "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; + "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; } bundle agent mergedata_bench(i) { vars: - "d1" - data => '{ "name": "alice" }'; - "d2" - data => '{ "age": $(i) }'; - "data" - data => mergedata(d1, d2); + "d1" data => '{ "name": "alice" }'; + "d2" data => '{ "age": $(i) }'; + "data" data => mergedata(d1, d2); + reports: - "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; + "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; } bundle agent min_bench(i) { vars: - "alpha" - slist => { "a", "c", "b", "d", "f", "$(i)" }; - "numer" - ilist => { 1, 3, 2, 4, 6, "$(i)" }; - "alpha_min" - string => min(alpha, "lex"); - "numer_min" - string => min(numer, "int"); + "alpha" slist => { "a", "c", "b", "d", "f", "$(i)" }; + "numer" ilist => { 1, 3, 2, 4, 6, "$(i)" }; + "alpha_min" string => min(alpha, "lex"); + "numer_min" string => min(numer, "int"); + reports: - "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; + "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; } bundle agent none_bench(i) { vars: - "list" - slist => { "a", "b", "c", "$(i)" }; + "list" slist => { "a", "b", "c", "$(i)" }; + classes: - "test_2" - expression => none("[0-9]", list); + "test_2" expression => none("[0-9]", list); + reports: - "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; + "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; } bundle agent not_bench(i) { classes: - "myclass_$(i)" - expression => "any"; - "yes" - expression => not("!myclass_$(i)"); - "no" - expression => not("myclass_$(i)"); + "myclass_$(i)" expression => "any"; + "yes" expression => not("!myclass_$(i)"); + "no" expression => not("myclass_$(i)"); + reports: - "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; + "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; } bundle agent now_bench(i) { vars: - "epoch" - int => now(); + "epoch" int => now(); + reports: - "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; + "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; } bundle agent nth_bench(i) { vars: - "list" - slist => { "a", "b", "c", "d", "e", "$(i)" }; - "first" - string => nth(list, "0"); - "second" - string => nth(list, "1"); - "third" - string => nth(list, "2"); - "forth" - string => nth(list, "3"); - "fifth" - string => nth(list, "4"); - "sixth" - string => nth(list, "5"); + "list" slist => { "a", "b", "c", "d", "e", "$(i)" }; + "first" string => nth(list, "0"); + "second" string => nth(list, "1"); + "third" string => nth(list, "2"); + "forth" string => nth(list, "3"); + "fifth" string => nth(list, "4"); + "sixth" string => nth(list, "5"); + reports: - "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; + "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; } bundle agent on_bench(i) { vars: - "epoch" - int => on("$(i)", "$(i)", "$(i)", "$(i)", "$(i)", "$(i)"); + "epoch" int => on("$(i)", "$(i)", "$(i)", "$(i)", "$(i)", "$(i)"); + reports: - "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; + "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; } bundle agent or_bench(i) { classes: - "myclass_$(i)" - expression => "any"; - "test_1" - expression => or("myclass_$(i)", "myclass_$(i)"); - "test_2" - expression => or("myclass_$(i)", "!myclass_$(i)"); - "test_3" - expression => or("!myclass_$(i)", "myclass_$(i)"); - "test_3" - expression => or("!myclass_$(i)", "!myclass_$(i)"); + "myclass_$(i)" expression => "any"; + "test_1" expression => or("myclass_$(i)", "myclass_$(i)"); + "test_2" expression => or("myclass_$(i)", "!myclass_$(i)"); + "test_3" expression => or("!myclass_$(i)", "myclass_$(i)"); + "test_3" expression => or("!myclass_$(i)", "!myclass_$(i)"); + reports: - "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; + "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; } bundle agent parseintarray_bench(i) { vars: - # Define data inline for convenience - "table" - string => - "1:2 + # Define data inline for convenience + "table" string => "1:2 3:4 $(i):6"; - "dim" - int => parseintarray("items", "$(table)", "\s*#[^\n]*", ":", "1000", "200000"); + + "dim" + int => parseintarray( + "items", "$(table)", "\s*#[^\n]*", ":", "1000", "200000" + ); + reports: - "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; + "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; } bundle agent parsejson_bench(i) { vars: - "json" - string => '{ "name": "alice", "age": $(i) }'; - "data" - data => parsejson("$(json)"); + "json" string => '{ "name": "alice", "age": $(i) }'; + "data" data => parsejson("$(json)"); + reports: - "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; + "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; } bundle agent parserealarray_bench(i) { vars: - "table" - string => - "1.1:2.2 + "table" string => "1.1:2.2 3.3:4.4 $(i).5:6.6"; - "dim" - int => parserealarray("items", "$(table)", "\s*#[^\n]*", ":", "1000", "200000"); + + "dim" + int => parserealarray( + "items", "$(table)", "\s*#[^\n]*", ":", "1000", "200000" + ); + reports: - "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; + "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; } bundle agent parsestringarray_bench(i) { - vars: - "table" - string => - "a:b + vars: + "table" string => "a:b c:d $(i):f"; - "dim" - int => parsestringarray("items", "$(table)", "\s*#[^\n]*", ":", "1000", "200000"); + + "dim" + int => parsestringarray( + "items", "$(table)", "\s*#[^\n]*", ":", "1000", "200000" + ); + reports: - "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; + "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; } bundle agent parsestringarrayidx_bench(i) { - vars: - "table" - string => - "one: a + vars: + "table" string => "one: a two: b $(i): c"; - "dim" - int => parsestringarrayidx("items", "$(table)", "\s*#[^\n]*", ":", "1000", "200000"); + + "dim" + int => parsestringarrayidx( + "items", "$(table)", "\s*#[^\n]*", ":", "1000", "200000" + ); + reports: - "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; + "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; } bundle agent product_bench(i) { vars: - "series" - rlist => { "1.1", "1.2", "2.3", "3.$(i)" }; - "prod" - real => product(series); + "series" rlist => { "1.1", "1.2", "2.3", "3.$(i)" }; + "prod" real => product(series); + reports: - "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; + "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; } bundle agent randomint_bench(i) { vars: - "rand" - int => randomint("0", "$(i)"); + "rand" int => randomint("0", "$(i)"); + reports: - "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; + "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; } bundle agent regarray_bench(i) { vars: - "array[0]" - string => "a1"; - "array[1]" - string => "a2"; - "array[2]" - string => "b$(i)"; + "array[0]" string => "a1"; + "array[1]" string => "a2"; + "array[2]" string => "b$(i)"; + classes: - "yes" - expression => regarray(array, "[ab][123]"); - "no" - expression => regarray(array, "[cd][456]"); + "yes" expression => regarray(array, "[ab][123]"); + "no" expression => regarray(array, "[cd][456]"); + reports: - "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; + "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; } bundle agent regcmp_bench(i) { classes: - "odd" - expression => regcmp("[0-9]*[02468]", "$(i)"); - "par" - expression => regcmp("[0-9]*[13579]", "$(i)"); + "odd" expression => regcmp("[0-9]*[02468]", "$(i)"); + "par" expression => regcmp("[0-9]*[13579]", "$(i)"); + reports: - "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; + "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; } bundle agent regex_replace_bench(i) { vars: - "str" - string => regex_replace("$(i)", "[0-9]*[02468]", "odd", "i"); + "str" string => regex_replace("$(i)", "[0-9]*[02468]", "odd", "i"); + reports: - "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; + "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; } bundle agent regextract_bench(i) { classes: - "ok" - expression => regextract("abc([0-9]+)def", "abc$(i)def", "arr"); + "ok" expression => regextract("abc([0-9]+)def", "abc$(i)def", "arr"); + reports: - "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; + "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; } bundle agent reglist_bench(i) { vars: - "test" - slist => { "a", "$(i)", "c" }; + "test" slist => { "a", "$(i)", "c" }; + classes: - "yes" - expression => reglist("@(test)", "[0-9]*[02468]"); + "yes" expression => reglist("@(test)", "[0-9]*[02468]"); + reports: - "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; + "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; } bundle agent reverse_bench(i) { vars: - "test" - slist => { "a", "b", "c", "1", "2", "$(i)" }; - "reversed" - slist => reverse(test); + "test" slist => { "a", "b", "c", "1", "2", "$(i)" }; + "reversed" slist => reverse(test); + reports: - "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; + "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; } bundle agent shuffle_bench(i) { vars: - "test" - slist => { "a", "b", "c", "1", "2", "3" }; - "shuffled" - slist => shuffle(test, "seed_$(i)"); + "test" slist => { "a", "b", "c", "1", "2", "3" }; + "shuffled" slist => shuffle(test, "seed_$(i)"); + reports: - "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; + "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; } bundle agent some_bench(i) { vars: - "test" - slist => { "a", "b", "c", "1", "$(i)", "3" }; + "test" slist => { "a", "b", "c", "1", "$(i)", "3" }; + classes: - "yes" - expression => some("[0-9]*[02468]", test); + "yes" expression => some("[0-9]*[02468]", test); + reports: - "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; + "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; } bundle agent sort_bench(i) { vars: - "test" - slist => { "1", "2", "3", "4", "5", "$(i)" }; - "shuffled" - slist => shuffle(test, "seed_$(i)"); - "lex" - slist => sort(shuffled, "lex"); - "int" - slist => sort(shuffled, "int"); + "test" slist => { "1", "2", "3", "4", "5", "$(i)" }; + "shuffled" slist => shuffle(test, "seed_$(i)"); + "lex" slist => sort(shuffled, "lex"); + "int" slist => sort(shuffled, "int"); + reports: - "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; + "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; } bundle agent splitstring_bench(i) { vars: - "test" - string => "1.5;2.3;$(i).0"; - "split" - slist => splitstring("$(test)", ";", "inf"); + "test" string => "1.5;2.3;$(i).0"; + "split" slist => splitstring("$(test)", ";", "inf"); + reports: - "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; + "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; } bundle agent storejson_bench(i) { vars: - "dat" - data => '{ "name": "alice", "age": $(i) }'; - "json" - string => storejson(dat); + "dat" data => '{ "name": "alice", "age": $(i) }'; + "json" string => storejson(dat); + reports: - "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; + "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; } bundle agent strcmp_bench(i) { classes: - "same" - expression => strcmp("test$(i)", "test$(i)"); - "diff" - expression => strcmp("$(i)test", "test$(i)"); + "same" expression => strcmp("test$(i)", "test$(i)"); + "diff" expression => strcmp("$(i)test", "test$(i)"); + reports: - "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; + "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; } bundle agent strftime_bench(i) { vars: - "at_time" - string => strftime("localtime", "%Y-%m-%d %T", "$(i)"); - "gmt_at_time" - string => strftime("gmtime", "%Y-%m-%d %T", "$(i)"); + "at_time" string => strftime("localtime", "%Y-%m-%d %T", "$(i)"); + "gmt_at_time" string => strftime("gmtime", "%Y-%m-%d %T", "$(i)"); + reports: - "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; + "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; } bundle agent string_downcase_bench(i) { vars: - "downcase" - string => string_downcase("AbC dEf_$(i)"); + "downcase" string => string_downcase("AbC dEf_$(i)"); + reports: - "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; + "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; } bundle agent string_head_bench(i) { vars: - "str" - string => "a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, 1, 2, 3, 4, 5, 6, 7, 8, 9"; - "head" - string => string_head("$(str)", "$(i)"); + "str" + string => "a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, 1, 2, 3, 4, 5, 6, 7, 8, 9"; + + "head" string => string_head("$(str)", "$(i)"); + reports: - "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; + "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; } bundle agent string_length_bench(i) { vars: - "len" - int => string_length("Hello world $(i)!"); + "len" int => string_length("Hello world $(i)!"); + reports: - "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; + "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; } bundle agent string_mustache_bench(i) { vars: - "deserts" - data => parsejson('{"deserts":{"Africa":"Sahara","Asia":"Gobi"}}'); - "data" - string => string_mustache("from container $(i): deserts = {{%deserts}}from container: {{#deserts}}The desert {{.}} is in {{@}}. {{/deserts}}", deserts); + "deserts" + data => parsejson('{"deserts":{"Africa":"Sahara","Asia":"Gobi"}}'); + + "data" + string => string_mustache( + "from container $(i): deserts = {{%deserts}}from container: {{#deserts}}The desert {{.}} is in {{@}}. {{/deserts}}", + deserts + ); + reports: - "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; + "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; } bundle agent string_replace_bench(i) { vars: - "str" - string => string_replace("This is a string $(i)", "string", "thing"); + "str" string => string_replace("This is a string $(i)", "string", "thing"); + reports: - "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; + "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; } bundle agent string_reverse_bench(i) { vars: - "str" - string => string_reverse("abcdefghijklmnopqrstuvwxyz$(i)"); + "str" string => string_reverse("abcdefghijklmnopqrstuvwxyz$(i)"); + reports: - "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; + "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; } bundle agent string_split_bench(i) { vars: - "split" - slist => string_split("a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z", ",", "$(i)"); + "split" + slist => string_split( + "a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z", ",", "$(i)" + ); + reports: - "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; + "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; } bundle agent string_tail_bench(i) { vars: - "tail" - string => string_tail("a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z", "$(i)"); + "tail" + string => string_tail( + "a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z", + "$(i)" + ); + reports: - "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; + "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; } bundle agent string_upcase_bench(i) { vars: - "upcase" - string => string_upcase("AbC dEf_$(i)"); + "upcase" string => string_upcase("AbC dEf_$(i)"); + reports: - "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; + "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; } bundle agent sublist_bench(i) { vars: - "list" - slist => { "a", "b", "c", "d", "e", "f", "g", - "h", "i", "j", "k", "l", "m", "n", - "o", "p", "q", "r", "s", "t", "u", - "v", "x", "y", "z" }; - "sub_head" - slist => sublist(list, "head", "$(i)"); - "sub_tail" - slist => sublist(list, "tail", "$(i)"); - reports: - "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; + "list" + slist => { + "a", + "b", + "c", + "d", + "e", + "f", + "g", + "h", + "i", + "j", + "k", + "l", + "m", + "n", + "o", + "p", + "q", + "r", + "s", + "t", + "u", + "v", + "x", + "y", + "z", + }; + + "sub_head" slist => sublist(list, "head", "$(i)"); + "sub_tail" slist => sublist(list, "tail", "$(i)"); + + reports: + "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; } bundle agent sum_bench(i) { vars: - "nums" - ilist => { "1", "2", "3", "4", "5", "$(i)" }; - "num_sum" - real => sum(nums); + "nums" ilist => { "1", "2", "3", "4", "5", "$(i)" }; + "num_sum" real => sum(nums); + reports: - "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; + "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; } bundle agent translatepath_bench(i) { vars: - "path" - string => translatepath("/a/b/c/file_$(i).txt"); + "path" string => translatepath("/a/b/c/file_$(i).txt"); + reports: - "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; + "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; } bundle agent unique_bench(i) { vars: - "uni" - slist => { "one", "two", "three", - "1", "2", "3", - "one", "$(i)", "two" }; + "uni" + slist => { "one", "two", "three", "1", "2", "3", "one", "$(i)", "two" }; + reports: - "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; + "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; } bundle agent validdata_bench(i) { classes: - "is_valid" - expression => validdata('{ "name": "alice", "age": $(i) }', "JSON"); - "not_valid" - expression => validdata('{ "name": "alice", "age": $(i) ]', "JSON"); + "is_valid" + expression => validdata('{ "name": "alice", "age": $(i) }', "JSON"); + + "not_valid" + expression => validdata('{ "name": "alice", "age": $(i) ]', "JSON"); + reports: - "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; + "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; } bundle agent validjson_bench(i) { classes: - "is_valid" - expression => validjson('{ "name": "alice", "age": $(i) }'); - "not_valid" - expression => validjson('{ "name": "alice", "age": $(i) ]'); + "is_valid" expression => validjson('{ "name": "alice", "age": $(i) }'); + "not_valid" expression => validjson('{ "name": "alice", "age": $(i) ]'); + reports: - "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; + "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; } bundle agent variablesmatching_bench(i) { vars: - "matches" - slist => variablesmatching(".*$(i).*", "source=agent"); + "matches" slist => variablesmatching(".*$(i).*", "source=agent"); + reports: - "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; + "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; } bundle agent variablesmatching_as_data_bench(i) { vars: - "matches" - data => variablesmatching_as_data(".*$(i).*", "source=agent"); + "matches" data => variablesmatching_as_data(".*$(i).*", "source=agent"); + reports: - "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; + "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; } bundle agent variance_bench(i) { vars: - "nums" - ilist => { "1", "2", "3", "$(i) " }; - "vari" - real => variance(nums); + "nums" ilist => { "1", "2", "3", "$(i) " }; + "vari" real => variance(nums); + reports: - "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; + "Benching '$(this.bundle)' ($(i)/$(benchmark.n)) ..."; } bundle agent print_benchmark_done_msg() diff --git a/examples/const.cf b/examples/const.cf index 1403c7ec17..b730ea1108 100644 --- a/examples/const.cf +++ b/examples/const.cf @@ -3,35 +3,36 @@ bundle agent __main__ # @brief Example illustrating cosnt vars { vars: - "example_file" - string => "/tmp/const-vars.txt"; + "example_file" string => "/tmp/const-vars.txt"; files: - "$(example_file)" - create => "true", - content => concat("CFEngine const vars$(const.n)", - "before const.at $(const.at) after const.at$(const.n)", - "before const.dollar $(const.dollar) after const.dollar$(const.n)", - "before const.dirsep $(const.dirsep) after const.dirsep$(const.n)", - "before const.linesep $(const.linesep) after const.linesep$(const.n)", - "before const.endl$(const.endl) after const.endl$(const.n)", - "before const.n$(const.n) after const.n$(const.n)", - "before const.r $(const.r) after const.r$(const.n)", - "before const.t $(const.t) after const.t$(const.n)"); + "$(example_file)" + create => "true", + content => concat( + "CFEngine const vars$(const.n)", + "before const.at $(const.at) after const.at$(const.n)", + "before const.dollar $(const.dollar) after const.dollar$(const.n)", + "before const.dirsep $(const.dirsep) after const.dirsep$(const.n)", + "before const.linesep $(const.linesep) after const.linesep$(const.n)", + "before const.endl$(const.endl) after const.endl$(const.n)", + "before const.n$(const.n) after const.n$(const.n)", + "before const.r $(const.r) after const.r$(const.n)", + "before const.t $(const.t) after const.t$(const.n)" + ); reports: - "const vars available: $(with)" - with => storejson( variablesmatching_as_data( "default:const\..*" ) ); + "const vars available: $(with)" + with => storejson(variablesmatching_as_data("default:const\..*")); - "$(example_file):" - printfile => cat( "$(example_file)" ); + "$(example_file):" printfile => cat("$(example_file)"); } + body printfile cat(file) # @brief Report the contents of a file # @param file The full path of the file to report { - file_to_print => "$(file)"; - number_of_lines => "inf"; + file_to_print => "$(file)"; + number_of_lines => "inf"; } #+end_src ############################################################################### diff --git a/examples/container_iteration.cf b/examples/container_iteration.cf index 2d674129b9..ca65d250a4 100644 --- a/examples/container_iteration.cf +++ b/examples/container_iteration.cf @@ -1,50 +1,50 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - #+begin_src cfengine3 body common control { - bundlesequence => { run }; + bundlesequence => { run }; } bundle agent run { vars: - "x" data => parsejson('[ + "x" + data => parsejson( + '[ { "one": "a" }, { "two": "b" }, { "three": "c" } -]'); +]' + ); - # get the numeric indices of x: 0, 1, 2 - "xi" slist => getindices(x); + # get the numeric indices of x: 0, 1, 2 + "xi" slist => getindices(x); - # for each xi, make a variable xpiece_$(xi) so we'll have - # xpiece_0, xpiece_1, xpiece_2. Each xpiece will have that - # particular element of the list x. - "xpiece_$(xi)" string => format("%S", "x[$(xi)]"); + # for each xi, make a variable xpiece_$(xi) so we'll have + # xpiece_0, xpiece_1, xpiece_2. Each xpiece will have that + # particular element of the list x. + "xpiece_$(xi)" string => format("%S", "x[$(xi)]"); reports: - "$(xi): $(xpiece_$(xi))"; + "$(xi): $(xpiece_$(xi))"; } #+end_src ############################################################################### diff --git a/examples/container_key_iteration.cf b/examples/container_key_iteration.cf index a01da5c7dc..3430793bdd 100644 --- a/examples/container_key_iteration.cf +++ b/examples/container_key_iteration.cf @@ -1,61 +1,60 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - #+begin_src cfengine3 body common control { - bundlesequence => { run }; + bundlesequence => { run }; } bundle agent run { vars: - "animals" data => parsejson(' + "animals" + data => parsejson( + ' { "dog": { "legs": 4, "tail": true, "names": [ "Fido", "Cooper", "Sandy" ] }, "cat": { "legs": 4, "tail": true, "names": [ "Fluffy", "Snowball", "Tabby" ] }, "dolphin": { "legs": 0, "tail": true, "names": [ "Flipper", "Duffy" ] }, "hamster": { "legs": 4, "tail": true, "names": [ "Skullcrusher", "Kimmy", "Fluffadoo" ] }, - }'); - - "keys_unsorted" slist => getindices("animals"); - "keys" slist => sort(keys_unsorted, "lex"); + }' + ); - "animals_$(keys)" data => mergedata("animals[$(keys)]"); + "keys_unsorted" slist => getindices("animals"); + "keys" slist => sort(keys_unsorted, "lex"); + "animals_$(keys)" data => mergedata("animals[$(keys)]"); methods: - # pass the container and a key inside it - "any" usebundle => analyze(@(animals), $(keys)); + # pass the container and a key inside it + "any" usebundle => analyze(@(animals), $(keys)); } bundle agent analyze(animals, a) { vars: - "names" slist => getvalues("animals[$(a)][names]"); - "names_str" string => format("%S", names); + "names" slist => getvalues("animals[$(a)][names]"); + "names_str" string => format("%S", names); reports: - "$(this.bundle): possible names for animal '$(a)': $(names_str)"; - "$(this.bundle): describe animal '$(a)' => name = $(a), legs = $(animals[$(a)][legs]), tail = $(animals[$(a)][tail])"; + "$(this.bundle): possible names for animal '$(a)': $(names_str)"; + "$(this.bundle): describe animal '$(a)' => name = $(a), legs = $(animals[$(a)][legs]), tail = $(animals[$(a)][tail])"; } #+end_src ############################################################################### diff --git a/examples/control_expand.cf b/examples/control_expand.cf index 0168ce0d41..2ad06c4f8e 100644 --- a/examples/control_expand.cf +++ b/examples/control_expand.cf @@ -1,91 +1,75 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - - bundle common g { classes: - - "softclass" expression => "any"; + "softclass" expression => "any"; vars: - - "bundle" slist => { "bundle1", "bundle2", @(g.extra) }; + "bundle" slist => { "bundle1", "bundle2", @(g.extra) }; any:: - # default extra - - "extra" slist => { "bundle3" }, - policy => "overridable"; + "extra" + slist => { "bundle3" }, + policy => "overridable"; softclass:: - - "extra" slist => { "bundle3", "bundle4" }, - policy => "overridable"; - + "extra" + slist => { "bundle3", "bundle4" }, + policy => "overridable"; } - ############################################################## - body common control { - bundlesequence => { @(g.bundle) }; + bundlesequence => { @(g.bundle) }; } - ############################################################## - bundle agent bundle1 { vars: - - "var1" string => "anything"; - "bundle" slist => { @(g.bundle) }; + "var1" string => "anything"; + "bundle" slist => { @(g.bundle) }; reports: - "$(bundle)"; + "$(bundle)"; } bundle agent bundle2 { classes: - - "ok" expression => isvariable("bundle1.var1"); + "ok" expression => isvariable("bundle1.var1"); reports: - ok:: - "Success"; } bundle agent bundle3 { reports: - "Success extra..."; + "Success extra..."; } bundle agent bundle4 { reports: - "Success extra more..."; + "Success extra more..."; } diff --git a/examples/copy.cf b/examples/copy.cf index 375b4d6611..d6eb7a255d 100644 --- a/examples/copy.cf +++ b/examples/copy.cf @@ -1,40 +1,36 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - body common control { - bundlesequence => { "copy" }; + bundlesequence => { "copy" }; } bundle agent copy { files: - "/tmp/testfile1-cop" copy_from => mycopy("/tmp/testfile1", "gudea"); - "/tmp/testfile2-cop" copy_from => mycopy("/tmp/testfile2", "gudea"); + "/tmp/testfile1-cop" copy_from => mycopy("/tmp/testfile1", "gudea"); + "/tmp/testfile2-cop" copy_from => mycopy("/tmp/testfile2", "gudea"); } -body copy_from mycopy(from,server) +body copy_from mycopy(from, server) { - source => "$(from)"; - #servers => { "$(server)" }; + source => "$(from)"; + #servers => { "$(server)" }; } - diff --git a/examples/copy_classes.cf b/examples/copy_classes.cf index 688024a27b..1c347c1bc9 100644 --- a/examples/copy_classes.cf +++ b/examples/copy_classes.cf @@ -1,43 +1,37 @@ -body common control +body common control { - bundlesequence => { "copy_file"}; - - inputs => { "$(sys.libdir)/stdlib.cf" }; + bundlesequence => { "copy_file" }; + inputs => { "$(sys.libdir)/stdlib.cf" }; } - ###################################################### - -bundle agent copy_file() +bundle agent copy_file() { files: - - "/tmp/non_existent" + "/tmp/non_existent" copy_from => local_cp_compare("/non_existent"), # perms => m("777"), action => warn_only, classes => check_promises("NE_NE"); - - "/tmp/non_existent" + "/tmp/non_existent" copy_from => local_cp_compare("/tmp/existent_file"), # perms => m("777"), action => warn_only, classes => check_promises("NE_E"); - - "/tmp/existent_file" + "/tmp/existent_file" copy_from => local_cp_compare("/tmp/existent_file"), # perms => m("777"), action => warn_only, classes => check_promises("E_E"); - "/tmp/existent_file" + "/tmp/existent_file" copy_from => local_cp_compare("/tmp/different_file"), # perms => m("777"), action => warn_only, classes => check_promises("D_E"); - "/tmp/existent_file" + "/tmp/existent_file" copy_from => local_cp_compare("/non_existent"), # perms => m("777"), action => warn_only, @@ -46,81 +40,92 @@ bundle agent copy_file() reports: NE_NE_kept:: "NE_NE_kept"; + NE_NE_repaired:: "NE_NE_repaired"; + NE_NE_failed:: "NE_NE_failed"; + NE_NE_denied:: "NE_NE_denied"; + NE_NE_timeout:: "NE_NE_timeout"; NE_E_kept:: "NE_E_kept"; + NE_E_repaired:: "NE_E_repaired"; + NE_E_failed:: "NE_E_failed"; + NE_E_denied:: "NE_E_denied"; + NE_E_timeout:: "NE_E_timeout"; - E_E_kept:: "E_E_kept"; + E_E_repaired:: "E_E_repaired"; + E_E_failed:: "E_E_failed"; + E_E_denied:: "E_E_denied"; + E_E_timeout:: "E_E_timeout"; - D_E_kept:: "D_E_kept"; + D_E_repaired:: "D_E_repaired"; + D_E_failed:: "D_E_failed"; + D_E_denied:: "D_E_denied"; + D_E_timeout:: "D_E_timeout"; E_NE_kept:: "E_NE_kept"; + E_NE_repaired:: "E_NE_repaired"; + E_NE_failed:: "E_NE_failed"; + E_NE_denied:: "E_NE_denied"; + E_NE_timeout:: "E_NE_timeout"; } - ###################################################### - body classes check_promises(prom) { - promise_kept => { "$(prom)_kept" }; - promise_repaired => { "$(prom)_repaired" }; - - repair_failed => { "$(prom)_failed" }; - repair_denied => { "$(prom)_denied" }; - repair_timeout => { "$(prom)_timeout" }; + promise_kept => { "$(prom)_kept" }; + promise_repaired => { "$(prom)_repaired" }; + repair_failed => { "$(prom)_failed" }; + repair_denied => { "$(prom)_denied" }; + repair_timeout => { "$(prom)_timeout" }; } - ###################################################### - body copy_from local_cp_compare(from) { - source => "$(from)"; - verify => "true"; - compare => "hash"; + source => "$(from)"; + verify => "true"; + compare => "hash"; } - - diff --git a/examples/copy_copbl.cf b/examples/copy_copbl.cf index d2269f4950..c1dd7c4134 100644 --- a/examples/copy_copbl.cf +++ b/examples/copy_copbl.cf @@ -1,45 +1,41 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - body common control { - bundlesequence => { "mycopy" }; - inputs => { "$(sys.libdir)/stdlib.cf" }; + bundlesequence => { "mycopy" }; + inputs => { "$(sys.libdir)/stdlib.cf" }; } bundle agent mycopy { files: - "/tmp/test_plain" - -#@ Path and name of the file we wish to copy to - + "/tmp/test_plain" + #@ Path and name of the file we wish to copy to comment => "/tmp/test_plain promises to be an up-to-date copy of /bin/echo to demonstrate copying a local file", copy_from => local_cp("$(sys.workdir)/bin/file"); -#@ Copy locally from path/filename - - "/tmp/test_remote_plain" + #@ Copy locally from path/filename + "/tmp/test_remote_plain" comment => "/tmp/test_plain_remote promises to be a copy of cfengine://serverhost.example.org/repo/config-files/motd", - copy_from => secure_cp("/repo/config-files/motd", "serverhost.example.org"); + copy_from => secure_cp( + "/repo/config-files/motd", "serverhost.example.org" + ); } #@ Copy remotely from path/filename and specified host diff --git a/examples/copy_edit.cf b/examples/copy_edit.cf index 5f89d55b69..974e749e63 100644 --- a/examples/copy_edit.cf +++ b/examples/copy_edit.cf @@ -1,118 +1,85 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - ######################################################## # # Copy and edit convergently # ######################################################## - body common control - { - bundlesequence => { "example" }; - version => "1.2.3"; + bundlesequence => { "example" }; + version => "1.2.3"; } - ######################################################## - bundle agent example - { vars: - - "source" string => "/tmp"; - "dest" string => "/tmp"; + "source" string => "/tmp"; + "dest" string => "/tmp"; files: - - "/$(dest)/staging-file" - - comment => "Copy from source to buffer", - copy_from => cp("$(source)/source-template"), - classes => satisfied("copy_ok"); + "/$(dest)/staging-file" + comment => "Copy from source to buffer", + copy_from => cp("$(source)/source-template"), + classes => satisfied("copy_ok"); copy_ok:: - - "/$(dest)/final-file" - - comment => "Build a file template and expand keys", - edit_line => myedits("/$(dest)/staging-file"), - edit_defaults => empty; - + "/$(dest)/final-file" + comment => "Build a file template and expand keys", + edit_line => myedits("/$(dest)/staging-file"), + edit_defaults => empty; } - ######################################################### - body copy_from cp(from) - { - source => "$(from)"; - compare => "mtime"; - type_check => "true"; + source => "$(from)"; + compare => "mtime"; + type_check => "true"; } - ######################################################## - bundle edit_line myedits(f) - { insert_lines: - - "$(f)" - - comment => "Populate empty file", + "$(f)" + comment => "Populate empty file", insert_type => "file"; replace_patterns: - - "TEMPLATE_HOST_KEY" - + "TEMPLATE_HOST_KEY" comment => "Replace a place-marker with the name of this host", replace_with => rp("$(sys.host)"); - } - ######################################################## - body replace_with rp(x) - { - replace_value => "$(x)"; - occurrences => "all"; + replace_value => "$(x)"; + occurrences => "all"; } - ######################################################### - body classes satisfied(x) { - promise_repaired => { "$(x)" }; - persist_time => "0"; + promise_repaired => { "$(x)" }; + persist_time => "0"; } - ####################################################### - body edit_defaults empty - { - empty_file_before_editing => "true"; + empty_file_before_editing => "true"; } diff --git a/examples/copydir_copbl.cf b/examples/copydir_copbl.cf index 0709cbe054..2561fbd750 100644 --- a/examples/copydir_copbl.cf +++ b/examples/copydir_copbl.cf @@ -1,45 +1,36 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - body common control { - bundlesequence => { "my_recursive_copy" }; - inputs => { "$(sys.libdir)/stdlib.cf" }; + bundlesequence => { "my_recursive_copy" }; + inputs => { "$(sys.libdir)/stdlib.cf" }; } bundle agent my_recursive_copy { files: - - "/home/mark/tmp/test_dir" - + "/home/mark/tmp/test_dir" copy_from => local_cp("$(sys.workdir)/bin/."), depth_search => recurse("inf"); - "/home/mark/tmp/test_dir" - - copy_from => secure_cp("$(sys.workdir)/bin","serverhost"), + "/home/mark/tmp/test_dir" + copy_from => secure_cp("$(sys.workdir)/bin", "serverhost"), depth_search => recurse("inf"); - } - - diff --git a/examples/copylinks.cf b/examples/copylinks.cf index b3f3a53d79..1d7979e9c5 100644 --- a/examples/copylinks.cf +++ b/examples/copylinks.cf @@ -1,81 +1,59 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - ######################################################## # # Simple test copy with link/copy exceptions # ######################################################## - ######################################################## - body common control - { - bundlesequence => { "example" }; - - version => "1.2.3"; + bundlesequence => { "example" }; + version => "1.2.3"; } - ######################################################## - bundle agent example - { files: - - "/home/mark/tmp/test_to" - - copy_from => mycopy("/home/mark/tmp/test_from"), - perms => system, + "/home/mark/tmp/test_to" + copy_from => mycopy("/home/mark/tmp/test_from"), + perms => system, move_obstructions => "true", depth_search => recurse("inf"); - } - ######################################################### - body perms system - { - mode => "0644"; + mode => "0644"; } - ######################################################### - body depth_search recurse(d) - { - depth => "$(d)"; + depth => "$(d)"; } - ######################################################### - body copy_from mycopy(from) - { - source => "$(from)"; - #copylink_patterns => { ".*" }; # copy all links - linkcopy_patterns => { ".*" }; # copy all links - #copy_backup => "timestamp"; + source => "$(from)"; + #copylink_patterns => { ".*" }; # copy all links + linkcopy_patterns => { ".*" }; + # copy all links + #copy_backup => "timestamp"; } - diff --git a/examples/countclassesmatching.cf b/examples/countclassesmatching.cf index 37a7b6886c..f94f201861 100644 --- a/examples/countclassesmatching.cf +++ b/examples/countclassesmatching.cf @@ -1,39 +1,37 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - #+begin_src cfengine3 body common control { - bundlesequence => { "example" }; + bundlesequence => { "example" }; } bundle agent example { vars: - # this is anchored, so you need .* to match multiple things - "num" int => countclassesmatching("cfengine"); - "hardcount" int => countclassesmatching(".*", "hardclass"); + # this is anchored, so you need .* to match multiple things + "num" int => countclassesmatching("cfengine"); + "hardcount" int => countclassesmatching(".*", "hardclass"); + reports: - "Found $(num) classes matching"; + "Found $(num) classes matching"; } #+end_src ############################################################################### diff --git a/examples/countlinesmatching.cf b/examples/countlinesmatching.cf index c00e1ca74b..76849b17aa 100644 --- a/examples/countlinesmatching.cf +++ b/examples/countlinesmatching.cf @@ -1,39 +1,36 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - #+begin_src cfengine3 body common control { - bundlesequence => { "example" }; + bundlesequence => { "example" }; } bundle agent example { vars: - # typically there is only one root user - "no" int => countlinesmatching("root:.*","/etc/passwd"); + # typically there is only one root user + "no" int => countlinesmatching("root:.*", "/etc/passwd"); reports: - "Found $(no) lines matching"; + "Found $(no) lines matching"; } #+end_src ############################################################################### diff --git a/examples/create_filedir.cf b/examples/create_filedir.cf index c06b03bce2..e1cecb2480 100644 --- a/examples/create_filedir.cf +++ b/examples/create_filedir.cf @@ -1,70 +1,53 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise -# versions of CFEngine, the applicable Commercial Open Source License +# versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - ######################################################## # # Simple test create files # ######################################################## - body common control - { - bundlesequence => { "example" }; + bundlesequence => { "example" }; } - ######################################################## - bundle agent example - { files: - - "/home/mark/tmp/test_plain" -#@ The promiser specifies the path and name of the file. + "/home/mark/tmp/test_plain" + #@ The promiser specifies the path and name of the file. perms => system, create => "true"; -#@ The `perms` attribute sets the file permissions as defined in the `system` -#@ body below. The `create` attribute makes sure that the files exists. If it -#@ doesn't, CFEngine will create it. - - "/home/mark/tmp/test_dir/." - + #@ The `perms` attribute sets the file permissions as defined in the `system` + #@ body below. The `create` attribute makes sure that the files exists. If it + #@ doesn't, CFEngine will create it. + "/home/mark/tmp/test_dir/." perms => system, create => "true"; -#@ The trailing `/.` in the filename tells CFEngine that the promiser is a -#@ directory. + #@ The trailing `/.` in the filename tells CFEngine that the promiser is a + #@ directory. } - ######################################################### - body perms system - { - mode => "0640"; + mode => "0640"; } #@ This body sets permissions to "0640" - - ######################################################### - diff --git a/examples/createdb.cf b/examples/createdb.cf index ab81d8b844..fc9ea2cced 100644 --- a/examples/createdb.cf +++ b/examples/createdb.cf @@ -1,67 +1,55 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - - body common control { - bundlesequence => { "databases" }; + bundlesequence => { "databases" }; } bundle agent databases - { databases: - - "knowledge_bank/topics" - + "knowledge_bank/topics" database_operation => "create", database_type => "sql", - database_columns => { - "demo_name,varchar,256", - "demo_comment,varchar,1024", - "demo_id,varchar,256", - "demo_type,varchar,256", - "demo_extra,varchar,26" + database_columns => { + "demo_name,varchar,256", + "demo_comment,varchar,1024", + "demo_id,varchar,256", + "demo_type,varchar,256", + "demo_extra,varchar,26", }, - database_server => myserver; } - ################################################ - - body database_server myserver { - none:: - db_server_owner => "postgres"; - db_server_password => ""; - db_server_host => "localhost"; - db_server_type => "postgres"; - db_server_connection_db => "postgres"; - any:: - db_server_owner => "root"; - db_server_password => ""; - db_server_host => "localhost"; - db_server_type => "mysql"; - db_server_connection_db => "mysql"; + none:: + db_server_owner => "postgres"; + db_server_password => ""; + db_server_host => "localhost"; + db_server_type => "postgres"; + db_server_connection_db => "postgres"; + any:: + db_server_owner => "root"; + db_server_password => ""; + db_server_host => "localhost"; + db_server_type => "mysql"; + db_server_connection_db => "mysql"; } - diff --git a/examples/customize_by_named_list.cf b/examples/customize_by_named_list.cf index a7cf9dcacf..98a75151cb 100644 --- a/examples/customize_by_named_list.cf +++ b/examples/customize_by_named_list.cf @@ -1,25 +1,22 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - ######################################################## # # Simple test - copy from a single directory of spec files @@ -27,71 +24,47 @@ # edits. # ######################################################## - body common control - { - bundlesequence => { "virtualhosts" }; - version => "1.2.3"; + bundlesequence => { "virtualhosts" }; + version => "1.2.3"; } - ######################################################## - bundle agent virtualhosts - { vars: - - - "vmbase" string => "/home/mark/tmp/vm"; - "source_files" string => "/home/mark/tmp/src"; - - # list of hosts to create - - "hostlist" slist => { - "host1", - "host2", - "host3", - "host4", - "host5", - "host6", - "host7", - "host8", - "host9" + "vmbase" string => "/home/mark/tmp/vm"; + "source_files" string => "/home/mark/tmp/src"; + + # list of hosts to create + "hostlist" + slist => { + "host1", + "host2", + "host3", + "host4", + "host5", + "host6", + "host7", + "host8", + "host9", }; - - - - - - ################### or just a new file to the dir ################ - # - # "hostlist" slist => { SelectFilesIn("$(source_files)",".*") } - # - ################################################################## - + ################### or just a new file to the dir ################ + # + # "hostlist" slist => { SelectFilesIn("$(source_files)",".*") } + # + ################################################################## files: - - "$(vmbase)/$(hostlist)/config_for_$(hostlist).vm" - + "$(vmbase)/$(hostlist)/config_for_$(hostlist).vm" copy_from => buildvm("$(source_files)/template_$(hostlist)"); - - - - # - # Now edit config .e.g. edit in $(ipadr[$(hostlist)]) for each - # - + # Now edit config .e.g. edit in $(ipadr[$(hostlist)]) for each } - ######################################################### # library template ######################################################### - body copy_from buildvm(from) - { - source => "$(from)"; - copy_backup => "true"; #/false/timestamp + source => "$(from)"; + copy_backup => "true"; + #/false/timestamp } - diff --git a/examples/data_expand.cf b/examples/data_expand.cf index d0542e39cf..9e19ce89ac 100644 --- a/examples/data_expand.cf +++ b/examples/data_expand.cf @@ -1,25 +1,22 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - #+begin_src prep #@ ``` #@ echo '{ "$(main.x)": "$(main.y)" }' > /tmp/expand.json @@ -30,16 +27,14 @@ bundle agent main { vars: - "x" string => "the expanded x"; - "y" string => "the expanded y"; - - "read" data => readjson("/tmp/expand.json", inf); - "expanded" data => data_expand(read); - - "expanded_str" string => format("%S", expanded); + "x" string => "the expanded x"; + "y" string => "the expanded y"; + "read" data => readjson("/tmp/expand.json", inf); + "expanded" data => data_expand(read); + "expanded_str" string => format("%S", expanded); reports: - "$(this.bundle): the x and y references expanded to $(expanded_str)"; + "$(this.bundle): the x and y references expanded to $(expanded_str)"; } #+end_src ############################################################################### diff --git a/examples/data_readstringarray.cf b/examples/data_readstringarray.cf index 286c9d7e5e..94407f1738 100644 --- a/examples/data_readstringarray.cf +++ b/examples/data_readstringarray.cf @@ -1,25 +1,22 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - #+begin_src prep #@ ``` #@ echo a,b,c > /tmp/cfe_array @@ -34,27 +31,32 @@ #+begin_src cfengine3 body common control { - bundlesequence => { "example" }; + bundlesequence => { "example" }; } bundle agent example { vars: - # The comment regex warrents an explination: - # # matches the character # literally - # [^\n]* match a single character not including the newline character - # between zero and unlimited times, as many times as possible - "bykey" data => data_readstringarray("/tmp/cfe_array","#[^\n]*",",",10,400); - "byint" data => data_readstringarrayidx("/tmp/cfe_array","#[^\n]*",",",10,400); + # The comment regex warrents an explination: + # # matches the character # literally + # [^\n]* match a single character not including the newline character + # between zero and unlimited times, as many times as possible + "bykey" + data => data_readstringarray("/tmp/cfe_array", "#[^\n]*", ",", 10, 400); - "bykey_str" string => format("%S", bykey); - "byint_str" string => format("%S", byint); - reports: - "By key: $(bykey_str)"; - "specific element by key a, offset 0: '$(bykey[a][0])'"; - "By int offset: $(byint_str)"; - "specific element by int offset 2, 0: '$(byint[2][0])'"; + "byint" + data => data_readstringarrayidx( + "/tmp/cfe_array", "#[^\n]*", ",", 10, 400 + ); + "bykey_str" string => format("%S", bykey); + "byint_str" string => format("%S", byint); + + reports: + "By key: $(bykey_str)"; + "specific element by key a, offset 0: '$(bykey[a][0])'"; + "By int offset: $(byint_str)"; + "specific element by int offset 2, 0: '$(byint[2][0])'"; } #+end_src ############################################################################### diff --git a/examples/data_regextract.cf b/examples/data_regextract.cf index 31b0e293ff..605a3cd038 100644 --- a/examples/data_regextract.cf +++ b/examples/data_regextract.cf @@ -1,25 +1,22 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - ##+begin_src prep #@ ``` #@ printf "[general]\n" > /tmp/instance.cfg @@ -32,40 +29,45 @@ bundle agent main { vars: - # the returned data container is a key-value map: - - # the whole matched string is put in key "0" - # the first three characters are put in key "name1" - # the next three characters go into key "2" (the capture has no name) - # the next two characters go into key "3" (the capture has no name) - # then the dash is ignored - # then three characters are put in key "name2" - # then another dash is ignored - # the next three characters go into key "5" (the capture has no name) - # anything else is ignored - - "parsed" data => data_regextract("^(?...)(...)(..)-(?...)-(..).*", "abcdef12-345-67andsoon"); - "parsed_str" string => format("%S", parsed); + # the returned data container is a key-value map: + # the whole matched string is put in key "0" + # the first three characters are put in key "name1" + # the next three characters go into key "2" (the capture has no name) + # the next two characters go into key "3" (the capture has no name) + # then the dash is ignored + # then three characters are put in key "name2" + # then another dash is ignored + # the next three characters go into key "5" (the capture has no name) + # anything else is ignored + "parsed" + data => data_regextract( + "^(?...)(...)(..)-(?...)-(..).*", + "abcdef12-345-67andsoon" + ); - # Illustrating multiline regular expression + "parsed_str" string => format("%S", parsed); - "instance_guid_until_end_of_string" - data => data_regextract( "^guid\s?+=\s?+(?.*)$", - readfile( "/tmp/instance.cfg", 200)); + # Illustrating multiline regular expression + "instance_guid_until_end_of_string" + data => data_regextract( + "^guid\s?+=\s?+(?.*)$", readfile("/tmp/instance.cfg", 200) + ); - "instance_guid" - data => data_regextract( "^guid\s+=\s+(?[^\n]*)", - readfile( "/tmp/instance.cfg", 200)); + "instance_guid" + data => data_regextract( + "^guid\s+=\s+(?[^\n]*)", readfile("/tmp/instance.cfg", 200) + ); - "instance_port" - data => data_regextract( "^port\s?+=\s?+(?[^\n]*)", - readfile( "/tmp/instance.cfg", 200)); + "instance_port" + data => data_regextract( + "^port\s?+=\s?+(?[^\n]*)", readfile("/tmp/instance.cfg", 200) + ); reports: - "$(this.bundle): parsed[0] '$(parsed[0])' parses into: $(parsed_str)"; - "$(this.bundle): instance_guid_until_end_of_string[value] '$(instance_guid_until_end_of_string[value])'"; - "$(this.bundle): instance_guid[value] '$(instance_guid[value])'"; - "$(this.bundle): instance_port[value] '$(instance_port[value])'"; + "$(this.bundle): parsed[0] '$(parsed[0])' parses into: $(parsed_str)"; + "$(this.bundle): instance_guid_until_end_of_string[value] '$(instance_guid_until_end_of_string[value])'"; + "$(this.bundle): instance_guid[value] '$(instance_guid[value])'"; + "$(this.bundle): instance_port[value] '$(instance_port[value])'"; } #+end_src ############################################################################### diff --git a/examples/data_sysctlvalues.cf b/examples/data_sysctlvalues.cf index d2c56a8e71..8c61315c9a 100644 --- a/examples/data_sysctlvalues.cf +++ b/examples/data_sysctlvalues.cf @@ -3,30 +3,28 @@ bundle agent inventory_sysctl # @brief Inventory each sysctl variable { vars: - # Get the complete set of sysctl variables and values as a data structure - "_sysctl_d" - data => data_sysctlvalues(), - unless => isvariable( _sysctl_d ); + # Get the complete set of sysctl variables and values as a data structure + "_sysctl_d" + data => data_sysctlvalues(), + unless => isvariable(_sysctl_d); - # Get the sysctl variable names - "_sysctl_i" - slist => getindices( "_sysctl_d" ); + # Get the sysctl variable names + "_sysctl_i" slist => getindices("_sysctl_d"); - # Define a variable tagged for inventory for each sysctl variable - "sysctl[$(_sysctl_i)]" - string => "$(_sysctl_d[$(_sysctl_i)])", - meta => { "inventory", "attribute_name=Kernel Tunable $(_sysctl_i)" }; + # Define a variable tagged for inventory for each sysctl variable + "sysctl[$(_sysctl_i)]" + string => "$(_sysctl_d[$(_sysctl_i)])", + meta => { "inventory", "attribute_name=Kernel Tunable $(_sysctl_i)" }; reports: - # Show what data_sysctlvalues() returned. - "data_sysctlvalues() returned:$(with)" - with => storejson( @(_sysctl_d) ); - + # Show what data_sysctlvalues() returned. + "data_sysctlvalues() returned:$(with)" with => storejson(@(_sysctl_d)); } + bundle agent __main__ { - methods: "inventory_sysctl"; - + methods: + "inventory_sysctl"; } #+end_src ############################################################################### diff --git a/examples/datastate.cf b/examples/datastate.cf index 8caa8d542c..3d28d9e50c 100644 --- a/examples/datastate.cf +++ b/examples/datastate.cf @@ -1,57 +1,56 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - #+begin_src cfengine3 body common control { - bundlesequence => { holder, test }; + bundlesequence => { holder, test }; } bundle common holder { classes: - "holderclass" expression => "any"; # will be global - + "holderclass" expression => "any"; + # will be global vars: - "s" string => "Hello!"; - "d" data => parsejson('[4,5,6]'); - "list" slist => { "element1", "element2" }; + "s" string => "Hello!"; + "d" data => parsejson('[4,5,6]'); + "list" slist => { "element1", "element2" }; } bundle agent test { vars: - "state" data => datastate(); + "state" data => datastate(); - # all the variables in bundle "holder" defined as of the execution of datastate() will be here - "holderstate" string => format("%S", "state[vars][holder]"); - # all the classes defined as of the execution of datastate() will be here - "allclasses" slist => getindices("state[classes]"); + # all the variables in bundle "holder" defined as of the execution of datastate() will be here + "holderstate" string => format("%S", "state[vars][holder]"); + + # all the classes defined as of the execution of datastate() will be here + "allclasses" slist => getindices("state[classes]"); classes: - "have_holderclass" expression => some("holderclass", allclasses); + "have_holderclass" expression => some("holderclass", allclasses); reports: - "holder vars = $(holderstate)"; + "holder vars = $(holderstate)"; + have_holderclass:: "I have the holder class"; } diff --git a/examples/def.json b/examples/def.json index 5b8b32e45e..6b85c7c532 100644 --- a/examples/def.json +++ b/examples/def.json @@ -1,9 +1,7 @@ { "vars": { "example_augment_string_override": "defined in def.json", - "example_augment_list_override": [ "defined", "in", "def.json"], - "example_augment_structured_override": { - "key1": "defined in def.json" - } + "example_augment_list_override": ["defined", "in", "def.json"], + "example_augment_structured_override": { "key1": "defined in def.json" } } } diff --git a/examples/defaults.cf b/examples/defaults.cf index 97c2ba5491..85423bb3ff 100644 --- a/examples/defaults.cf +++ b/examples/defaults.cf @@ -1,81 +1,64 @@ - # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - # # Default values for variables and parameters, introduced 3.4.0 # - ########################################################### - bundle agent main - -{ +{ defaults: - - # We can have default values even if variables are not defined at all. - # This is equivalent to a variable definition, so not particularly useful. - - "X" string => "I am a default value"; - "Y" slist => { "I am a default list item 1", "I am a default list item 2" }; + # We can have default values even if variables are not defined at all. + # This is equivalent to a variable definition, so not particularly useful. + "X" string => "I am a default value"; + "Y" slist => { "I am a default list item 1", "I am a default list item 2" }; methods: - - # More useful, defaults if parameters are passed to a param bundle - - "example" usebundle => mymethod("","bbb"); + # More useful, defaults if parameters are passed to a param bundle + "example" usebundle => mymethod("", "bbb"); reports: - - "The default value of X is $(X)"; - "The default value of Y is $(Y)"; + "The default value of X is $(X)"; + "The default value of Y is $(Y)"; } - ########################################################### - -bundle agent mymethod(a,b) - +bundle agent mymethod(a, b) { vars: - - "no_return" string => "ok"; # readfile("/dont/exist","123"); - + "no_return" string => "ok"; + # readfile("/dont/exist","123"); defaults: + "a" + string => "AAAAAAAAA", + if_match_regex => ""; - "a" string => "AAAAAAAAA", if_match_regex => ""; - - "b" string => "BBBBBBBBB", if_match_regex => ""; + "b" + string => "BBBBBBBBB", + if_match_regex => ""; - "no_return" string => "no such file"; + "no_return" string => "no such file"; reports: - - "The value of a is $(a)"; - "The value of b is $(b)"; - - "The value of no_return is $(no_return)"; - + "The value of a is $(a)"; + "The value of b is $(b)"; + "The value of no_return is $(no_return)"; } - ############################################################################### #+begin_src example_output #@ ``` @@ -87,4 +70,3 @@ bundle agent mymethod(a,b) #@ R: The default value of Y is I am a default list item 2 #@ ``` #+end_src - diff --git a/examples/defaults2.cf b/examples/defaults2.cf index 72f2c4fba6..c050e4f546 100644 --- a/examples/defaults2.cf +++ b/examples/defaults2.cf @@ -1,68 +1,46 @@ - # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - # # Default values for variables and parameters, introduced 3.4.0 -# - body common control - { - bundlesequence => { "example" }; + bundlesequence => { "example" }; } - ########################################################### - bundle agent example - -{ +{ vars: - - "Y" slist => { "I am list item 1", "I am list item 2" }; + "Y" slist => { "I am list item 1", "I am list item 2" }; methods: - - # More useful, defaults if parameters are passed to a param bundle - - "example" usebundle => mymethod(@(example.Y)); - + # More useful, defaults if parameters are passed to a param bundle + "example" usebundle => mymethod(@(example.Y)); } - ########################################################### - bundle agent mymethod(list) - { defaults: - - "list" slist => { "1", "2", "3"}, if_match_regex => ".*list item.*"; - # "list" string => "1" , if_match_regex => ".*list item.*"; - - + "list" + slist => { "1", "2", "3" }, + if_match_regex => ".*list item.*"; + # "list" string => "1" , if_match_regex => ".*list item.*"; reports: - - "The value of list is $(list)"; - + "The value of list is $(list)"; } - - diff --git a/examples/defaults3.cf b/examples/defaults3.cf index dee49f5489..81afc4d7ee 100644 --- a/examples/defaults3.cf +++ b/examples/defaults3.cf @@ -1,28 +1,33 @@ - - body common control { - bundlesequence => { "main" }; + bundlesequence => { "main" }; } bundle agent main { methods: - - "example" usebundle => test("one","x","","$(four)"); - + "example" usebundle => test("one", "x", "", "$(four)"); } - -bundle agent test(a,b,c,d) +bundle agent test(a, b, c, d) { defaults: + "a" + string => "default a", + if_match_regex => ""; + + "b" + string => "default b", + if_match_regex => "x"; + + "c" + string => "default c", + if_match_regex => ""; - "a" string => "default a", if_match_regex => ""; - "b" string => "default b", if_match_regex => "x"; - "c" string => "default c", if_match_regex => ""; - "d" string => "default d", if_match_regex => "\$\([a-zA-Z0-9_.]+\)"; + "d" + string => "default d", + if_match_regex => "\$\([a-zA-Z0-9_.]+\)"; reports: - "a = '$(a)', b = '$(b)', c = '$(c)' d = '$(d)'"; + "a = '$(a)', b = '$(b)', c = '$(c)' d = '$(d)'"; } diff --git a/examples/definitions.cf b/examples/definitions.cf index ca5e892b32..6ee20386d1 100644 --- a/examples/definitions.cf +++ b/examples/definitions.cf @@ -1,105 +1,74 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - # # Testing some variable/class definitions - note scope # # Use browser -f promise_output_agent.html to view -# - body common control - { - bundlesequence => { "mycommon", "assign" }; + bundlesequence => { "mycommon", "assign" }; } - ########################################################### - bundle common mycommon - { classes: - - "global_class" expression => "any"; - - "another_global" xor => { "any", "linux", "solaris"}; + "global_class" expression => "any"; + "another_global" xor => { "any", "linux", "solaris" }; } - ########################################################### - bundle agent assign - -{ +{ vars: - - "scalar" int => "16k"; - - # "xxx" string => readfile( "/home/mark/tmp/testfile" , "33" ); - - "ran" int => randomint(4,88); + "scalar" int => "16k"; - # "yyy" slist => { readstringlist("/home/mark/tmp/testlist","#[a-zA-Z0-9 ]*","[^a-zA-Z0-9]",15,4000) }; - # "zzz" slist => { readstringlist("/home/mark/tmp/testlist2","#[^\n]*",",",5,4000) }; - # "aaa" ilist => { readintlist("/home/mark/tmp/testilist","#[a-zA-Z0-9 ]*",",",10,4000) }; - - "dim_array" int => readstringarray("array_name","/etc/passwd","#[^\n]*",":",10,4000); + # "xxx" string => readfile( "/home/mark/tmp/testfile" , "33" ); + "ran" int => randomint(4, 88); + # "yyy" slist => { readstringlist("/home/mark/tmp/testlist","#[a-zA-Z0-9 ]*","[^a-zA-Z0-9]",15,4000) }; + # "zzz" slist => { readstringlist("/home/mark/tmp/testlist2","#[^\n]*",",",5,4000) }; + # "aaa" ilist => { readintlist("/home/mark/tmp/testilist","#[a-zA-Z0-9 ]*",",",10,4000) }; + "dim_array" + int => readstringarray( + "array_name", "/etc/passwd", "#[^\n]*", ":", 10, 4000 + ); classes: - - # Standard aliasing - - "myclass" or => { "solaris", "linux" }; - - # got_array is a class that says whether the read was successful - # array_name[] is the lval - - # Create a distribution - - "my_dist" dist => { "10", "20", "30", "40" }; - - # - # Now like "alerts" in cf2 - # - + # Standard aliasing + "myclass" or => { "solaris", "linux" }; + + # got_array is a class that says whether the read was successful + # array_name[] is the lval + # Create a distribution + "my_dist" dist => { "10", "20", "30", "40" }; + # Now like "alerts" in cf2 reports: + "Dimension of passwd array $(dim_array)"; + "Read item from list: $(yyy)"; - "Dimension of passwd array $(dim_array)"; - - "Read item from list: $(yyy)"; - - # Any kind of rule can define classes on exit - - "Read this file: [$(xxx)] ..." - classes => persist("alertclass","20"); - + # Any kind of rule can define classes on exit + "Read this file: [$(xxx)] ..." classes => persist("alertclass", "20"); } - ###################################################################### - -body classes persist(class,time) - +body classes persist(class, time) { - promise_repaired => { "$(class)" }; - persist_time => "$(time)"; - timer_policy => "absolute"; + promise_repaired => { "$(class)" }; + persist_time => "$(time)"; + timer_policy => "absolute"; } diff --git a/examples/deletelines.cf b/examples/deletelines.cf index 2d9245a42e..9354d8113d 100644 --- a/examples/deletelines.cf +++ b/examples/deletelines.cf @@ -1,90 +1,67 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - - - body common control { - bundlesequence => { "example" }; + bundlesequence => { "example" }; } - - bundle agent example { files: - - "/tmp/resolv.conf" # test on "/tmp/resolv.conf" # - - create => "true", - edit_line => resolver, + "/tmp/resolv.conf" + # test on "/tmp/resolv.conf" # + create => "true", + edit_line => resolver, edit_defaults => def; - } - - ####################################################### # For the library ####################################################### - bundle edit_line resolver - { vars: - - "search" slist => { "search iu.hio.no cfengine.com", "nameserver 128.39.89.10" }; + "search" + slist => { "search iu.hio.no cfengine.com", "nameserver 128.39.89.10" }; delete_lines: - - "search.*"; + "search.*"; insert_lines: - - "$(search)" location => end; + "$(search)" location => end; } - ####################################################### - body edit_defaults def { - empty_file_before_editing => "false"; - edit_backup => "false"; - max_file_size => "100000"; + empty_file_before_editing => "false"; + edit_backup => "false"; + max_file_size => "100000"; } - ######################################################## - body location start - { - # If not line to match, applies to whole text body - before_after => "before"; + # If not line to match, applies to whole text body + before_after => "before"; } - ######################################################## - body location end - { - # If not line to match, applies to whole text body - before_after => "after"; + # If not line to match, applies to whole text body + before_after => "after"; } diff --git a/examples/depends_on.cf b/examples/depends_on.cf index aaaec1f03a..6ed05d5639 100644 --- a/examples/depends_on.cf +++ b/examples/depends_on.cf @@ -1,18 +1,11 @@ - - body common control { - bundlesequence => { "one" }; + bundlesequence => { "one" }; } bundle agent one { reports: - - "two" - depends_on => { "handle_one" }; - - "one" - handle => "handle_one"; - + "two" depends_on => { "handle_one" }; + "one" handle => "handle_one"; } diff --git a/examples/depends_on2.cf b/examples/depends_on2.cf index d276e530b3..70ddbb8cb6 100644 --- a/examples/depends_on2.cf +++ b/examples/depends_on2.cf @@ -1,50 +1,36 @@ - - body common control { - bundlesequence => { "main" }; + bundlesequence => { "main" }; } bundle agent main { methods: - - "any" usebundle => one; - - "any" usebundle => mars:two; - + "any" usebundle => one; + "any" usebundle => mars:two; } bundle agent one { reports: - - "two" - depends_on => { "handle_one" }; - - "one" - handle => "handle_one"; - + "two" depends_on => { "handle_one" }; + "one" handle => "handle_one"; } body file control { - namespace => "mars"; + namespace => "mars"; } - bundle agent two { reports: - - "marstwo" + "marstwo" handle => "mars_two", depends_on => { "handle_one" }; - # Currently bugged -> CFE-3206 - # "marsone" - # handle => "handle_one"; - - "marsthree" - depends_on => { "default.handle_one", "mars_two" }; + # Currently bugged -> CFE-3206 + # "marsone" + # handle => "handle_one"; + "marsthree" depends_on => { "default.handle_one", "mars_two" }; } diff --git a/examples/difference.cf b/examples/difference.cf index 792ab3a9ea..77db0e92d4 100644 --- a/examples/difference.cf +++ b/examples/difference.cf @@ -1,57 +1,56 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - #+begin_src cfengine3 body common control { - bundlesequence => { "test" }; + bundlesequence => { "test" }; } bundle agent test { vars: - "a" slist => { 1,2,3,"x" }; - "b" slist => { "x" }; + "a" slist => { 1, 2, 3, "x" }; + "b" slist => { "x" }; + + # normal usage + "diff_between_a_and_b" slist => difference(a, b); + "diff_between_a_and_b_str" string => join(",", diff_between_a_and_b); - # normal usage - "diff_between_a_and_b" slist => difference(a, b); - "diff_between_a_and_b_str" string => join(",", diff_between_a_and_b); + # NOTE: advanced usage! + "mylist1" slist => { "a", "b" }; + "mylist2" slist => { "a", "b" }; + "$(mylist1)_str" string => join(",", $(mylist1)); - # NOTE: advanced usage! - "mylist1" slist => { "a", "b" }; - "mylist2" slist => { "a", "b" }; - "$(mylist1)_str" string => join(",", $(mylist1)); + # Here we're going to really call difference(a,a) then difference(a,b) then difference(b,a) then difference(b,b) + # We create a new variable for each difference!!! + "diff_$(mylist1)_$(mylist2)" slist => difference($(mylist1), $(mylist2)); - # Here we're going to really call difference(a,a) then difference(a,b) then difference(b,a) then difference(b,b) - # We create a new variable for each difference!!! - "diff_$(mylist1)_$(mylist2)" slist => difference($(mylist1), $(mylist2)); - "diff_$(mylist1)_$(mylist2)_str" string => join(",", "diff_$(mylist1)_$(mylist2)"); + "diff_$(mylist1)_$(mylist2)_str" + string => join(",", "diff_$(mylist1)_$(mylist2)"); reports: - # normal usage - "The difference between lists a and b is '$(diff_between_a_and_b_str)'"; + # normal usage + "The difference between lists a and b is '$(diff_between_a_and_b_str)'"; - # NOTE: advanced usage results! - "The difference of list '$($(mylist1)_str)' with '$($(mylist2)_str)' is '$(diff_$(mylist1)_$(mylist2)_str)'"; + # NOTE: advanced usage results! + "The difference of list '$($(mylist1)_str)' with '$($(mylist2)_str)' is '$(diff_$(mylist1)_$(mylist2)_str)'"; } #+end_src ############################################################################### diff --git a/examples/dirname.cf b/examples/dirname.cf index 2c7f3a29e1..8f0f249b7f 100644 --- a/examples/dirname.cf +++ b/examples/dirname.cf @@ -1,37 +1,35 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - #+begin_src cfengine3 body common control { - bundlesequence => { "example" }; + bundlesequence => { "example" }; } bundle agent example { vars: - "apache_dir" string => dirname("/etc/apache2/httpd.conf"); + "apache_dir" string => dirname("/etc/apache2/httpd.conf"); + reports: - "apache conf dir = $(apache_dir)"; + "apache conf dir = $(apache_dir)"; } #+end_src ############################################################################### diff --git a/examples/disable.cf b/examples/disable.cf index ed54193ad5..6197fd845b 100644 --- a/examples/disable.cf +++ b/examples/disable.cf @@ -1,42 +1,31 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - body common control { - bundlesequence => { "my_disable" }; - inputs => { "$(sys.libdir)/stdlib.cf" }; + bundlesequence => { "my_disable" }; + inputs => { "$(sys.libdir)/stdlib.cf" }; } bundle agent my_disable { - files: - - "/home/mark/tmp/test_create" - rename => disable; - - "/home/mark/tmp/rotate_my_log" - rename => rotate("4"); - + "/home/mark/tmp/test_create" rename => disable; + "/home/mark/tmp/rotate_my_log" rename => rotate("4"); } - - diff --git a/examples/disable_and_rotate_files.cf b/examples/disable_and_rotate_files.cf index 1220fe4745..10548665ea 100644 --- a/examples/disable_and_rotate_files.cf +++ b/examples/disable_and_rotate_files.cf @@ -1,68 +1,49 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - ####################################################### # # Disabling / rotating files # ####################################################### - body common control - { - bundlesequence => { "example" }; + bundlesequence => { "example" }; } - - ############################################ - bundle agent example - { files: - - "/home/mark/tmp/test_create" - + "/home/mark/tmp/test_create" comment => "this rule does something", rename => disable; - "/home/mark/tmp/rotateme" - - rename => rotate("4"); + "/home/mark/tmp/rotateme" rename => rotate("4"); } - ############################################ - body rename disable - { - disable => "true"; - disable_suffix => "_blownaway"; + disable => "true"; + disable_suffix => "_blownaway"; } - ############################################ - body rename rotate(level) - { - rotate => "$(level)"; + rotate => "$(level)"; } diff --git a/examples/diskfree.cf b/examples/diskfree.cf index 7660d3b878..c32595238d 100644 --- a/examples/diskfree.cf +++ b/examples/diskfree.cf @@ -1,42 +1,40 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - #+begin_src cfengine3 body common control { - bundlesequence => { "example" }; + bundlesequence => { "example" }; } bundle agent example { classes: - "has_space" expression => isgreaterthan($(free), 0); + "has_space" expression => isgreaterthan($(free), 0); vars: - "free" int => diskfree("/tmp"); + "free" int => diskfree("/tmp"); reports: has_space:: "The filesystem has free space"; + !has_space:: "The filesystem has NO free space"; } diff --git a/examples/dollar.cf b/examples/dollar.cf index 328edeabe9..6e620e925a 100644 --- a/examples/dollar.cf +++ b/examples/dollar.cf @@ -1,49 +1,34 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - - - body common control - { - bundlesequence => { "example" }; + bundlesequence => { "example" }; } - ########################################################### - bundle agent example - -{ +{ classes: - - "some" expression => "any"; + "some" expression => "any"; reports: - some:: - "The value of $(const.dollar)(const.dollar) is $(const.dollar)"; - "But the value of \$(dollar) is \$(dollar)"; - } - diff --git a/examples/edit.empty_before_use.cf b/examples/edit.empty_before_use.cf index fa74032b2f..63ecb3c31f 100644 --- a/examples/edit.empty_before_use.cf +++ b/examples/edit.empty_before_use.cf @@ -2,47 +2,51 @@ bundle agent __main__ { files: + "/tmp/example-edit.empty_before_use.one" create => "true"; + "/tmp/example-edit.empty_before_use.two" create => "true"; - "/tmp/example-edit.empty_before_use.one" create => "true"; - "/tmp/example-edit.empty_before_use.two" create => "true"; - - "/tmp/example-edit.empty_before_use.one" - edit_line => show_edit_empty_before_use, - edit_defaults => my_empty_file_before_editing; - - "/tmp/example-edit.empty_before_use.two" - edit_line => show_edit_empty_before_use; + "/tmp/example-edit.empty_before_use.one" + edit_line => show_edit_empty_before_use, + edit_defaults => my_empty_file_before_editing; + "/tmp/example-edit.empty_before_use.two" + edit_line => show_edit_empty_before_use; } bundle edit_line show_edit_empty_before_use { reports: - "$(with)" - with => concat( "The promise to edit '$(edit.filename)' was ", - "instructed to ignore any pre-existing content." ), - if => strcmp( "true", "$(edit.empty_before_use)"); - - "$(with)" - with => concat( "The promise to edit '$(edit.filename)' was ", - "not instructed to ignore any pre-existing content."), - if => strcmp( "false", "$(edit.empty_before_use)"); - - "$(with)" - with => concat ( "This version of CFEngine does not know if the", - "edit operation is expected to ignore pre-existing ", - "content the variable 'edit.empty_before_use' does ", - "not exist"), - unless => isvariable ( "edit.empty_before_use" ); - + "$(with)" + with => concat( + "The promise to edit '$(edit.filename)' was ", + "instructed to ignore any pre-existing content." + ), + if => strcmp("true", "$(edit.empty_before_use)"); + + "$(with)" + with => concat( + "The promise to edit '$(edit.filename)' was ", + "not instructed to ignore any pre-existing content." + ), + if => strcmp("false", "$(edit.empty_before_use)"); + + "$(with)" + with => concat( + "This version of CFEngine does not know if the", + "edit operation is expected to ignore pre-existing ", + "content the variable 'edit.empty_before_use' does ", + "not exist" + ), + unless => isvariable("edit.empty_before_use"); } body edit_defaults my_empty_file_before_editing { - empty_file_before_editing => "true"; # The variable - # edit.empty_before_use allows this - # to be known from within an - # edit_line bundle. + empty_file_before_editing => "true"; + # The variable + # edit.empty_before_use allows this + # to be known from within an + # edit_line bundle. } #+end_src ############################################################################### diff --git a/examples/edit.filename.cf b/examples/edit.filename.cf index d98eec5e18..0d0db6bac5 100644 --- a/examples/edit.filename.cf +++ b/examples/edit.filename.cf @@ -2,48 +2,51 @@ bundle agent __main__ { files: - - "/tmp/example-edit.filename.txt" content => "Hello World!"; - - "/tmp/example-edit.filename.txt" - edit_line => show_edit_filename; - + "/tmp/example-edit.filename.txt" content => "Hello World!"; + "/tmp/example-edit.filename.txt" edit_line => show_edit_filename; } bundle edit_line show_edit_filename { reports: - "$(with)" - with => concat( "I found the string 'World' in the file being ", - "edited ('$(edit.filename)')"), - if => strcmp( "false", "$(edit.empty_before_use)"); # It's probably - # useless to probe - # the content of the - # file if you are - # ignoring - # pre-existing - # content. - - "$(with)" - with => concat( "It's probably not very useful to inspect content", - "that is being thrown away." ), - if => strcmp( "true", "$(edit.empty_before_use)"); - - "$(with)" - with => concat ( "This version of CFEngine does not know if the", - "edit operation is expected to ignore pre-existing ", - "content the variable 'edit.empty_before_use' does ", - "not exist"), - unless => isvariable ( "edit.empty_before_use" ); - + "$(with)" + with => concat( + "I found the string 'World' in the file being ", + "edited ('$(edit.filename)')" + ), + if => strcmp("false", "$(edit.empty_before_use)"); + + # It's probably + # useless to probe + # the content of the + # file if you are + # ignoring + # pre-existing + # content. + "$(with)" + with => concat( + "It's probably not very useful to inspect content", + "that is being thrown away." + ), + if => strcmp("true", "$(edit.empty_before_use)"); + + "$(with)" + with => concat( + "This version of CFEngine does not know if the", + "edit operation is expected to ignore pre-existing ", + "content the variable 'edit.empty_before_use' does ", + "not exist" + ), + unless => isvariable("edit.empty_before_use"); } body edit_defaults my_empty_file_before_editing { - empty_file_before_editing => "true"; # The variable - # edit.empty_before_use allows this - # to be known from within an - # edit_line bundle. + empty_file_before_editing => "true"; + # The variable + # edit.empty_before_use allows this + # to be known from within an + # edit_line bundle. } #+end_src ############################################################################### diff --git a/examples/edit_column_files.cf b/examples/edit_column_files.cf index 7fc167bd8c..fb4fd0f402 100644 --- a/examples/edit_column_files.cf +++ b/examples/edit_column_files.cf @@ -1,25 +1,22 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - ###################################################################### # # File editing @@ -30,84 +27,52 @@ # - insert # ###################################################################### - - body common control - { - version => "1.2.3"; - bundlesequence => { "bun" }; + version => "1.2.3"; + bundlesequence => { "bun" }; } - ######################################################## - bundle agent bun - { vars: - - "userset" slist => { "one", "two", "three" }; + "userset" slist => { "one", "two", "three" }; files: - - # Make a copy of the password file - - "/home/mark/tmp/passwd" - - create => "true", - edit_line => set_user_field("mark","6","/home/dir"); - - "/home/mark/tmp/group" - - create => "true", - edit_line => append_user_field("wheel","4","@(bun.userset)"); - + # Make a copy of the password file + "/home/mark/tmp/passwd" + create => "true", + edit_line => set_user_field("mark", "6", "/home/dir"); + + "/home/mark/tmp/group" + create => "true", + edit_line => append_user_field("wheel", "4", "@(bun.userset)"); } - ######################################################## - -bundle edit_line set_user_field(user,field,val) +bundle edit_line set_user_field(user, field, val) { field_edits: - - "$(user).*" - - # Set field of the file to parameter - - edit_field => col(":","$(field)","$(val)","set"); + "$(user).*" edit_field => col(":", "$(field)", "$(val)", "set"); } - ######################################################## - -bundle edit_line append_user_field(user,field,allusers) +bundle edit_line append_user_field(user, field, allusers) { vars: - - "val" slist => { @(allusers) }; + "val" slist => { @(allusers) }; field_edits: - - "$(user).*" - - # Set field of the file to parameter - - edit_field => col(":","$(field)","$(val)","alphanum"); - + "$(user).*" edit_field => col(":", "$(field)", "$(val)", "alphanum"); } - ######################################## # Bodies ######################################## - -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)"; - field_operation => "$(method)"; - extend_fields => "true"; - allow_blank_fields => "true"; + field_separator => "$(split)"; + select_field => "$(col)"; + value_separator => ","; + field_value => "$(newval)"; + field_operation => "$(method)"; + extend_fields => "true"; + allow_blank_fields => "true"; } - diff --git a/examples/edit_comment_lines.cf b/examples/edit_comment_lines.cf index 7d441e4a6c..cf0d37545a 100644 --- a/examples/edit_comment_lines.cf +++ b/examples/edit_comment_lines.cf @@ -1,25 +1,22 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - ###################################################################### # # File editing @@ -30,65 +27,44 @@ # - insert # ###################################################################### - - body common control - { - version => "1.2.3"; - bundlesequence => { "example" }; + version => "1.2.3"; + bundlesequence => { "example" }; } - ######################################################## - bundle agent example - { - files: - - "/home/mark/tmp/cf3_test" - - create => "true", + "/home/mark/tmp/cf3_test" + create => "true", edit_line => myedit("second"); } - ######################################################## - bundle edit_line myedit(parameter) { vars: + "edit_variable" string => "private edit variable is $(parameter)"; - "edit_variable" string => "private edit variable is $(parameter)"; - - replace_patterns: - - # replace shell comments with C comments - - "#(.*)" - + # replace shell comments with C comments + "#(.*)" replace_with => C_comment, select_region => MySection("New section"); - } - ######################################## # Bodies ######################################## - body replace_with C_comment - { - replace_value => "/* $(match.1) */"; # backreference 0 - occurrences => "all"; # first, last all + replace_value => "/* $(match.1) */"; + # backreference 0 + occurrences => "all"; + # first, last all } - ######################################################## - body select_region MySection(x) - { - select_start => "\[$(x)\]"; - select_end => "\[.*\]"; + select_start => "\[$(x)\]"; + select_end => "\[.*\]"; } diff --git a/examples/edit_deletenotmatch.cf b/examples/edit_deletenotmatch.cf index a9af940657..6bfdcb1df9 100644 --- a/examples/edit_deletenotmatch.cf +++ b/examples/edit_deletenotmatch.cf @@ -1,31 +1,27 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - ######################################################## # # Simple test editfile # ######################################################## - # # This assumes a file format like: # @@ -36,34 +32,21 @@ # [section 2] # # lines... etc - - body common control - { - bundlesequence => { "example" }; + bundlesequence => { "example" }; } - ######################################################## - bundle agent example - { files: - - "/tmp/passwd_excerpt" - - create => "true", + "/tmp/passwd_excerpt" + create => "true", edit_line => MarkNRoot; } - ######################################################## - bundle edit_line MarkNRoot { delete_lines: - - "mark.*|root.*" not_matching => "true"; - + "mark.*|root.*" not_matching => "true"; } - diff --git a/examples/edit_insert_fuzzylines.cf b/examples/edit_insert_fuzzylines.cf index 4fb55e2058..b0728a0ea2 100644 --- a/examples/edit_insert_fuzzylines.cf +++ b/examples/edit_insert_fuzzylines.cf @@ -1,78 +1,53 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - - ####################################################### # # Insert a number of lines with vague whitespace # ####################################################### - body common control - { - any:: - - bundlesequence => { "insert" }; + any:: + bundlesequence => { "insert" }; } - - ####################################################### - bundle agent insert - { vars: + "v" string => " One potato"; - "v" string => " One potato"; - files: - - "/tmp/test_insert" - + "/tmp/test_insert" create => "true", edit_line => Insert("$(insert.v)"); - } - ####################################################### # For the library ####################################################### - bundle edit_line Insert(name) - { insert_lines: - - " $(name)" - - whitespace_policy => { "ignore_leading", "ignore_embedded" }; - + " $(name)" whitespace_policy => { "ignore_leading", "ignore_embedded" }; } - ####################################################### - body edit_defaults empty - { - empty_file_before_editing => "true"; + empty_file_before_editing => "true"; } diff --git a/examples/edit_insert_lines.cf b/examples/edit_insert_lines.cf index e0bf3b9bd0..49d3d9d161 100644 --- a/examples/edit_insert_lines.cf +++ b/examples/edit_insert_lines.cf @@ -1,82 +1,60 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - - ####################################################### # # Insert a number of lines # ####################################################### - body common control - { - any:: - - bundlesequence => { "insert" }; + any:: + bundlesequence => { "insert" }; } - - ####################################################### - bundle agent insert - { vars: - - "v" string => " + "v" + string => " One potato Two potato Three potatoe Four "; - - files: - - "/tmp/test_insert" + files: + "/tmp/test_insert" create => "true", edit_line => Insert("$(insert.v)"), edit_defaults => empty; - } - ####################################################### # For the library ####################################################### - bundle edit_line Insert(name) - { insert_lines: - - "Begin$(const.n)$(name)$(const.n)End"; - + "Begin$(const.n)$(name)$(const.n)End"; } - ####################################################### - body edit_defaults empty - { - empty_file_before_editing => "false"; + empty_file_before_editing => "false"; } diff --git a/examples/edit_insert_lines_silly.cf b/examples/edit_insert_lines_silly.cf index d86ef4a795..349dbfe0ba 100644 --- a/examples/edit_insert_lines_silly.cf +++ b/examples/edit_insert_lines_silly.cf @@ -1,82 +1,54 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - - ####################################################### # # Insert a number of lines # ####################################################### - body common control - { - any:: - - bundlesequence => { "insert" }; + any:: + bundlesequence => { "insert" }; } - - ####################################################### - bundle agent insert - { vars: + "v" slist => { "One potato", "Two potato", "Three potatoe", "Four" }; - "v" slist => { - "One potato", - "Two potato", - "Three potatoe", - "Four" - }; - files: - - "/tmp/test_insert" - + "/tmp/test_insert" create => "true", edit_line => Insert("@(insert.v)"); - # edit_defaults => empty; - + # edit_defaults => empty; } - ####################################################### # For the library ####################################################### - bundle edit_line Insert(name) - { insert_lines: - - "$(name)"; - + "$(name)"; } - ####################################################### - body edit_defaults empty - { - empty_file_before_editing => "true"; + empty_file_before_editing => "true"; } diff --git a/examples/edit_passwd_file.cf b/examples/edit_passwd_file.cf index bc25760727..355bcb1efe 100644 --- a/examples/edit_passwd_file.cf +++ b/examples/edit_passwd_file.cf @@ -1,91 +1,63 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - - body common control { - bundlesequence => { "addpasswd" }; + bundlesequence => { "addpasswd" }; } bundle agent addpasswd { vars: - - # want to set these values by the names of their array keys - - "pwd[mark]" string => "mark:x:1000:100:Mark Burgess:/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"; + # want to set these values by the names of their array keys + "pwd[mark]" string => "mark:x:1000:100:Mark Burgess:/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: - - - "/tmp/passwd" - + "/tmp/passwd" create => "true", edit_line => append_users_starting("addpasswd.pwd"); - } - ############################################################ # Library stuff ############################################################ - bundle edit_line append_users_starting(v) - { vars: - - "index" slist => getindices("$(v)"); + "index" slist => getindices("$(v)"); classes: - - "add_$(index)" not => userexists("$(index)"); + "add_$(index)" not => userexists("$(index)"); insert_lines: - - "$($(v)[$(index)])" - - if => "add_$(index)"; - + "$($(v)[$(index)])" if => "add_$(index)"; } - ############################################################ - bundle edit_line append_groups_starting(v) - { vars: - - "index" slist => getindices("$(v)"); + "index" slist => getindices("$(v)"); classes: - - "add_$(index)" not => groupexists("$(index)"); + "add_$(index)" not => groupexists("$(index)"); insert_lines: - - "$($(v)[$(index)])" - - if => "add_$(index)"; - + "$($(v)[$(index)])" if => "add_$(index)"; } diff --git a/examples/edit_passwd_file_basic.cf b/examples/edit_passwd_file_basic.cf index d6c105efe3..2ed9c1cc21 100644 --- a/examples/edit_passwd_file_basic.cf +++ b/examples/edit_passwd_file_basic.cf @@ -1,49 +1,34 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - - body common control { - bundlesequence => { "edit_passwd" }; - inputs => { "$(sys.libdir)/stdlib.cf" }; + bundlesequence => { "edit_passwd" }; + inputs => { "$(sys.libdir)/stdlib.cf" }; } bundle agent edit_passwd { - vars: - - "userset" slist => { "user1", "user2", "user3" }; + "userset" slist => { "user1", "user2", "user3" }; files: - - "/etc/passwd" - edit_line => - set_user_field("mark","7","/set/this/shell"); - - - "/etc/group" - edit_line => - append_user_field("root","4","@(main.userset)"); - + "/etc/passwd" edit_line => set_user_field("mark", "7", "/set/this/shell"); + "/etc/group" edit_line => append_user_field("root", "4", "@(main.userset)"); } - diff --git a/examples/edit_replace_string.cf b/examples/edit_replace_string.cf index 17e5c93152..0474c62207 100644 --- a/examples/edit_replace_string.cf +++ b/examples/edit_replace_string.cf @@ -1,25 +1,22 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - ###################################################################### # # File editing @@ -30,65 +27,40 @@ # - insert # ###################################################################### - - body common control - { - version => "1.2.3"; - bundlesequence => { "example" }; + version => "1.2.3"; + bundlesequence => { "example" }; } - ######################################################## - bundle agent example - { - files: - - "/tmp/replacestring" - - create => "true", + "/tmp/replacestring" + create => "true", edit_line => myedit("second"); } - ######################################################## - bundle edit_line myedit(parameter) { vars: + "edit_variable" string => "private edit variable is $(parameter)"; - "edit_variable" string => "private edit variable is $(parameter)"; - - replace_patterns: - - # replace shell comments with C comments - - "puppet" - - replace_with => With("cfengine 3"); - + # replace shell comments with C comments + "puppet" replace_with => With("cfengine 3"); } - ######################################## # Bodies ######################################## - body replace_with With(x) - { - replace_value => "$(x)"; - occurrences => "first"; + replace_value => "$(x)"; + occurrences => "first"; } - ######################################## - body select_region MySection(x) - { - select_start => "\[$(x)\]"; - select_end => "\[.*\]"; + select_start => "\[$(x)\]"; + select_end => "\[.*\]"; } - diff --git a/examples/edit_sectioned_file.cf b/examples/edit_sectioned_file.cf index ec38265a0e..6b61b2cc41 100644 --- a/examples/edit_sectioned_file.cf +++ b/examples/edit_sectioned_file.cf @@ -1,31 +1,27 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - ######################################################## # # Simple test editfile # ######################################################## - # # This assumes a file format like: # @@ -36,86 +32,58 @@ # [section 2] # # lines... etc - - body common control - { - bundlesequence => { "example" }; + bundlesequence => { "example" }; } - ######################################################## - bundle agent example - { vars: - - "v1" string => "numerical backreference"; + "v1" string => "numerical backreference"; files: - - "/home/mark/tmp/cf3_test" - - create => "true", - edit_line => AppendIfNoLine("cfengine tcp 5308","second"); - - + "/home/mark/tmp/cf3_test" + create => "true", + edit_line => AppendIfNoLine("cfengine tcp 5308", "second"); } - ######################################################## - -bundle edit_line AppendIfNoLine(parameter,two) +bundle edit_line AppendIfNoLine(parameter, two) { vars: - - "list" slist => { "1", "2", "3" }; + "list" slist => { "1", "2", "3" }; insert_lines: + "$(parameter) and $(two)-$(list)" location => append; + "NEW Special-insert!!!" select_region => MySection("New section"); + "set variable = value" select_region => MySection("New section"); - "$(parameter) and $(two)-$(list)" location => append; - - "NEW Special-insert!!!" select_region => MySection("New section"); - "set variable = value" select_region => MySection("New section"); - - - "/home/mark/tmp/insert" insert_type => "file", + "/home/mark/tmp/insert" + insert_type => "file", expand_scalars => "true", select_region => MySection("New section"); delete_lines: - - # "l.*"; - # "NEW.*" select_region => MySection("New section"); - - # Delete LinesStarting in file - + # "l.*"; + # "NEW.*" select_region => MySection("New section"); + # Delete LinesStarting in file } - ######################################################## - body location append - { - # If not line to match, applies to whole text body - before_after => "after"; + # If not line to match, applies to whole text body + before_after => "after"; } - ######################################################## - body location after(x) - { - # If not line to match, applies to whole text body - #select_line_matching => "$(x)"; - before_after => "after"; + # If not line to match, applies to whole text body + #select_line_matching => "$(x)"; + before_after => "after"; } - ######################################################## - body select_region MySection(x) - { - select_start => "\[$(x)\]"; - select_end => "\[.*\]"; + select_start => "\[$(x)\]"; + select_end => "\[.*\]"; } diff --git a/examples/edit_setvar.cf b/examples/edit_setvar.cf index c7e21da9fd..808580825e 100644 --- a/examples/edit_setvar.cf +++ b/examples/edit_setvar.cf @@ -1,74 +1,52 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - ####################################################### # # Edit variable = value in a text file # ####################################################### - body common control - { - bundlesequence => { "example" }; + bundlesequence => { "example" }; } - - ####################################################### - bundle agent example - { vars: - - "v[variable_1]" string => "value_1"; - "v[variable_2]" string => "value_2"; + "v[variable_1]" string => "value_1"; + "v[variable_2]" string => "value_2"; files: - - "/tmp/test_setvar" - - edit_line => setvars_v1("testsetvar.v"); - + "/tmp/test_setvar" edit_line => setvars_v1("testsetvar.v"); } - ####################################################### # For the library ####################################################### - bundle edit_line setvars_v1(contexted_array_name) - { vars: + "parameter_name" slist => getindices("$(contexted_array_name)"); - "parameter_name" slist => getindices("$(contexted_array_name)"); - - delete_lines: - - "$(parameter_name).*"; + delete_lines: + "$(parameter_name).*"; insert_lines: - - "$(parameter_name) = $($(contexted_array_name)[$(parameter_name)])"; - + "$(parameter_name) = $($(contexted_array_name)[$(parameter_name)])"; } - diff --git a/examples/edit_template.cf b/examples/edit_template.cf index e08bca448b..4251e97f00 100644 --- a/examples/edit_template.cf +++ b/examples/edit_template.cf @@ -1,21 +1,16 @@ - body common control { - bundlesequence => { "main" }; + bundlesequence => { "main" }; } bundle agent main { vars: - - "here" string => "/home/a10004/LapTop/cfengine/core/examples"; - - "list" slist => { "one", "two", "three" }; + "here" string => "/home/a10004/LapTop/cfengine/core/examples"; + "list" slist => { "one", "two", "three" }; files: - - "/tmp/output" - + "/tmp/output" create => "true", edit_template => "$(here)/input.edittemplate"; } diff --git a/examples/edit_triggerclass.cf b/examples/edit_triggerclass.cf index d53486db39..272bc36eed 100644 --- a/examples/edit_triggerclass.cf +++ b/examples/edit_triggerclass.cf @@ -1,102 +1,73 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - - ####################################################### # # Insert a number of lines and trigger a followup if edited # ####################################################### - body common control - { - any:: - - bundlesequence => { "insert" }; + any:: + bundlesequence => { "insert" }; } - - ####################################################### - bundle agent insert - { vars: - - "v" string => " + "v" + string => " One potato Two potato Three potahto Four "; - - files: - - "/tmp/test_insert" + files: + "/tmp/test_insert" edit_line => Insert("$(insert.v)"), edit_defaults => empty, classes => trigger("edited"); commands: - edited:: - "/bin/echo make bananas"; reports: - edited:: - "The potatoes are bananas"; - } - ####################################################### # For the library ####################################################### - bundle edit_line Insert(name) - { insert_lines: - - "Begin$(const.n) $(name)$(const.n)End"; - + "Begin$(const.n) $(name)$(const.n)End"; } - ####################################################### - body edit_defaults empty - { - empty_file_before_editing => "true"; + empty_file_before_editing => "true"; } - ####################################################### - body classes trigger(x) - { - promise_repaired => { "$(x)" }; + promise_repaired => { "$(x)" }; } diff --git a/examples/edit_xml.cf b/examples/edit_xml.cf index 611a736595..473b707848 100644 --- a/examples/edit_xml.cf +++ b/examples/edit_xml.cf @@ -1,87 +1,86 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - ############################################################################### #+begin_src cfengine3 # for more info: http://cfengine.com/docs/master/reference-promise-types-edit_xml.html - body common control { - bundlesequence => { run }; - inputs => { "$(sys.libdir)/stdlib.cf" }; + bundlesequence => { run }; + inputs => { "$(sys.libdir)/stdlib.cf" }; } bundle agent run { vars: - "file" string => "$(this.promise_filename).txt"; + "file" string => "$(this.promise_filename).txt"; + methods: - "rm" usebundle => rmxml; - "make" usebundle => makexml; - "use" usebundle => maintainxml; - "report" usebundle => reportxml; + "rm" usebundle => rmxml; + "make" usebundle => makexml; + "use" usebundle => maintainxml; + "report" usebundle => reportxml; } bundle agent rmxml { files: - "$(run.file)" delete => tidy; + "$(run.file)" delete => tidy; } bundle agent makexml { files: - "$(run.file)" + "$(run.file)" comment => "Create xml file", create => "true", edit_defaults => empty, - edit_xml => xml_insert_tree_nopath('cfe_alias'); + edit_xml => xml_insert_tree_nopath( + 'cfe_alias' + ); } bundle agent reportxml { vars: - "data" string => readfile($(run.file), 4k); - reports: - "Final XML is $(data)"; -# R: Final XML is -# newhosttextnewalias + "data" string => readfile($(run.file), 4k); + reports: + "Final XML is $(data)"; + # R: Final XML is + # newhosttextnewalias } bundle agent maintainxml { files: - "$(run.file)" + "$(run.file)" comment => "Maintain xml file: set the Alias node", create => "false", - edit_xml => xml_set_value("newalias","/Host/Alias"); + edit_xml => xml_set_value("newalias", "/Host/Alias"); - "$(run.file)" + "$(run.file)" comment => "Maintain xml file: replace a Host node with a name attribute = cfe_host", create => "false", - edit_xml => xml_set_value("newhosttext","/Host[@name='cfe_host']"); + edit_xml => xml_set_value("newhosttext", "/Host[@name='cfe_host']"); - "$(run.file)" + "$(run.file)" comment => "Maintain xml file: replace a Host node's name attribute", create => "false", edit_xml => xml_set_attribute("name", "newhostname", "/Host"); diff --git a/examples/ensure_line_present_prepend_append.cf b/examples/ensure_line_present_prepend_append.cf index 75005cee03..9b64ebdacb 100644 --- a/examples/ensure_line_present_prepend_append.cf +++ b/examples/ensure_line_present_prepend_append.cf @@ -1,41 +1,38 @@ # Note that this example assumes that the masterfiles policy framework is installed # in inputs in your user's working directory (e.g. /var/cfengine/inputs for root). - #+begin_src cfengine3 body common control { - bundlesequence => { "line_prepend", "line_append" , "output" }; - inputs => { "$(sys.libdir)/stdlib.cf" }; + bundlesequence => { "line_prepend", "line_append", "output" }; + inputs => { "$(sys.libdir)/stdlib.cf" }; } - bundle agent line_prepend { files: - "/tmp/test_line_prepend" - edit_line => prepend_if_no_line("I am the first line"), - create => "true"; + "/tmp/test_line_prepend" + edit_line => prepend_if_no_line("I am the first line"), + create => "true"; } - bundle agent line_append { files: - "/tmp/test_line_append" - edit_line => append_if_no_line("I am the last line"), - create => "true"; + "/tmp/test_line_append" + edit_line => append_if_no_line("I am the last line"), + create => "true"; } bundle agent output { vars: - "prepend_file" string => readfile("/tmp/test_line_prepend", 1000); - "append_file" string => readfile("/tmp/test_line_append", 1000); + "prepend_file" string => readfile("/tmp/test_line_prepend", 1000); + "append_file" string => readfile("/tmp/test_line_append", 1000); reports: - "Contents of /tmp/test_line_prepend:"; - "$(prepend_file)"; - "Contents of /tmp/test_line_append:"; - "$(append_file)"; + "Contents of /tmp/test_line_prepend:"; + "$(prepend_file)"; + "Contents of /tmp/test_line_append:"; + "$(append_file)"; } #+end_src diff --git a/examples/env.cf b/examples/env.cf index 111bafc5a9..dfe933c063 100644 --- a/examples/env.cf +++ b/examples/env.cf @@ -1,17 +1,15 @@ - body common control { - bundlesequence => { "one" }; + bundlesequence => { "one" }; } body agent control { - environment => { "A=123", "B=456", "PGK_PATH=/tmp"}; + environment => { "A=123", "B=456", "PGK_PATH=/tmp" }; } bundle agent one { commands: - - "/usr/bin/env"; + "/usr/bin/env"; } diff --git a/examples/epimenides.cf b/examples/epimenides.cf index 7503e871d1..08d77caf38 100644 --- a/examples/epimenides.cf +++ b/examples/epimenides.cf @@ -1,39 +1,33 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - - body common control { - bundlesequence => { "g" }; + bundlesequence => { "g" }; } bundle common g { vars: - - "head" string => "Swallow my ${tail}"; - "tail" string => "behind my "; + "head" string => "Swallow my ${tail}"; + "tail" string => "behind my "; reports: - - "Go $(head)"; + "Go $(head)"; } diff --git a/examples/escape.cf b/examples/escape.cf index 2ff234e723..391b7a4052 100644 --- a/examples/escape.cf +++ b/examples/escape.cf @@ -1,41 +1,37 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - #+begin_src cfengine3 body common control { - bundlesequence => { "example" }; + bundlesequence => { "example" }; } bundle agent example { vars: - "ip" string => "10.123.321.250"; - "escaped" string => escape($(ip)); + "ip" string => "10.123.321.250"; + "escaped" string => escape($(ip)); reports: - "escaped $(ip) = $(escaped)"; + "escaped $(ip) = $(escaped)"; } - #+end_src ############################################################################### #+begin_src example_output diff --git a/examples/eval.cf b/examples/eval.cf index b537d1fdf9..96728356ce 100644 --- a/examples/eval.cf +++ b/examples/eval.cf @@ -1,45 +1,62 @@ #+begin_src cfengine3 body common control { - bundlesequence => { run }; + bundlesequence => { run }; } + body agent control { - inform => "true"; + inform => "true"; } + bundle agent run { vars: - "values[0]" string => "x"; # bad - "values[1]" string => "+ 200"; # bad - "values[2]" string => "200 + 100"; - "values[3]" string => "200 - 100"; - "values[4]" string => "- - -"; # bad - "values[5]" string => "2 + 3 - 1"; - "values[6]" string => ""; # 0 - "values[7]" string => "3 / 0"; # inf but not an error - "values[8]" string => "3^3"; - # "values[9]" string => "-1^2.1"; # 'nan' or '-nan' (on some platforms) - "values[10]" string => "sin(20)"; - "values[11]" string => "cos(20)"; - "values[19]" string => "20 % 3"; # remainder - "values[20]" string => "sqrt(0.2)"; - "values[21]" string => "ceil(3.5)"; - "values[22]" string => "floor(3.4)"; - "values[23]" string => "abs(-3.4)"; - "values[24]" string => "-3.4 == -3.4"; - "values[25]" string => "-3.400000 == -3.400001"; - "values[26]" string => "e"; - "values[27]" string => "pi"; - "values[28]" string => "100m"; # 100 million - "values[29]" string => "100k"; # 100 thousand + "values[0]" string => "x"; + + # bad + "values[1]" string => "+ 200"; + + # bad + "values[2]" string => "200 + 100"; + "values[3]" string => "200 - 100"; + "values[4]" string => "- - -"; + + # bad + "values[5]" string => "2 + 3 - 1"; + "values[6]" string => ""; + + # 0 + "values[7]" string => "3 / 0"; + + # inf but not an error + "values[8]" string => "3^3"; + + # "values[9]" string => "-1^2.1"; # 'nan' or '-nan' (on some platforms) + "values[10]" string => "sin(20)"; + "values[11]" string => "cos(20)"; + "values[19]" string => "20 % 3"; + + # remainder + "values[20]" string => "sqrt(0.2)"; + "values[21]" string => "ceil(3.5)"; + "values[22]" string => "floor(3.4)"; + "values[23]" string => "abs(-3.4)"; + "values[24]" string => "-3.4 == -3.4"; + "values[25]" string => "-3.400000 == -3.400001"; + "values[26]" string => "e"; + "values[27]" string => "pi"; + "values[28]" string => "100m"; - "indices" slist => sort( getindices("values"), int); + # 100 million + "values[29]" string => "100k"; - "eval[$(indices)]" string => eval("$(values[$(indices)])", "math", "infix"); + # 100 thousand + "indices" slist => sort(getindices("values"), int); + "eval[$(indices)]" string => eval("$(values[$(indices)])", "math", "infix"); reports: - "math/infix eval('$(values[$(indices)])') = '$(eval[$(indices)])'"; + "math/infix eval('$(values[$(indices)])') = '$(eval[$(indices)])'"; } #+end_src ############################################################################### diff --git a/examples/every.cf b/examples/every.cf index 58e9c50cf6..72c2abd567 100644 --- a/examples/every.cf +++ b/examples/every.cf @@ -1,85 +1,102 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - #+begin_src cfengine3 body common control { - bundlesequence => { "test" }; + bundlesequence => { "test" }; } bundle agent test - { classes: - "every_dot_star" expression => every(".*", test); - "every_dot" expression => every(".", test); - "every_number" expression => every("[0-9]", test); - - "every2_dot_star" expression => every(".*", test2); - "every2_dot" expression => every(".", test2); - "every2_number" expression => every("[0-9]", test2); + "every_dot_star" expression => every(".*", test); + "every_dot" expression => every(".", test); + "every_number" expression => every("[0-9]", test); + "every2_dot_star" expression => every(".*", test2); + "every2_dot" expression => every(".", test2); + "every2_number" expression => every("[0-9]", test2); vars: - "test" slist => { - 1,2,3, - "one", "two", "three", - "long string", - "four", "fix", "six", - "one", "two", "three", + "test" + slist => { + 1, + 2, + 3, + "one", + "two", + "three", + "long string", + "four", + "fix", + "six", + "one", + "two", + "three", }; - "test2" data => parsejson('[1,2,3, + "test2" + data => parsejson( + '[1,2,3, "one", "two", "three", "long string", "four", "fix", "six", - "one", "two", "three",]'); + "one", "two", "three",]' + ); reports: - "The test list is $(test)"; + "The test list is $(test)"; every_dot_star:: "every() test passed: every element matches '.*'"; + !every_dot_star:: "every() test failed: not every element matches '.*'"; + every_number:: "every() test failed: every element matches '[0-9]'"; + !every_number:: "every() test passed: not every element matches '[0-9]'"; + every_dot:: "every() test failed: every element matches '.'"; + !every_dot:: "every() test passed: not every element matches '.'"; - "The test2 list is $(test2)"; + every2_dot_star:: "every() test2 passed: every element matches '.*'"; + !every2_dot_star:: "every() test2 failed: not every element matches '.*'"; + every2_number:: "every() test2 failed: every element matches '[0-9]'"; + !every2_number:: "every() test2 passed: not every element matches '[0-9]'"; + every2_dot:: "every() test2 failed: every element matches '.'"; + !every2_dot:: "every() test2 passed: not every element matches '.'"; } diff --git a/examples/exec_args.cf b/examples/exec_args.cf index 152ba55eea..bcfa01a14f 100644 --- a/examples/exec_args.cf +++ b/examples/exec_args.cf @@ -1,48 +1,36 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - # # Test the symmetry between using / not using args => # Locks should prevent these from being run twice, all else being equal. -# - body common control { - bundlesequence => { "main" }; + bundlesequence => { "main" }; } bundle agent main { - vars: - - "testlist" slist => { "apple", "banana", "carrot" }; + "testlist" slist => { "apple", "banana", "carrot" }; commands: - - "/bin/echo test1 $(testlist)"; - - "/bin/echo test1" - - args => "$(testlist)"; - + "/bin/echo test1 $(testlist)"; + "/bin/echo test1" args => "$(testlist)"; } diff --git a/examples/exec_in_sequence.cf b/examples/exec_in_sequence.cf index 6c302c1d3f..ba15e80016 100644 --- a/examples/exec_in_sequence.cf +++ b/examples/exec_in_sequence.cf @@ -1,81 +1,60 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - ######################################################## # # Simple test execution # ######################################################## - body common control - { - bundlesequence => { "example" }; + bundlesequence => { "example" }; } - ######################################################## - bundle agent example - { vars: - - "size" int => "46k"; - "rand" int => randomint("33","$(size)"); + "size" int => "46k"; + "rand" int => randomint("33", "$(size)"); commands: - - "/bin/echo" + "/bin/echo" args => "Hello world - $(size)/$(rand)", contain => standard, - classes => cdefine("followup","alert"); + classes => cdefine("followup", "alert"); followup:: - - "/bin/ls" - contain => standard; + "/bin/ls" contain => standard; reports: - alert:: - "What happened?"; - } - ###################################################################### - body contain standard - { - exec_owner => "mark"; - useshell => "useshell"; + exec_owner => "mark"; + useshell => "useshell"; } - ###################################################################### - -body classes cdefine(class,alert) - +body classes cdefine(class, alert) { - promise_repaired => { "$(class)" }; - repair_failed => { "$(alert)" }; + promise_repaired => { "$(class)" }; + repair_failed => { "$(alert)" }; } diff --git a/examples/execd.cf b/examples/execd.cf index e638ee875a..ae83b58d30 100644 --- a/examples/execd.cf +++ b/examples/execd.cf @@ -1,38 +1,33 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - body common control { - bundlesequence => { }; + bundlesequence => {}; } body executor control - { - mailto => "MARK@iu.hio.no"; - mailfrom => "cfengine@domain.tld"; - smtpserver => "MAIL-out.hio.no"; - mailmaxlines => "50"; - schedule => { "Min00_05", "Min30_35" }; - - exec_command => "/var/cfengine/bin/cf-agent"; + mailto => "MARK@iu.hio.no"; + mailfrom => "cfengine@domain.tld"; + smtpserver => "MAIL-out.hio.no"; + mailmaxlines => "50"; + schedule => { "Min00_05", "Min30_35" }; + exec_command => "/var/cfengine/bin/cf-agent"; } diff --git a/examples/execresult.cf b/examples/execresult.cf index b78b7eb01c..9e6aa9be2f 100644 --- a/examples/execresult.cf +++ b/examples/execresult.cf @@ -1,25 +1,22 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - #+begin_src prep #@ ``` #@ rm -rf /tmp/testhere @@ -39,30 +36,32 @@ #+begin_src cfengine3 body common control { - bundlesequence => { "example" }; + bundlesequence => { "example" }; } bundle agent example { vars: - "my_result" - string => execresult("/bin/ls /tmp/testhere", noshell); + "my_result" string => execresult("/bin/ls /tmp/testhere", noshell); - "my_result_with_stdout_and_stderr" - string => execresult("/tmp/testhere/echo-stdout-and-stderr", noshell); + "my_result_with_stdout_and_stderr" + string => execresult("/tmp/testhere/echo-stdout-and-stderr", noshell); - "my_result_with_stdout" - string => execresult("/tmp/testhere/echo-stdout-and-stderr 2>/dev/null", useshell); + "my_result_with_stdout" + string => execresult( + "/tmp/testhere/echo-stdout-and-stderr 2>/dev/null", useshell + ); - "my_result_with_stderr" - string => execresult("/tmp/testhere/echo-stdout-and-stderr 1>/dev/null", useshell); + "my_result_with_stderr" + string => execresult( + "/tmp/testhere/echo-stdout-and-stderr 1>/dev/null", useshell + ); reports: - "/bin/ls /tmp/testhere returned '$(my_result)'"; - "my_result_with_stdout_and_stderr == '$(my_result_with_stdout_and_stderr)'"; - "my_result_with_stdout == '$(my_result_with_stdout)'"; - "my_result_with_stderr == '$(my_result_with_stderr)'"; - + "/bin/ls /tmp/testhere returned '$(my_result)'"; + "my_result_with_stdout_and_stderr == '$(my_result_with_stdout_and_stderr)'"; + "my_result_with_stdout == '$(my_result_with_stdout)'"; + "my_result_with_stderr == '$(my_result_with_stderr)'"; } #+end_src ############################################################################### diff --git a/examples/execresult_as_data.cf b/examples/execresult_as_data.cf index f9b3fc2f41..2bcae48bfa 100644 --- a/examples/execresult_as_data.cf +++ b/examples/execresult_as_data.cf @@ -2,20 +2,17 @@ #+begin_src cfengine3 body common control { - bundlesequence => { "example" }; + bundlesequence => { "example" }; } bundle agent example { vars: - "my_data" - data => execresult_as_data("echo 'hello'", "useshell", "both"); - "my_json_string" - string => storejson(my_data); + "my_data" data => execresult_as_data("echo 'hello'", "useshell", "both"); + "my_json_string" string => storejson(my_data); reports: - "echo 'hello' returned '$(my_json_string)'"; - + "echo 'hello' returned '$(my_json_string)'"; } #+end_src ############################################################################### diff --git a/examples/expand.cf b/examples/expand.cf index df926e12bf..cb9ac84809 100644 --- a/examples/expand.cf +++ b/examples/expand.cf @@ -1,52 +1,36 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - - - body common control - { - bundlesequence => { "example" }; + bundlesequence => { "example" }; } - ########################################################### - bundle agent example - -{ +{ vars: - - "component" slist => { "cf-monitord", "cf-serverd", "cf-execd" }; + "component" slist => { "cf-monitord", "cf-serverd", "cf-execd" }; processes: - - "$(component)" restart_class => canonify("start_$(component)"); + "$(component)" restart_class => canonify("start_$(component)"); commands: - - "/bin/echo /var/cfengine/bin/$(component)" - + "/bin/echo /var/cfengine/bin/$(component)" if => canonify("start_$(component)"); - - } - diff --git a/examples/failedcommand.cf b/examples/failedcommand.cf index ca03c36b05..971a275aef 100644 --- a/examples/failedcommand.cf +++ b/examples/failedcommand.cf @@ -1,31 +1,29 @@ -body common control -{ - bundlesequence => { "cmdtest" }; -} - -bundle agent cmdtest -{ - files: - "/tmp/test" - copy_from => copy("/etc/passwd"); - - - "/tmp/test" - classes => example, - transformer => "/bin/grep -q lkajfo999999 $(this.promiser)"; - - reports: - hasfailed:: - "The files-promise failed!"; -} - -body classes example -{ - failed_returncodes => { "1" }; - repair_failed => { "hasfailed" }; -} - -body copy_from copy(file) -{ - source => "$(file)"; -} +body common control +{ + bundlesequence => { "cmdtest" }; +} + +bundle agent cmdtest +{ + files: + "/tmp/test" copy_from => copy("/etc/passwd"); + + "/tmp/test" + classes => example, + transformer => "/bin/grep -q lkajfo999999 $(this.promiser)"; + + reports: + hasfailed:: + "The files-promise failed!"; +} + +body classes example +{ + failed_returncodes => { "1" }; + repair_failed => { "hasfailed" }; +} + +body copy_from copy(file) +{ + source => "$(file)"; +} diff --git a/examples/file_change_detection.cf b/examples/file_change_detection.cf index 5af7ba9d04..55ca13a2af 100644 --- a/examples/file_change_detection.cf +++ b/examples/file_change_detection.cf @@ -1,88 +1,63 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - ######################################################## # # Simple backgrounding # ######################################################## - body common control - { - bundlesequence => { "example" }; + bundlesequence => { "example" }; } - ######################################################## - body agent control - { - agentaccess => { "mark", "root" }; + agentaccess => { "mark", "root" }; } - ######################################################## - bundle agent example - { files: - - "/home/mark/tmp" -> "me" - - changes => tripwire, + "/home/mark/tmp" -> "me" + changes => tripwire, depth_search => recurse("inf"), - action => background; - - "/home/mark/LapTop/words" -> "you" + action => background; - changes => tripwire, + "/home/mark/LapTop/words" -> "you" + changes => tripwire, depth_search => recurse("inf"); - } - - ######################################################### - body changes tripwire - { - hash => "md5"; - report_changes => "content"; - update_hashes => "true"; + hash => "md5"; + report_changes => "content"; + update_hashes => "true"; } - ######################################################### - body action background - { - background => "true"; + background => "true"; } - ######################################################### - body depth_search recurse(d) - { - depth => "$(d)"; + depth => "$(d)"; } diff --git a/examples/file_hash.cf b/examples/file_hash.cf index 3fc1ce94c6..b2165d867f 100644 --- a/examples/file_hash.cf +++ b/examples/file_hash.cf @@ -1,25 +1,22 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - #+begin_src prep #@ ``` #@ echo 1 > /tmp/1 @@ -31,26 +28,22 @@ #+begin_src cfengine3 body common control { - bundlesequence => { "example" }; + bundlesequence => { "example" }; } bundle agent example - { vars: - - "md5" string => file_hash("/tmp/1","md5"); - "sha256" string => file_hash("/tmp/2","sha256"); - "sha384" string => hash("/tmp/3","sha384"); - "sha512" string => hash("/tmp/3","sha512"); + "md5" string => file_hash("/tmp/1", "md5"); + "sha256" string => file_hash("/tmp/2", "sha256"); + "sha384" string => hash("/tmp/3", "sha384"); + "sha512" string => hash("/tmp/3", "sha512"); reports: - - "'1\n' hashed to: md5 $(md5)"; - "'2\n' hashed to: sha256 $(sha256)"; - "'3\n' hashed to: sha384 $(sha384)"; - "'3\n' hashed to: sha512 $(sha512)"; - + "'1\n' hashed to: md5 $(md5)"; + "'2\n' hashed to: sha256 $(sha256)"; + "'3\n' hashed to: sha384 $(sha384)"; + "'3\n' hashed to: sha512 $(sha512)"; } #+end_src ############################################################################### diff --git a/examples/file_owner_list_template.cf b/examples/file_owner_list_template.cf index 19378897a1..64462f84e9 100644 --- a/examples/file_owner_list_template.cf +++ b/examples/file_owner_list_template.cf @@ -1,60 +1,45 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - ######################################################## # # List substitution in bodies # ######################################################## - body common control - { - bundlesequence => { "example" }; + bundlesequence => { "example" }; } - ######################################################## - bundle agent example - { vars: - - "usernames" slist => { "one", "two", "three" }; + "usernames" slist => { "one", "two", "three" }; files: - - "/home/mark/tmp/test_plain" - + "/home/mark/tmp/test_plain" perms => users("@(usernames)"), create => "true"; - } - ######################################################### - body perms users(x) - { - mode => "0640"; - owners => { @(x) }; + mode => "0640"; + owners => { @(x) }; } diff --git a/examples/fileexists.cf b/examples/fileexists.cf index 008cee6c9e..f8d342f429 100644 --- a/examples/fileexists.cf +++ b/examples/fileexists.cf @@ -1,43 +1,38 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - #+begin_src cfengine3 body common control { - bundlesequence => { "example" }; + bundlesequence => { "example" }; } bundle agent example { classes: - # this.promise_filename has the currently-executed file, so it - # better exist! - "exists" expression => fileexists($(this.promise_filename)); - "exists_etc_passwd" expression => fileexists("/etc/passwd"); + # this.promise_filename has the currently-executed file, so it + # better exist! + "exists" expression => fileexists($(this.promise_filename)); + "exists_etc_passwd" expression => fileexists("/etc/passwd"); reports: - exists:: - "I exist! I mean, file exists!"; } #+end_src diff --git a/examples/filenames.cf b/examples/filenames.cf index 0ed8372349..30173bec41 100644 --- a/examples/filenames.cf +++ b/examples/filenames.cf @@ -1,47 +1,33 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - # # filenames -# - body common control - { - bundlesequence => { "example" }; + bundlesequence => { "example" }; } bundle agent example { files: - - - "/etc/passwd" - - create => "true"; - - "C:\etc\passwd" - create => "true"; - - "etc/passwd" - create => "true"; + "/etc/passwd" create => "true"; + "C:\etc\passwd" create => "true"; + "etc/passwd" create => "true"; } diff --git a/examples/fileperms.cf b/examples/fileperms.cf index 585dfaf519..a15633f9a7 100644 --- a/examples/fileperms.cf +++ b/examples/fileperms.cf @@ -1,52 +1,35 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - body common control - { - - bundlesequence => { - "main" - }; - + bundlesequence => { "main" }; } - ######################################################### - bundle agent main - { - files: - - "/tmp/foo" perms => p("at","0750"); - + "/tmp/foo" perms => p("at", "0750"); } - ######################################################### - -body perms p(user,mode) - +body perms p(user, mode) { - owners => { "$(user)" }; - mode => "$(mode)"; + owners => { "$(user)" }; + mode => "$(mode)"; } diff --git a/examples/files-content-if-fileexists.cf b/examples/files-content-if-fileexists.cf index cde6527bae..07cdfefa18 100644 --- a/examples/files-content-if-fileexists.cf +++ b/examples/files-content-if-fileexists.cf @@ -6,8 +6,9 @@ #+begin_src cfengine3 body agent control { - inform => "true"; + inform => "true"; } + bundle agent __main__ { files: diff --git a/examples/files-content-with.cf b/examples/files-content-with.cf index 6034773507..dc695cf4be 100644 --- a/examples/files-content-with.cf +++ b/examples/files-content-with.cf @@ -6,14 +6,15 @@ #+begin_src cfengine3 body agent control { - inform => "true"; + inform => "true"; } + bundle agent __main__ { files: - "/tmp/hello" - content => "Output from stat: $(with)", - with => execresult( 'stat -c "%U" /', "useshell" ); + "/tmp/hello" + content => "Output from stat: $(with)", + with => execresult('stat -c "%U" /', "useshell"); } #+end_src #+begin_src example_output diff --git a/examples/files-content.cf b/examples/files-content.cf index 0adfd9b06d..362e6b43fb 100644 --- a/examples/files-content.cf +++ b/examples/files-content.cf @@ -6,13 +6,13 @@ #+begin_src cfengine3 body agent control { - inform => "true"; + inform => "true"; } + bundle agent __main__ { files: - "/tmp/hello" - content => "Hello, CFEngine"; + "/tmp/hello" content => "Hello, CFEngine"; } #+end_src #+begin_src example_output diff --git a/examples/files-create-class-expression.cf b/examples/files-create-class-expression.cf index 70f43bada9..3ee1402bee 100644 --- a/examples/files-create-class-expression.cf +++ b/examples/files-create-class-expression.cf @@ -6,14 +6,14 @@ #+begin_src cfengine3 body agent control { - inform => "true"; + inform => "true"; } + bundle agent __main__ { files: linux:: - "/tmp/linux" - create => "true"; + "/tmp/linux" create => "true"; } #+end_src #+begin_src example_output diff --git a/examples/files_auto_define.cf b/examples/files_auto_define.cf index 679d0bf5ec..4b9f4d8ac5 100644 --- a/examples/files_auto_define.cf +++ b/examples/files_auto_define.cf @@ -10,29 +10,30 @@ #+begin_src cfengine3 body agent control { - inform => "true"; # So that we can easily see class definition - files_auto_define => { ".*" }; # Trigger for any copied file + inform => "true"; + # So that we can easily see class definition + files_auto_define => { ".*" }; + # Trigger for any copied file } + bundle agent main { - files: - "/tmp/source_file.txt" - content => "Hello World!"; + "/tmp/source_file.txt" content => "Hello World!"; - "/tmp/example_files_auto_define.txt" - copy_from => local_dcp( "/tmp/source_file.txt" ); + "/tmp/example_files_auto_define.txt" + copy_from => local_dcp("/tmp/source_file.txt"); reports: - "Defined '$(with)', the canonified form of 'auto_/tmp/example_files_auto_define.txt'" - with => canonify( "auto_/tmp/example_files_auto_define.txt"), - if => canonify( "auto_/tmp/example_files_auto_define.txt"); + "Defined '$(with)', the canonified form of 'auto_/tmp/example_files_auto_define.txt'" + with => canonify("auto_/tmp/example_files_auto_define.txt"), + if => canonify("auto_/tmp/example_files_auto_define.txt"); } # Copied from the standard library to make self-contained. body copy_from local_dcp(from) { - source => "$(from)"; - compare => "digest"; + source => "$(from)"; + compare => "digest"; } #+end_src ############################################################################### diff --git a/examples/files_content.cf b/examples/files_content.cf index 285ce4a4a5..b357804b20 100644 --- a/examples/files_content.cf +++ b/examples/files_content.cf @@ -3,36 +3,34 @@ bundle agent example_file_content # @brief Example showing files content { vars: - "my_content" - string => "Hello from var!"; + "my_content" string => "Hello from var!"; files: - "/tmp/hello_string" - create => "true", - content => "Hello from string!"; + "/tmp/hello_string" + create => "true", + content => "Hello from string!"; - "/tmp/hello_var" - create => "true", - content => "$(my_content)"; + "/tmp/hello_var" + create => "true", + content => "$(my_content)"; reports: - "/tmp/hello_string" - printfile => cat( $(this.promiser) ); - "/tmp/hello_var" - printfile => cat( $(this.promiser) ); + "/tmp/hello_string" printfile => cat($(this.promiser)); + "/tmp/hello_var" printfile => cat($(this.promiser)); } body printfile cat(file) # @brief Report the contents of a file # @param file The full path of the file to report { - file_to_print => "$(file)"; - number_of_lines => "inf"; + file_to_print => "$(file)"; + number_of_lines => "inf"; } bundle agent __main__ { - methods: "example_file_content"; + methods: + "example_file_content"; } ############################################################################### #+end_src diff --git a/examples/files_depth_search_include_basedir.cf b/examples/files_depth_search_include_basedir.cf index 52e35dafa9..8befa5c9b2 100644 --- a/examples/files_depth_search_include_basedir.cf +++ b/examples/files_depth_search_include_basedir.cf @@ -21,90 +21,93 @@ bundle agent main # @brief Example showing how to promise permissions recursively and promise a directory tree is empty. It illustrates the behavior of `include_basedir` in `depth_search` bodies and that the delete ignores `include_basedir`. { files: - "/tmp/CFE-3217/test-delete/." -> { "CFE-3217", "CFE-3218" } - depth_search => aggressive("true"), - file_select => all, - delete => tidy, - comment => "include_basedir => 'true' will not result in thd promised directory being removed."; + "/tmp/CFE-3217/test-delete/." -> { "CFE-3217", "CFE-3218" } + depth_search => aggressive("true"), + file_select => all, + delete => tidy, + comment => "include_basedir => 'true' will not result in thd promised directory being removed."; - "/tmp/CFE-3217/test-delete-nobasedir/." - depth_search => aggressive("false"), - file_select => all, - delete => tidy, - comment => "include_basedir => 'false' will not result in thd promised directory being removed."; + "/tmp/CFE-3217/test-delete-nobasedir/." + depth_search => aggressive("false"), + file_select => all, + delete => tidy, + comment => "include_basedir => 'false' will not result in thd promised directory being removed."; - "/tmp/CFE-3217/test-perms/." - perms => m(555), - depth_search => aggressive("true"), - file_select => all, - comment => "include_basedir => 'true' results in thd promised directory having permissions managed as well."; + "/tmp/CFE-3217/test-perms/." + perms => m(555), + depth_search => aggressive("true"), + file_select => all, + comment => "include_basedir => 'true' results in thd promised directory having permissions managed as well."; - "/tmp/CFE-3217/test-perms-nobasedir/." -> { "CFE-3217" } - perms => m(555), - depth_search => aggressive("false"), - file_select => all, - comment => "include_basedir => 'false' results in thd promised directory not having permissions managed."; + "/tmp/CFE-3217/test-perms-nobasedir/." -> { "CFE-3217" } + perms => m(555), + depth_search => aggressive("false"), + file_select => all, + comment => "include_basedir => 'false' results in thd promised directory not having permissions managed."; reports: + "delete => tidy"; - "delete => tidy"; - "/tmp/CFE-3217/test-delete present despite include_basedir => 'true'" - if => isdir("/tmp/CFE-3217/test-delete"); - "/tmp/CFE-3217/test-delete-nobasedir present as expected with include_basedir => 'false'" - if => isdir("/tmp/CFE-3217/test-delete-nobasedir"); - "/tmp/CFE-3217/test-delete absent, unexpectedly" - unless => isdir("/tmp/CFE-3217/test-delete"); - "/tmp/CFE-3217/test-delete-nobasedir absent, unexpectedly" - unless => isdir("/tmp/CFE-3217/test-delete-nobasedir"); + "/tmp/CFE-3217/test-delete present despite include_basedir => 'true'" + if => isdir("/tmp/CFE-3217/test-delete"); + "/tmp/CFE-3217/test-delete-nobasedir present as expected with include_basedir => 'false'" + if => isdir("/tmp/CFE-3217/test-delete-nobasedir"); - "perms => m(555)"; - "/tmp/CFE-3217/test-perms $(with), as expected with include_basedir => 'true'" - with => filestat( "/tmp/CFE-3217/test-perms", modeoct ), - if => strcmp( filestat( "/tmp/CFE-3217/test-perms", modeoct ), "40555" ); + "/tmp/CFE-3217/test-delete absent, unexpectedly" + unless => isdir("/tmp/CFE-3217/test-delete"); - "/tmp/CFE-3217/test-perms-nobasedir $(with), not 555, as expected with include_basedir => 'false'" - with => filestat( "/tmp/CFE-3217/test-perms-nobasedir", modeoct ), - unless => strcmp( filestat( "/tmp/CFE-3217/test-perms-nobasedir", modeoct ), "40555" ); + "/tmp/CFE-3217/test-delete-nobasedir absent, unexpectedly" + unless => isdir("/tmp/CFE-3217/test-delete-nobasedir"); + + "perms => m(555)"; + + "/tmp/CFE-3217/test-perms $(with), as expected with include_basedir => 'true'" + with => filestat("/tmp/CFE-3217/test-perms", modeoct), + if => strcmp(filestat("/tmp/CFE-3217/test-perms", modeoct), "40555"); + + "/tmp/CFE-3217/test-perms-nobasedir $(with), not 555, as expected with include_basedir => 'false'" + with => filestat("/tmp/CFE-3217/test-perms-nobasedir", modeoct), + unless => strcmp( + filestat("/tmp/CFE-3217/test-perms-nobasedir", modeoct), "40555" + ); } body depth_search aggressive(include_basedir) # @brief Search for files recursively from promiser traversing synmlinks and filesystem boundaries. { - depth => "inf"; - # exclude_dirs => { @(exclude_dirs) }; - include_basedir => "$(include_basedir)"; - # include_dirs => { @(include_dirs) }; - # inherit_from => "$(inherit_from)"; - # meta => "$(meta)"; meta attribute inside the depth_search body? It's not documented. TODO!? - rmdeadlinks => "false"; # Depth search removes dead links, this seems like something that should be in delete body. TODO!? - traverse_links => "true"; - xdev => "true"; - + depth => "inf"; + # exclude_dirs => { @(exclude_dirs) }; + include_basedir => "$(include_basedir)"; + # include_dirs => { @(include_dirs) }; + # inherit_from => "$(inherit_from)"; + # meta => "$(meta)"; meta attribute inside the depth_search body? It's not documented. TODO!? + rmdeadlinks => "false"; + # Depth search removes dead links, this seems like something that should be in delete body. TODO!? + traverse_links => "true"; + xdev => "true"; } - #@ Inlined bodies from the stdlib in the Masterfiles Policy Framework - body file_select all # @brief Select all file system entries { - leaf_name => { ".*" }; - file_result => "leaf_name"; + leaf_name => { ".*" }; + file_result => "leaf_name"; } body delete tidy # @brief Delete the file and remove empty directories # and links to directories { - dirlinks => "delete"; - rmdirs => "true"; + dirlinks => "delete"; + rmdirs => "true"; } body perms m(mode) # @brief Set the file mode # @param mode The new mode { - mode => "$(mode)"; + mode => "$(mode)"; } #+end_src ############################################################################### diff --git a/examples/files_transformer.cf b/examples/files_transformer.cf index 11a8e56a26..28edbc27e5 100644 --- a/examples/files_transformer.cf +++ b/examples/files_transformer.cf @@ -12,12 +12,14 @@ bundle agent main { vars: - "gzip_path" string => ifelse( isexecutable("/bin/gzip"), "/bin/gzip", - "/usr/bin/gzip" ); + "gzip_path" + string => ifelse( + isexecutable("/bin/gzip"), "/bin/gzip", "/usr/bin/gzip" + ); + files: linux:: - "/tmp/example-files-transformer.txt" - content => "Hello World"; + "/tmp/example-files-transformer.txt" content => "Hello World"; "/tmp/example-files-transformer.txt" transformer => "$(gzip_path) $(this.promiser)"; @@ -26,7 +28,6 @@ bundle agent main # being absent on completion. Note: It is the expectation and # responsibility of the transformer itself that the transformation results # in the promised file no longer existing. - "/tmp/example-files-transformer.txt" transformer => "$(gzip_path) $(this.promiser)"; @@ -36,21 +37,33 @@ bundle agent main transformer => "$(gzip_path) $(this.promiser)"; reports: - "/tmp/example-files-transformer.txt $(with)" - with => ifelse( fileexists( "/tmp/example-files-transformer.txt"), "exists", - "does not exist"); + "/tmp/example-files-transformer.txt $(with)" + with => ifelse( + fileexists("/tmp/example-files-transformer.txt"), + "exists", + "does not exist" + ); - "/tmp/example-files-transformer.txt.gz $(with)" - with => ifelse( fileexists( "/tmp/example-files-transformer.txt.gz"), "exists", - "does not exist"); + "/tmp/example-files-transformer.txt.gz $(with)" + with => ifelse( + fileexists("/tmp/example-files-transformer.txt.gz"), + "exists", + "does not exist" + ); - "/tmp/this-file-does-not-exist-to-be-transformed.txt $(with)" - with => ifelse( fileexists( "/tmp/this-file-does-not-exist-to-be-transformed.txt"), "exists", - "does not exist"); + "/tmp/this-file-does-not-exist-to-be-transformed.txt $(with)" + with => ifelse( + fileexists("/tmp/this-file-does-not-exist-to-be-transformed.txt"), + "exists", + "does not exist" + ); - "/tmp/this-file-does-not-exist-to-be-transformed.txt.gz $(with)" - with => ifelse( fileexists( "/tmp/this-file-does-not-exist-to-be-transformed.txt.gz"), "exists", - "does not exist"); + "/tmp/this-file-does-not-exist-to-be-transformed.txt.gz $(with)" + with => ifelse( + fileexists("/tmp/this-file-does-not-exist-to-be-transformed.txt.gz"), + "exists", + "does not exist" + ); } #+end_src ############################################################################### diff --git a/examples/filesexist.cf b/examples/filesexist.cf index a1c5f3f241..45e9ddb985 100644 --- a/examples/filesexist.cf +++ b/examples/filesexist.cf @@ -1,51 +1,41 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - #+begin_src cfengine3 body common control - { - bundlesequence => { "example" }; + bundlesequence => { "example" }; } bundle agent example - { vars: - - "mylist" slist => { "/tmp/a", "/tmp/b", "/tmp/c" }; + "mylist" slist => { "/tmp/a", "/tmp/b", "/tmp/c" }; classes: - - "exists" expression => filesexist("@(mylist)"); + "exists" expression => filesexist("@(mylist)"); reports: - exists:: - "All files exist"; !exists:: - "Not all files exist"; } #+end_src diff --git a/examples/filesexist2.cf b/examples/filesexist2.cf index a08d3b7e05..c63268ba4c 100644 --- a/examples/filesexist2.cf +++ b/examples/filesexist2.cf @@ -1,64 +1,45 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - - body common control - { - bundlesequence => { "example" }; + bundlesequence => { "example" }; } - ########################################################### - bundle agent example - -{ +{ vars: - - "mylist" slist => { "/tmp/a", "/tmp/b", "/tmp/c" }; - + "mylist" slist => { "/tmp/a", "/tmp/b", "/tmp/c" }; methods: - - "any" usebundle => crystal_meth(@(example.mylist)); - + "any" usebundle => crystal_meth(@(example.mylist)); } bundle agent crystal_meth(x) - { classes: - - "exists" expression => filesexist("@(x)"); + "exists" expression => filesexist("@(x)"); reports: - exists:: - "File does exist"; !exists:: - "Does not yet exist"; - } - diff --git a/examples/filesize.cf b/examples/filesize.cf index 4e8cb9428c..8711ffd6b0 100644 --- a/examples/filesize.cf +++ b/examples/filesize.cf @@ -1,42 +1,39 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - ############################################################################### #+begin_src cfengine3 body common control { - bundlesequence => { example }; + bundlesequence => { example }; } bundle agent example { vars: - # my own size! - "exists" int => filesize("$(this.promise_filename)"); - "nexists" int => filesize("/etc/passwdx"); + # my own size! + "exists" int => filesize("$(this.promise_filename)"); + "nexists" int => filesize("/etc/passwdx"); reports: - "File size $(exists)"; - "Does not exist: $(nexists)"; + "File size $(exists)"; + "Does not exist: $(nexists)"; } #+end_src ############################################################################### diff --git a/examples/filestat.cf b/examples/filestat.cf index c9c917ecc0..fa1945b9de 100644 --- a/examples/filestat.cf +++ b/examples/filestat.cf @@ -1,25 +1,22 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - #+begin_src prep #@ ``` #@ echo 1234567890 > FILE.txt @@ -32,32 +29,37 @@ #+begin_src cfengine3 body common control { - bundlesequence => { "example" }; + bundlesequence => { "example" }; } bundle agent example { vars: - "file" string => "$(this.promise_filename).txt"; + "file" string => "$(this.promise_filename).txt"; + methods: - "fileinfo" usebundle => fileinfo("$(file)"); + "fileinfo" usebundle => fileinfo("$(file)"); } + bundle agent fileinfo(f) { vars: - # use the full list if you want to see all the attributes! - # "fields" slist => splitstring("size,gid,uid,ino,nlink,ctime,atime,mtime,mode,modeoct,permstr,permoct,type,devno,dev_minor,dev_major,basename,dirname,linktarget,linktarget_shallow", ",", 999); - - # ino (inode number), ctime (creation time), - # devno/dev_minor/dev_major (device numbers) were omitted but - # they are all integers - - "fields" slist => splitstring("size,gid,uid,nlink,mode,modeoct,permstr,permoct,type,basename", ",", 999); + # use the full list if you want to see all the attributes! + # "fields" slist => splitstring("size,gid,uid,ino,nlink,ctime,atime,mtime,mode,modeoct,permstr,permoct,type,devno,dev_minor,dev_major,basename,dirname,linktarget,linktarget_shallow", ",", 999); + # ino (inode number), ctime (creation time), + # devno/dev_minor/dev_major (device numbers) were omitted but + # they are all integers + "fields" + slist => splitstring( + "size,gid,uid,nlink,mode,modeoct,permstr,permoct,type,basename", + ",", + 999 + ); - "stat[$(f)][$(fields)]" string => filestat($(f), $(fields)); + "stat[$(f)][$(fields)]" string => filestat($(f), $(fields)); reports: - "$(this.bundle): file $(stat[$(f)][basename]) has $(fields) = $(stat[$(f)][$(fields)])"; + "$(this.bundle): file $(stat[$(f)][basename]) has $(fields) = $(stat[$(f)][$(fields)])"; } #+end_src ############################################################################### diff --git a/examples/filter.cf b/examples/filter.cf index 29d23a1a10..673e29cc67 100644 --- a/examples/filter.cf +++ b/examples/filter.cf @@ -1,78 +1,84 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - #+begin_src cfengine3 body common control { - bundlesequence => { "test" }; + bundlesequence => { "test" }; } bundle agent test { vars: - "test" slist => { - 1,2,3, - "one", "two", "three", - "long string", - "one", "two", "three", + "test" + slist => { + 1, 2, 3, "one", "two", "three", "long string", "one", "two", "three", }; - "test2" data => parsejson('[1,2,3, "ab", "c"]'); - - "test_filtergrep" slist => filter("[0-9]", test, "true", "false", 999); - "test_exact1" slist => filter("one", test, "false", "false", 999); - "test_exact2" slist => filter(".", test, "false", "false", 999); - "test_invert" slist => filter("[0-9]", test, "true", "true", 999); - "test_max2" slist => filter(".*", test, "true", "false", 2); - "test_max0" slist => filter(".*", test, "true", "false", 0); - "test_grep" slist => grep("[0-9]", test); + "test2" data => parsejson('[1,2,3, "ab", "c"]'); + "test_filtergrep" slist => filter("[0-9]", test, "true", "false", 999); + "test_exact1" slist => filter("one", test, "false", "false", 999); + "test_exact2" slist => filter(".", test, "false", "false", 999); + "test_invert" slist => filter("[0-9]", test, "true", "true", 999); + "test_max2" slist => filter(".*", test, "true", "false", 2); + "test_max0" slist => filter(".*", test, "true", "false", 0); + "test_grep" slist => grep("[0-9]", test); + "test2_filtergrep" slist => filter("[0-9]", test2, "true", "false", 999); + "test2_exact1" slist => filter("one", test2, "false", "false", 999); + "test2_exact2" slist => filter(".", test2, "false", "false", 999); + "test2_invert" slist => filter("[0-9]", test2, "true", "true", 999); + "test2_max2" slist => filter(".*", test2, "true", "false", 2); + "test2_max0" slist => filter(".*", test2, "true", "false", 0); + "test2_grep" slist => grep("[0-9]", test2); - "test2_filtergrep" slist => filter("[0-9]", test2, "true", "false", 999); - "test2_exact1" slist => filter("one", test2, "false", "false", 999); - "test2_exact2" slist => filter(".", test2, "false", "false", 999); - "test2_invert" slist => filter("[0-9]", test2, "true", "true", 999); - "test2_max2" slist => filter(".*", test2, "true", "false", 2); - "test2_max0" slist => filter(".*", test2, "true", "false", 0); - "test2_grep" slist => grep("[0-9]", test2); - - "todo" slist => { "test", "test2", "test_filtergrep", "test_exact1", - "test_exact2", "test_invert", "test_max2", - "test_max0", "test_grep", "test2_filtergrep", - "test2_exact1", "test2_exact2", - "test2_invert", "test2_max2", "test2_max0", - "test2_grep"}; + "todo" + slist => { + "test", + "test2", + "test_filtergrep", + "test_exact1", + "test_exact2", + "test_invert", + "test_max2", + "test_max0", + "test_grep", + "test2_filtergrep", + "test2_exact1", + "test2_exact2", + "test2_invert", + "test2_max2", + "test2_max0", + "test2_grep", + }; - "$(todo)_str" string => format("%S", $(todo)); - "tests" slist => { "test", "test2" }; + "$(todo)_str" string => format("%S", $(todo)); + "tests" slist => { "test", "test2" }; reports: - "The $(tests) list is $($(tests)_str)"; - "The grepped list (only single digits from $(tests)) is $($(tests)_grep_str)"; - "The filter-grepped list (only single digits from $(tests)) is $($(tests)_grep_str)"; - "The filter-exact list, looking for only 'one' in $(tests), is $($(tests)_exact1_str)"; - "This list should be empty, the '.' is not literally in the list $(tests): $($(tests)_exact2_str)"; - "The filter-invert list, looking for non-digits in $(tests), is $($(tests)_invert_str)"; - "The filter-bound list, matching at most 2 items from the whole list $(tests), is $($(tests)_max2_str)"; - "This list should be empty because 0 elements of $(tests) were requested: $($(tests)_max0_str)"; + "The $(tests) list is $($(tests)_str)"; + "The grepped list (only single digits from $(tests)) is $($(tests)_grep_str)"; + "The filter-grepped list (only single digits from $(tests)) is $($(tests)_grep_str)"; + "The filter-exact list, looking for only 'one' in $(tests), is $($(tests)_exact1_str)"; + "This list should be empty, the '.' is not literally in the list $(tests): $($(tests)_exact2_str)"; + "The filter-invert list, looking for non-digits in $(tests), is $($(tests)_invert_str)"; + "The filter-bound list, matching at most 2 items from the whole list $(tests), is $($(tests)_max2_str)"; + "This list should be empty because 0 elements of $(tests) were requested: $($(tests)_max0_str)"; } #+end_src ############################################################################### diff --git a/examples/findfiles.cf b/examples/findfiles.cf index 1ef73683de..615a97e818 100644 --- a/examples/findfiles.cf +++ b/examples/findfiles.cf @@ -1,41 +1,37 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - #+begin_src cfengine3 body common control { - bundlesequence => { run }; + bundlesequence => { run }; } bundle agent run { vars: - "findtmp" slist => findfiles("/[tT][mM][pP]"); - # or find all .txt files under /tmp, up to 6 levels deep... - # "findtmp" slist => findfiles("/tmp/**/*.txt"); + "findtmp" slist => findfiles("/[tT][mM][pP]"); + # or find all .txt files under /tmp, up to 6 levels deep... + # "findtmp" slist => findfiles("/tmp/**/*.txt"); reports: - "All files that match '/[tT][mM][pP]' = $(findtmp)"; + "All files that match '/[tT][mM][pP]' = $(findtmp)"; } - #+end_src ############################################################################### #+begin_src example_output diff --git a/examples/findfiles_up.cf b/examples/findfiles_up.cf index f667c8d218..3463a5fe93 100644 --- a/examples/findfiles_up.cf +++ b/examples/findfiles_up.cf @@ -12,17 +12,14 @@ bundle agent __main__ { vars: - "path" # path to search up from - string => "/tmp/repo/submodule/some/place/deep/within/my/repo/"; - "glob" # glob pattern matching filename - string => ".git/config"; - "level" # how far to search - int => "inf"; - "configs" - data => findfiles_up("$(path)", "$(glob)", "$(level)"); + "path" string => "/tmp/repo/submodule/some/place/deep/within/my/repo/"; + "glob" string => ".git/config"; + "level" int => "inf"; + "configs" data => findfiles_up("$(path)", "$(glob)", "$(level)"); + reports: - "Submodules '$(glob)' is located in '$(configs[0])'"; - "Parents '$(glob)' is located in '$(configs[1])'"; + "Submodules '$(glob)' is located in '$(configs[0])'"; + "Parents '$(glob)' is located in '$(configs[1])'"; } #+end_src ############################################################################### diff --git a/examples/findlocalusers.cf b/examples/findlocalusers.cf index 0aaf4558fd..75cd543f66 100644 --- a/examples/findlocalusers.cf +++ b/examples/findlocalusers.cf @@ -7,24 +7,17 @@ body common control bundle agent example { vars: - "root_filter" - slist => {"gid=0", "name=root"}; - "root_container" - data => findlocalusers("@(root_filter)"); - "root_list" - slist => getindices("root_container"); - "bin_filter" - data => '["name=bin"]'; - "bin_container" - data => findlocalusers("@(bin_filter)"); - "bin_list" - slist => getindices("bin_container"); + "root_filter" slist => { "gid=0", "name=root" }; + "root_container" data => findlocalusers("@(root_filter)"); + "root_list" slist => getindices("root_container"); + "bin_filter" data => '["name=bin"]'; + "bin_container" data => findlocalusers("@(bin_filter)"); + "bin_list" slist => getindices("bin_container"); reports: "List: $(root_list)"; "List: $(bin_list)"; } - #+end_src ############################################################################# #+begin_src example_output diff --git a/examples/fix_names.cf b/examples/fix_names.cf index 5b97823cc8..a99f79da7e 100644 --- a/examples/fix_names.cf +++ b/examples/fix_names.cf @@ -1,25 +1,22 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - ###################################################################### # # File editing @@ -30,48 +27,28 @@ # - insert # ###################################################################### - - body common control - { - version => "1.2.3"; - bundlesequence => { "example" }; + version => "1.2.3"; + bundlesequence => { "example" }; } - ######################################################## - bundle agent example - { - files: - - "/home/mark/LapTop/Cfengine3/trunk/src/.*\.[ch]" - - edit_line => change_name; + "/home/mark/LapTop/Cfengine3/trunk/src/.*\.[ch]" edit_line => change_name; } - ######################################################## - bundle edit_line change_name { replace_patterns: - - "Verbose\(" - - replace_with => With("CfOut(cf_verbose,\"\","); - + "Verbose\(" replace_with => With("CfOut(cf_verbose,\"\","); } - ######################################## # Bodies ######################################## - body replace_with With(x) - { - replace_value => "$(x)"; - occurrences => "all"; + replace_value => "$(x)"; + occurrences => "all"; } - diff --git a/examples/format.cf b/examples/format.cf index de0eee95cd..3c6c303e91 100644 --- a/examples/format.cf +++ b/examples/format.cf @@ -1,55 +1,55 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - #+begin_src cfengine3 body common control { - bundlesequence => { "run" }; + bundlesequence => { "run" }; } bundle agent run { vars: - "v" string => "2.5.6"; - "vlist" slist => splitstring($(v), "\.", 3); - "padded" string => format("%04d%04d%04d", nth("vlist", 0), nth("vlist", 1), nth("vlist", 2)); - "a" string => format("%10.10s", "x"); - "b" string => format("%-10.10s", "x"); - "c" string => format("%04d", 1); - "d" string => format("%07.2f", 1); - "e" string => format("hello my name is %s %s", "Inigo", "Montoya"); + "v" string => "2.5.6"; + "vlist" slist => splitstring($(v), "\.", 3); - "container" data => parsejson('{ "x": "y", "z": true }'); + "padded" + string => format( + "%04d%04d%04d", nth("vlist", 0), nth("vlist", 1), nth("vlist", 2) + ); - "packed" string => format("slist = %S, container = %S", vlist, container); + "a" string => format("%10.10s", "x"); + "b" string => format("%-10.10s", "x"); + "c" string => format("%04d", 1); + "d" string => format("%07.2f", 1); + "e" string => format("hello my name is %s %s", "Inigo", "Montoya"); + "container" data => parsejson('{ "x": "y", "z": true }'); + "packed" string => format("slist = %S, container = %S", vlist, container); reports: - "version $(v) => padded $(padded)"; - "%10.10s on 'x' => '$(a)'"; - "%-10.10s on 'x' => '$(b)'"; - "%04d on '1' => '$(c)'"; - "%07.2f on '1' => '$(d)'"; - "you killed my father... => '$(e)'"; - "$(packed)"; + "version $(v) => padded $(padded)"; + "%10.10s on 'x' => '$(a)'"; + "%-10.10s on 'x' => '$(b)'"; + "%04d on '1' => '$(c)'"; + "%07.2f on '1' => '$(d)'"; + "you killed my father... => '$(e)'"; + "$(packed)"; } #+end_src ############################################################################### diff --git a/examples/function-return-types.cf b/examples/function-return-types.cf index ebdbeef8fa..1a023a5bc8 100644 --- a/examples/function-return-types.cf +++ b/examples/function-return-types.cf @@ -10,58 +10,76 @@ bundle agent example_function_return_types # @brief Example showing function return types { - classes: - "this_file_exists" expression => fileexists( $(this.promise_filename) ); + "this_file_exists" expression => fileexists($(this.promise_filename)); vars: - "my_string" string => concat( "Promises you cannot keep", - " are no better than lies"); - - "my_list_of_strings" - slist => readstringlist( "/tmp/list.txt", # File to read - "", # Don't ignore any lines - "\n", # Split on newlines - inf, # Extract as many entries as possible - inf); # Read in as much data as possible - - "my_list_of_integers" - ilist => readintlist( "/tmp/list.txt", # File to read - "^(\D+)|(\d+[^\n]+)", # Ignore any lines that are not integers - "\n", # Split on newlines - inf, # Maximum number of entries - inf); # Maximum number of bytes to read + "my_string" + string => concat("Promises you cannot keep", " are no better than lies"); - "my_list_of_reals" - rlist => readreallist( "/tmp/list.txt", # File to read - "^(\D+)", # Ignore any lines that are not digits - "\n", # Split on newlines - inf, # Maximum number of entries - inf); # Maximum number of bytes to read + "my_list_of_strings" + slist => readstringlist( + "/tmp/list.txt", + # File to read + "", + # Don't ignore any lines + "\n", + # Split on newlines + inf, + # Extract as many entries as possible + inf + ); - "my_integer" int => string_length( $(my_string) ); + # Read in as much data as possible + "my_list_of_integers" + ilist => readintlist( + "/tmp/list.txt", + # File to read + "^(\D+)|(\d+[^\n]+)", + # Ignore any lines that are not integers + "\n", + # Split on newlines + inf, + # Maximum number of entries + inf + ); - "my_real" real => sum( my_list_of_integers ); + # Maximum number of bytes to read + "my_list_of_reals" + rlist => readreallist( + "/tmp/list.txt", + # File to read + "^(\D+)", + # Ignore any lines that are not digits + "\n", + # Split on newlines + inf, + # Maximum number of entries + inf + ); - "my_data" data => mergedata( '{ "Hello": "world!" }' ); + # Maximum number of bytes to read + "my_integer" int => string_length($(my_string)); + "my_real" real => sum(my_list_of_integers); + "my_data" data => mergedata('{ "Hello": "world!" }'); reports: - "my_string: '$(my_string)'"; - "my_list_of_strings includes '$(my_list_of_strings)'"; - "my_list_of_integers includes '$(my_list_of_integers)'"; - "my_list_of_reals includes '$(my_list_of_reals)'"; - "my_integer: '$(my_integer)'"; - "my_real: '$(my_real)'"; - "my_data: '$(with)'" - with => string_mustache( "{{%-top-}}", my_data ); + "my_string: '$(my_string)'"; + "my_list_of_strings includes '$(my_list_of_strings)'"; + "my_list_of_integers includes '$(my_list_of_integers)'"; + "my_list_of_reals includes '$(my_list_of_reals)'"; + "my_integer: '$(my_integer)'"; + "my_real: '$(my_real)'"; + "my_data: '$(with)'" with => string_mustache("{{%-top-}}", my_data); this_file_exists:: "This file exists."; - } + bundle agent __main__ { - methods: "example_function_return_types"; + methods: + "example_function_return_types"; } #+end_src #+begin_src example_output diff --git a/examples/getacls.cf b/examples/getacls.cf index 637e2bb253..ab4baa6f7a 100644 --- a/examples/getacls.cf +++ b/examples/getacls.cf @@ -1,8 +1,6 @@ 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/examples/getbundlemetatags.cf b/examples/getbundlemetatags.cf index 46f57d64b9..e14314c89c 100644 --- a/examples/getbundlemetatags.cf +++ b/examples/getbundlemetatags.cf @@ -15,10 +15,8 @@ bundle agent example }; vars: - "bundle_tags" - slist => getbundlemetatags("default:example"); - "contact_tag" - slist => getbundlemetatags("default:example", "contact"); + "bundle_tags" slist => getbundlemetatags("default:example"); + "contact_tag" slist => getbundlemetatags("default:example", "contact"); reports: "Found tags: $(bundle_tags)"; diff --git a/examples/getclassmetatags.cf b/examples/getclassmetatags.cf index c816205047..a1ab0027cb 100644 --- a/examples/getclassmetatags.cf +++ b/examples/getclassmetatags.cf @@ -1,44 +1,42 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - #+begin_src cfengine3 body common control { - bundlesequence => { "example" }; + bundlesequence => { "example" }; } bundle agent example { classes: - "c" expression => "any", meta => { "mytag", "other=once", "other=twice" }; + "c" + expression => "any", + meta => { "mytag", "other=once", "other=twice" }; vars: - "ctags" slist => getclassmetatags("c"); - "othertag_values" slist => getclassmetatags("c", "other"); + "ctags" slist => getclassmetatags("c"); + "othertag_values" slist => getclassmetatags("c", "other"); reports: - "Found tags: $(ctags)"; - "Found tags for key 'other': $(othertag_values)"; - + "Found tags: $(ctags)"; + "Found tags for key 'other': $(othertag_values)"; } #+end_src ############################################################################### diff --git a/examples/getenv.cf b/examples/getenv.cf index 56d73977fa..bc3d8fc065 100644 --- a/examples/getenv.cf +++ b/examples/getenv.cf @@ -1,51 +1,42 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - #+begin_src cfengine3 body common control { - bundlesequence => { "example" }; + bundlesequence => { "example" }; } bundle agent example { vars: - - "myvar" string => getenv("EXAMPLE","2048"); + "myvar" string => getenv("EXAMPLE", "2048"); classes: - - "isdefined" not => strcmp("$(myvar)",""); + "isdefined" not => strcmp("$(myvar)", ""); reports: - isdefined:: - "The EXAMPLE environment variable is $(myvar)"; !isdefined:: - "The environment variable EXAMPLE does not exist"; - } #+end_src ############################################################################### diff --git a/examples/getfields.cf b/examples/getfields.cf index 7e1a6666f9..dbd161f83d 100644 --- a/examples/getfields.cf +++ b/examples/getfields.cf @@ -1,49 +1,44 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - #+begin_src cfengine3 body common control { - bundlesequence => { "example" }; + bundlesequence => { "example" }; } bundle agent example { vars: - - "no" int => getfields("root:.*","/etc/passwd",":","userdata"); + "no" int => getfields("root:.*", "/etc/passwd", ":", "userdata"); reports: - "Found $(no) lines matching"; - "root's handle = $(userdata[1])"; - "root's passwd = ... forget it!"; - "root's uid = $(userdata[3])"; - # uncomment this if you want to see the HOMEDIR field - #"root's homedir = $(userdata[6])"; - # uncomment this if you want to see the GID field - #"root's gid = $(userdata[4])"; - # uncomment this if you want to see the GECOS field - #"root's name = $(userdata[5])"; - + "Found $(no) lines matching"; + "root's handle = $(userdata[1])"; + "root's passwd = ... forget it!"; + "root's uid = $(userdata[3])"; + # uncomment this if you want to see the HOMEDIR field + #"root's homedir = $(userdata[6])"; + # uncomment this if you want to see the GID field + #"root's gid = $(userdata[4])"; + # uncomment this if you want to see the GECOS field + #"root's name = $(userdata[5])"; } #+end_src ############################################################################### diff --git a/examples/getgid.cf b/examples/getgid.cf index 3d9978e9c3..f40f3e34c1 100644 --- a/examples/getgid.cf +++ b/examples/getgid.cf @@ -1,29 +1,26 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - #+begin_src cfengine3 body common control { - bundlesequence => { "example" }; + bundlesequence => { "example" }; } bundle agent example @@ -31,13 +28,15 @@ bundle agent example vars: linux|solaris|hpux:: "gid" int => getgid("root"); + freebsd|darwin|openbsd:: "gid" int => getgid("wheel"); + aix:: "gid" int => getgid("system"); reports: - "root's gid is $(gid)"; + "root's gid is $(gid)"; } #+end_src ############################################################################### diff --git a/examples/getindices.cf b/examples/getindices.cf index c6f97522ed..84525a7157 100644 --- a/examples/getindices.cf +++ b/examples/getindices.cf @@ -1,51 +1,45 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - #+begin_src cfengine3 body common control { - bundlesequence => { "example" }; + bundlesequence => { "example" }; } bundle agent example { vars: - - "ps[relayhost]" string => "[mymailrelay]:587"; - "ps[mydomain]" string => "iu.hio.no"; - "ps[smtp_sasl_auth_enable]" string => "yes"; - "ps[smtp_sasl_password_maps]" string => "hash:/etc/postfix/sasl-passwd"; - "ps[smtp_sasl_security_options]" string => ""; - "ps[smtp_use_tls]" string => "yes"; - "ps[default_privs]" string => "mailman"; - "ps[inet_protocols]" string => "all"; - "ps[inet_interfaces]" string => "127.0.0.1"; - - "parameter_name" slist => getindices("ps"); - "parameter_name_sorted" slist => sort(parameter_name, lex); + "ps[relayhost]" string => "[mymailrelay]:587"; + "ps[mydomain]" string => "iu.hio.no"; + "ps[smtp_sasl_auth_enable]" string => "yes"; + "ps[smtp_sasl_password_maps]" string => "hash:/etc/postfix/sasl-passwd"; + "ps[smtp_sasl_security_options]" string => ""; + "ps[smtp_use_tls]" string => "yes"; + "ps[default_privs]" string => "mailman"; + "ps[inet_protocols]" string => "all"; + "ps[inet_interfaces]" string => "127.0.0.1"; + "parameter_name" slist => getindices("ps"); + "parameter_name_sorted" slist => sort(parameter_name, lex); reports: - - "Found key $(parameter_name_sorted)"; + "Found key $(parameter_name_sorted)"; } #+end_src ############################################################################### diff --git a/examples/getindices_and_values.cf b/examples/getindices_and_values.cf index e5934b68c7..02aac4f8c9 100644 --- a/examples/getindices_and_values.cf +++ b/examples/getindices_and_values.cf @@ -1,50 +1,38 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - - body common control - { - bundlesequence => { "example" }; + bundlesequence => { "example" }; } - - ####################################################### - bundle agent example - { vars: - - "v[index_1]" string => "value_1"; - "v[index_2]" string => "value_2"; - - "x" slist => getindices("v"); - "y" slist => getvalues("v"); + "v[index_1]" string => "value_1"; + "v[index_2]" string => "value_2"; + "x" slist => getindices("v"); + "y" slist => getvalues("v"); reports: - - "All indices:"; - " Found index: $(x) with value \"$(v[$(x)])\""; - "All values:"; - " Found value: $(y)"; + "All indices:"; + " Found index: $(x) with value \"$(v[$(x)])\""; + "All values:"; + " Found value: $(y)"; } diff --git a/examples/getmacaddress.cf b/examples/getmacaddress.cf index b9d2fc08d1..ede4fe6923 100644 --- a/examples/getmacaddress.cf +++ b/examples/getmacaddress.cf @@ -1,65 +1,49 @@ - body common control { - bundlesequence => { "get_mac_adr" }; + bundlesequence => { "get_mac_adr" }; } - ############################################################## - bundle agent get_mac_adr { 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"); classes: - linux:: - - "ok" expression => regextract( - ".*HWaddr ([^\s]+).*(\n.*)*", - "$(interface)", - "mac" - ); + "ok" + expression => regextract( + ".*HWaddr ([^\s]+).*(\n.*)*", "$(interface)", "mac" + ); solaris:: - - "ok" expression => regextract( - ".*ether ([^\s]+).*(\n.*)*", - "$(interface)", - "mac" - ); + "ok" + expression => regextract( + ".*ether ([^\s]+).*(\n.*)*", "$(interface)", "mac" + ); freebsd:: - - "ok" expression => regextract( - ".*ether ([^\s]+).*(\n.*)*", - "$(interface)", - "mac" - ); + "ok" + expression => regextract( + ".*ether ([^\s]+).*(\n.*)*", "$(interface)", "mac" + ); darwin:: - - "ok" expression => regextract( - "(?s).*ether ([^\s]+).*(\n.*)*", - "$(interface)", - "mac" - ); + "ok" + expression => regextract( + "(?s).*ether ([^\s]+).*(\n.*)*", "$(interface)", "mac" + ); reports: - ok:: - "MAC address is $(mac[1])"; - } diff --git a/examples/getregistry.cf b/examples/getregistry.cf index d3eb3c13bd..1c806196e7 100644 --- a/examples/getregistry.cf +++ b/examples/getregistry.cf @@ -1,41 +1,36 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - - body common control { - bundlesequence => { "reg" }; + bundlesequence => { "reg" }; } bundle agent reg { vars: - windows:: - - "value" string => registryvalue("HKEY_LOCAL_MACHINE\SOFTWARE\Northern.tech AS\Cfengine","value3"); + "value" + string => registryvalue( + "HKEY_LOCAL_MACHINE\SOFTWARE\Northern.tech AS\Cfengine", "value3" + ); reports: - - "Value extracted: $(value)"; - + "Value extracted: $(value)"; } diff --git a/examples/getuid.cf b/examples/getuid.cf index a5076eeeff..1dfa1c37d5 100644 --- a/examples/getuid.cf +++ b/examples/getuid.cf @@ -1,39 +1,35 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - #+begin_src cfengine3 body common control { - bundlesequence => { "example" }; + bundlesequence => { "example" }; } bundle agent example { vars: - - "uid" int => getuid("root"); + "uid" int => getuid("root"); reports: - "root's uid is $(uid)"; + "root's uid is $(uid)"; } #+end_src ############################################################################### diff --git a/examples/getuserinfo.cf b/examples/getuserinfo.cf index 9a516f042e..458a862aca 100644 --- a/examples/getuserinfo.cf +++ b/examples/getuserinfo.cf @@ -1,43 +1,51 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - #+begin_src cfengine3 body common control { - bundlesequence => { "example" }; + bundlesequence => { "example" }; } bundle agent example { - vars: - # note the results here will vary depending on your platform - "me" data => getuserinfo(); # the current user's info - "root" data => getuserinfo("root"); # the "root" user's info (usually UID 0) - "uid0" data => getuserinfo(0); # lookup user info for UID 0 (usually "root") - - # sys.user_data has the information for the user that started the agent - "out" string => format("I am '%s', root shell is '%s', and the agent was started by %S", "$(me[description])", "$(root[shell])", "sys.user_data"); + vars: + # note the results here will vary depending on your platform + "me" data => getuserinfo(); + + # the current user's info + "root" data => getuserinfo("root"); + + # the "root" user's info (usually UID 0) + "uid0" data => getuserinfo(0); + + # lookup user info for UID 0 (usually "root") + # sys.user_data has the information for the user that started the agent + "out" + string => format( + "I am '%s', root shell is '%s', and the agent was started by %S", + "$(me[description])", + "$(root[shell])", + "sys.user_data" + ); reports: - "$(out)"; + "$(out)"; } #+end_src diff --git a/examples/getusers.cf b/examples/getusers.cf index faa37a0450..c4db66ffc7 100644 --- a/examples/getusers.cf +++ b/examples/getusers.cf @@ -1,60 +1,54 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - #+begin_src cfengine3 body common control { - bundlesequence => { "example" }; + bundlesequence => { "example" }; } bundle agent example { vars: - - # The getusers function takes two filtering arguments: exclude_names and - # exclude_ids, both a comma separated list of usernames and user IDs - # respectively. - - # To get users with a uid 1000 and greater we generate a list of uids from - # 0 to 999 and convert it into a comma separated string used to filter the - # list of users. - - "users_with_uid_gt_999" - slist => getusers( "", join( ",", expandrange( "[0-999]", 1 ) ) ); - - # Here we get a list of users except usernames nfsnobody and vagrant as - # well as any users with uid 8 or 9 - - "users_except_nfsnobody_and_vagrant_and_uid_8_and_9" - slist => getusers( "nfsnobody,vagrant", "8,9" ); - - # Here we get a list of all users by not filtering any - "allusers" slist => getusers("",""); - "root_list" slist => { "root" }; - # this will get just the root users out of the full user list - "justroot" slist => intersection(allusers, root_list); + # The getusers function takes two filtering arguments: exclude_names and + # exclude_ids, both a comma separated list of usernames and user IDs + # respectively. + # To get users with a uid 1000 and greater we generate a list of uids from + # 0 to 999 and convert it into a comma separated string used to filter the + # list of users. + "users_with_uid_gt_999" + slist => getusers("", join(",", expandrange("[0-999]", 1))); + + # Here we get a list of users except usernames nfsnobody and vagrant as + # well as any users with uid 8 or 9 + "users_except_nfsnobody_and_vagrant_and_uid_8_and_9" + slist => getusers("nfsnobody,vagrant", "8,9"); + + # Here we get a list of all users by not filtering any + "allusers" slist => getusers("", ""); + "root_list" slist => { "root" }; + + # this will get just the root users out of the full user list + "justroot" slist => intersection(allusers, root_list); reports: - "Found just the root user: $(justroot)"; + "Found just the root user: $(justroot)"; } #+end_src ############################################################################### diff --git a/examples/getvalues.cf b/examples/getvalues.cf index 298b540738..216d07bb4f 100644 --- a/examples/getvalues.cf +++ b/examples/getvalues.cf @@ -1,51 +1,44 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - #+begin_src cfengine3 body common control { - bundlesequence => { "example" }; + bundlesequence => { "example" }; } bundle agent example { vars: + "v[index_1]" string => "value_1"; + "v[index_2]" string => "value_2"; + "values" slist => getvalues("v"); + "values_sorted" slist => sort(values, lex); - "v[index_1]" string => "value_1"; - "v[index_2]" string => "value_2"; - - "values" slist => getvalues("v"); - "values_sorted" slist => sort(values, lex); - - # works with data containers too - "d" data => parsejson('{ "k": [ 1, 2, 3, "a", "b", "c" ] }'); - - "cvalues" slist => getvalues("d[k]"); - "cvalues_sorted" slist => sort(cvalues, lex); + # works with data containers too + "d" data => parsejson('{ "k": [ 1, 2, 3, "a", "b", "c" ] }'); + "cvalues" slist => getvalues("d[k]"); + "cvalues_sorted" slist => sort(cvalues, lex); reports: - "Found values: $(values_sorted)"; - "Found container values: $(cvalues_sorted)"; - + "Found values: $(values_sorted)"; + "Found container values: $(cvalues_sorted)"; } #+end_src ############################################################################### diff --git a/examples/getvariablemetatags.cf b/examples/getvariablemetatags.cf index a251d7e164..2a2217442a 100644 --- a/examples/getvariablemetatags.cf +++ b/examples/getvariablemetatags.cf @@ -1,42 +1,41 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - #+begin_src cfengine3 body common control { - bundlesequence => { "example" }; + bundlesequence => { "example" }; } bundle agent example { vars: - "v" string => "myvalue", meta => { "mytag", "other=once", "other=twice" }; - "vtags" slist => getvariablemetatags("example.v"); - "othertag_values" slist => getvariablemetatags("example.v", "other"); + "v" + string => "myvalue", + meta => { "mytag", "other=once", "other=twice" }; - reports: - "Found tags: $(vtags)"; - "Found tags for key 'other': $(othertag_values)"; + "vtags" slist => getvariablemetatags("example.v"); + "othertag_values" slist => getvariablemetatags("example.v", "other"); + reports: + "Found tags: $(vtags)"; + "Found tags for key 'other': $(othertag_values)"; } #+end_src ############################################################################### diff --git a/examples/global_list_expansion.cf b/examples/global_list_expansion.cf index c295421588..81b6332438 100644 --- a/examples/global_list_expansion.cf +++ b/examples/global_list_expansion.cf @@ -1,62 +1,47 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - # # Show access of external lists. # # - to pass lists globally, use a parameter to dereference them -# - body common control { - bundlesequence => { hardening(@(va.tmpdirs)) }; + bundlesequence => { hardening(@(va.tmpdirs)) }; } - ######################################################### - -bundle common va +bundle common va { vars: - - "tmpdirs" slist => { "/tmp", "/var/tmp", "/usr/tmp" }; - -} - + "tmpdirs" slist => { "/tmp", "/var/tmp", "/usr/tmp" }; +} ########################################################## - bundle agent hardening(x) { classes: - - "ok" expression => "any"; + "ok" expression => "any"; vars: - - "other" slist => { "/tmp", "/var/tmp" }; + "other" slist => { "/tmp", "/var/tmp" }; reports: - ok:: - "Do $(x)"; "Other: $(other)"; -} +} diff --git a/examples/global_list_expansion_2.cf b/examples/global_list_expansion_2.cf index be31985219..314c164d6c 100644 --- a/examples/global_list_expansion_2.cf +++ b/examples/global_list_expansion_2.cf @@ -1,61 +1,46 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - # # Show access of external lists. -# - body common control { - bundlesequence => { hardening }; + bundlesequence => { hardening }; } - ######################################################### - -bundle common va +bundle common va { vars: - - "tmpdirs" slist => { "/tmp", "/var/tmp", "/usr/tmp" }; - -} - + "tmpdirs" slist => { "/tmp", "/var/tmp", "/usr/tmp" }; +} ########################################################## - bundle agent hardening { classes: - - "ok" expression => "any"; + "ok" expression => "any"; vars: - - "other" slist => { "/tmp", "/var/tmp" }; - "x" slist => { @(va.tmpdirs) }; + "other" slist => { "/tmp", "/var/tmp" }; + "x" slist => { @(va.tmpdirs) }; reports: - ok:: - "Do $(x)"; "Other: $(other)"; -} +} diff --git a/examples/grep.cf b/examples/grep.cf index 5d9421a8ef..ef026605e1 100644 --- a/examples/grep.cf +++ b/examples/grep.cf @@ -1,48 +1,52 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - #+begin_src cfengine3 body common control { - bundlesequence => { "test" }; + bundlesequence => { "test" }; } bundle agent test { vars: - - "mylist" slist => { "One", "Two", "Three", "Four", "Five" }; - "Tlist" slist => grep("T.*","mylist"); - "empty_list" slist => grep("ive","mylist"); - - "datalist" data => parsejson('[1,2,3, "Tab", "chive"]'); - "data_Tlist" slist => grep("T.*","datalist"); - "data_empty_list" slist => grep("ive","datalist"); - - "todo" slist => { "mylist", "Tlist", "empty_list", "datalist", "data_Tlist", "data_empty_list" }; - "$(todo)_str" string => format("%S", $(todo)); + "mylist" slist => { "One", "Two", "Three", "Four", "Five" }; + "Tlist" slist => grep("T.*", "mylist"); + "empty_list" slist => grep("ive", "mylist"); + "datalist" data => parsejson('[1,2,3, "Tab", "chive"]'); + "data_Tlist" slist => grep("T.*", "datalist"); + "data_empty_list" slist => grep("ive", "datalist"); + + "todo" + slist => { + "mylist", + "Tlist", + "empty_list", + "datalist", + "data_Tlist", + "data_empty_list", + }; + + "$(todo)_str" string => format("%S", $(todo)); reports: - "$(todo): $($(todo)_str)"; + "$(todo): $($(todo)_str)"; } #+end_src ############################################################################### diff --git a/examples/groupexists.cf b/examples/groupexists.cf index c6c5eddaa7..3410769dc8 100644 --- a/examples/groupexists.cf +++ b/examples/groupexists.cf @@ -1,42 +1,38 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - #+begin_src cfengine3 body common control { - bundlesequence => { "example" }; + bundlesequence => { "example" }; } - ########################################################### - bundle agent example { classes: - "gname" expression => groupexists("sys"); - "gid" expression => groupexists("0"); + "gname" expression => groupexists("sys"); + "gid" expression => groupexists("0"); reports: gname:: "Group exists by name"; + gid:: "Group exists by id"; } diff --git a/examples/guest_environment_kvm.cf b/examples/guest_environment_kvm.cf index 27ee8322be..980f7d7d1b 100644 --- a/examples/guest_environment_kvm.cf +++ b/examples/guest_environment_kvm.cf @@ -1,61 +1,56 @@ -# # Management of KVM/QEMU virtual machines # Assumes you already have a disk image (with an OS installed) for the machine on creation -# - - body common control { - bundlesequence => { "kvm_create" }; + bundlesequence => { "kvm_create" }; } - -bundle agent kvm_create +bundle agent kvm_create { - guest_environments: - "my_host_machine" - environment_resources => mykvm("my_host_machine", "x86_64", "1", "1048576", "/var/lib/libvirt/images/ubuntu104-64-clone.img"), - environment_type => "kvm", - environment_state => "create", - environment_host => "ubuntu"; + "my_host_machine" + environment_resources => mykvm( + "my_host_machine", + "x86_64", + "1", + "1048576", + "/var/lib/libvirt/images/ubuntu104-64-clone.img" + ), + environment_type => "kvm", + environment_state => "create", + environment_host => "ubuntu"; } - bundle agent kvm_suspend { guest_environments: - "my_host_machine" - environment_type => "kvm", - environment_state => "suspended", - environment_host => "ubuntu"; + "my_host_machine" + environment_type => "kvm", + environment_state => "suspended", + environment_host => "ubuntu"; } - bundle agent kvm_run { guest_environments: - "my_host_machine" - environment_type => "kvm", - environment_state => "running", - environment_host => "ubuntu"; + "my_host_machine" + environment_type => "kvm", + environment_state => "running", + environment_host => "ubuntu"; } - bundle agent kvm_delete { guest_environments: - "my_host_machine" - environment_type => "kvm", - environment_state => "delete", - environment_host => "ubuntu"; + "my_host_machine" + environment_type => "kvm", + environment_state => "delete", + environment_host => "ubuntu"; } - body environment_resources mykvm(name, arch, cpu_count, mem_kb, disk_file) { - env_spec => - " + env_spec => " $(name) $(mem_kb) $(mem_kb) @@ -85,4 +80,3 @@ body environment_resources mykvm(name, arch, cpu_count, mem_kb, disk_file) "; } - diff --git a/examples/hash.cf b/examples/hash.cf index ebbda900e3..e09032bb7d 100644 --- a/examples/hash.cf +++ b/examples/hash.cf @@ -1,48 +1,41 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - #+begin_src cfengine3 body common control { - bundlesequence => { "example" }; + bundlesequence => { "example" }; } bundle agent example - { vars: - - "md5" string => hash("Cfengine is not cryptic","md5"); - "sha256" string => hash("Cfengine is not cryptic","sha256"); - "sha384" string => hash("Cfengine is not cryptic","sha384"); - "sha512" string => hash("Cfengine is not cryptic","sha512"); + "md5" string => hash("Cfengine is not cryptic", "md5"); + "sha256" string => hash("Cfengine is not cryptic", "sha256"); + "sha384" string => hash("Cfengine is not cryptic", "sha384"); + "sha512" string => hash("Cfengine is not cryptic", "sha512"); reports: - - "Hashed to: md5 $(md5)"; - "Hashed to: sha256 $(sha256)"; - "Hashed to: sha384 $(sha384)"; - "Hashed to: sha512 $(sha512)"; - + "Hashed to: md5 $(md5)"; + "Hashed to: sha256 $(sha256)"; + "Hashed to: sha384 $(sha384)"; + "Hashed to: sha512 $(sha512)"; } #+end_src ############################################################################### diff --git a/examples/hash_to_int.cf b/examples/hash_to_int.cf index 03d31b9a0d..f5f1d2e4ad 100644 --- a/examples/hash_to_int.cf +++ b/examples/hash_to_int.cf @@ -1,25 +1,22 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - ############################################################################### #+begin_src cfengine3 body common control @@ -30,17 +27,16 @@ body common control bundle agent example { vars: - "hello" int => hash_to_int(0, 1000, "hello"); - "world" int => hash_to_int(0, 1000, "world"); + "hello" int => hash_to_int(0, 1000, "hello"); + "world" int => hash_to_int(0, 1000, "world"); # Hash can vary on hostkey or policy hub: - "hour" int => hash_to_int(0, 24, "$(sys.key_digest)"); + "hour" int => hash_to_int(0, 24, "$(sys.key_digest)"); "minute" int => hash_to_int(0, 60, "$(sys.policy_hub)"); reports: - "'hello' hashed to: $(hello)"; - "'world' hashed to: $(world)"; - + "'hello' hashed to: $(hello)"; + "'world' hashed to: $(world)"; } #+end_src ############################################################################### diff --git a/examples/hashcomment.cf b/examples/hashcomment.cf index e48687d877..68b8e69c8c 100644 --- a/examples/hashcomment.cf +++ b/examples/hashcomment.cf @@ -1,73 +1,54 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - ###################################################################### # # Comment lines # ###################################################################### - body common control - { - version => "1.2.3"; - bundlesequence => { "example" }; + version => "1.2.3"; + bundlesequence => { "example" }; } - ######################################################## - bundle agent example - { files: - - "/home/mark/tmp/comment_test" - - create => "true", + "/home/mark/tmp/comment_test" + create => "true", edit_line => comment_lines_matching; } - ######################################################## - bundle edit_line comment_lines_matching { vars: - - "regexes" slist => { "one.*", "two.*", "four.*" }; + "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"; } - diff --git a/examples/hashmatch.cf b/examples/hashmatch.cf index 2e3f8a2e4d..7543d85b39 100644 --- a/examples/hashmatch.cf +++ b/examples/hashmatch.cf @@ -1,46 +1,36 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - - body common control - { - bundlesequence => { "example" }; + bundlesequence => { "example" }; } - ########################################################### - bundle agent example - -{ +{ classes: - - "matches" expression => hashmatch("/etc/passwd","md5","c5068b7c2b1707f8939b283a2758a691"); + "matches" + expression => hashmatch( + "/etc/passwd", "md5", "c5068b7c2b1707f8939b283a2758a691" + ); reports: - matches:: - "File has correct version"; - } - diff --git a/examples/hashuncomment.cf b/examples/hashuncomment.cf index 1b289b4e59..a5bdba2a82 100644 --- a/examples/hashuncomment.cf +++ b/examples/hashuncomment.cf @@ -1,72 +1,54 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - ###################################################################### # # Uncomment lines # ###################################################################### - body common control - { - version => "1.2.3"; - bundlesequence => { "example" }; + version => "1.2.3"; + bundlesequence => { "example" }; } - # try this on some test data like - # one # two # mark one #mark two - ######################################################## - bundle agent example - { files: - - "/home/mark/tmp/comment_test" - - create => "true", - edit_line => uncomment_lines_matching("\s*mark.*","#"); + "/home/mark/tmp/comment_test" + create => "true", + edit_line => uncomment_lines_matching("\s*mark.*", "#"); } - ######################################################## - -bundle edit_line uncomment_lines_matching(regex,comment) +bundle edit_line uncomment_lines_matching(regex, comment) { replace_patterns: - - "#($(regex))$" replace_with => uncomment; + "#($(regex))$" replace_with => uncomment; } - ######################################################## - body replace_with uncomment { - replace_value => "$(match.1)"; - occurrences => "all"; + replace_value => "$(match.1)"; + occurrences => "all"; } - diff --git a/examples/helloworld.cf b/examples/helloworld.cf index f6a802b06f..fe2484da20 100644 --- a/examples/helloworld.cf +++ b/examples/helloworld.cf @@ -1,29 +1,26 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - bundle agent main { files: - "/tmp/hello_world" - create => "true", - content => "Hello, CFEngine!$(const.n)"; + "/tmp/hello_world" + create => "true", + content => "Hello, CFEngine!$(const.n)"; } diff --git a/examples/host2ip.cf b/examples/host2ip.cf index 02d23d273b..735cecb171 100644 --- a/examples/host2ip.cf +++ b/examples/host2ip.cf @@ -1,49 +1,37 @@ - # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - ####################################################### # # host2ip function # ####################################################### - body common control - { - bundlesequence => { "example" }; + bundlesequence => { "example" }; } - ####################################################### - bundle agent example - { vars: - - "ip" string => host2ip("www.google.com"); + "ip" string => host2ip("www.google.com"); reports: - - "IP address $(ip)"; - + "IP address $(ip)"; } diff --git a/examples/hostrange.cf b/examples/hostrange.cf index 79301a5166..6875b0afe5 100644 --- a/examples/hostrange.cf +++ b/examples/hostrange.cf @@ -1,50 +1,49 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - #+begin_src cfengine3 bundle agent main { vars: - - "range" string => "1-32"; - "hostname_f" string => execresult( "hostname -f", useshell); - "hostname_s" string => execresult( "hostname -s", useshell); - "hostname" string => execresult( "hostname", useshell); + "range" string => "1-32"; + "hostname_f" string => execresult("hostname -f", useshell); + "hostname_s" string => execresult("hostname -s", useshell); + "hostname" string => execresult("hostname", useshell); classes: + "hostgroup_alpha_no_leading_zeros" + expression => hostrange("host", $(range)); - "hostgroup_alpha_no_leading_zeros" expression => hostrange("host", $(range) ); - "hostgroup_alpha_leading_zeros" expression => hostrange("host", "00$(range)" ); - "hostgroup_alpha_UPPERCASE_prefix" expression => hostrange("HOST", "0$(range)" ); + "hostgroup_alpha_leading_zeros" + expression => hostrange("host", "00$(range)"); + + "hostgroup_alpha_UPPERCASE_prefix" + expression => hostrange("HOST", "0$(range)"); reports: - "sys.fqhost = '$(sys.fqhost)'"; - "sys.uqhost = '$(sys.uqhost)'"; - "hostname -f = '$(hostname_f)'"; - "hostname -s = '$(hostname_s)'"; - "hostname = '$(hostname)'"; + "sys.fqhost = '$(sys.fqhost)'"; + "sys.uqhost = '$(sys.uqhost)'"; + "hostname -f = '$(hostname_f)'"; + "hostname -s = '$(hostname_s)'"; + "hostname = '$(hostname)'"; hostgroup_alpha_no_leading_zeros:: - "This host is within the alpha host group range (host$(range))"; hostgroup_alpha_leading_zeros:: diff --git a/examples/hostsseen.cf b/examples/hostsseen.cf index f764a77c56..2aa0fea195 100644 --- a/examples/hostsseen.cf +++ b/examples/hostsseen.cf @@ -1,39 +1,32 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - - body common control { - bundlesequence => { "example" }; + bundlesequence => { "example" }; } bundle agent example - { vars: - - "myhosts" slist => { hostsseen("inf","lastseen","address") }; + "myhosts" slist => { hostsseen("inf", "lastseen", "address") }; reports: - "Found client/peer: $(myhosts)"; - + "Found client/peer: $(myhosts)"; } diff --git a/examples/hostswithclass.cf b/examples/hostswithclass.cf index cd230e3d9a..72e17c3c7b 100644 --- a/examples/hostswithclass.cf +++ b/examples/hostswithclass.cf @@ -1,20 +1,18 @@ body common control { - bundlesequence => { "example" }; - inputs => { "$(sys.libdir)/stdlib.cf" }; + bundlesequence => { "example" }; + inputs => { "$(sys.libdir)/stdlib.cf" }; } - bundle agent example { vars: - am_policy_hub:: - "host_list" slist => hostswithclass( "debian", "name" ); + "host_list" slist => hostswithclass("debian", "name"); files: am_policy_hub:: "/tmp/master_config.cfg" - edit_line => insert_lines("host=$(host_list)"), - create => "true"; + edit_line => insert_lines("host=$(host_list)"), + create => "true"; } diff --git a/examples/hostswithgroup.cf b/examples/hostswithgroup.cf index 2ae2a1aa1e..3b49cf2bb7 100644 --- a/examples/hostswithgroup.cf +++ b/examples/hostswithgroup.cf @@ -8,8 +8,7 @@ bundle agent example { vars: am_policy_hub:: - "host_list" - slist => hostswithgroup("Linux", "name"); + "host_list" slist => hostswithgroup("Linux", "name"); files: am_policy_hub:: diff --git a/examples/hub.cf b/examples/hub.cf index 6a82c42d28..2ea4c4bd3b 100644 --- a/examples/hub.cf +++ b/examples/hub.cf @@ -1,31 +1,27 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - ######################################################## # # Remote value from hub # ######################################################## - # # run this as follows: # @@ -33,55 +29,37 @@ # cf-agent -f runtest_2.cf # # Notice that the same file configures all parts of cfengine - ######################################################## - body common control - { - bundlesequence => { "example" }; - - version => "1.2.3"; + bundlesequence => { "example" }; + version => "1.2.3"; } - ######################################################## - bundle agent example - { vars: - - "remote_value" string => hubknowledge("monitoring"); + "remote_value" string => hubknowledge("monitoring"); reports: - - "Global knowledge: $(remote_value)"; + "Global knowledge: $(remote_value)"; } - ######################################################### # Server config ######################################################### - -body server control - +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 access_rules() - { access: - - "discovered value" - - handle => "monitoring", + "discovered value" + handle => "monitoring", resource_type => "literal", - admit => { "127.0.0.1" }; - + admit => { "127.0.0.1" }; } diff --git a/examples/id.cf b/examples/id.cf index 6779ef204b..7878442a5c 100644 --- a/examples/id.cf +++ b/examples/id.cf @@ -1,110 +1,80 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - ######################################################## # # Simple test of promise references # ######################################################## - body common control - { - bundlesequence => { "example" }; - - version => "1.2.3"; + bundlesequence => { "example" }; + version => "1.2.3"; } - ######################################################## - bundle agent example - { vars: - classes: - files: - - "/home/mark/tmp/testcopy" - - copy_from => mycopy("/home/mark/LapTop/words","127.0.0.1"), - perms => system, + "/home/mark/tmp/testcopy" + copy_from => mycopy("/home/mark/LapTop/words", "127.0.0.1"), + perms => system, depth_search => recurse("inf"); - } - ######################################################### - body perms system - { - mode => "0644"; + mode => "0644"; } - ######################################################### - body depth_search recurse(d) - { - depth => "$(d)"; + depth => "$(d)"; } - ######################################################### - -body copy_from mycopy(from,server) - +body copy_from mycopy(from, server) { - source => "$(from)"; - servers => { "$(server)" }; - copy_backup => "true"; #/false/timestamp - purge => "false"; - type_check => "true"; - force_ipv4 => "true"; + source => "$(from)"; + servers => { "$(server)" }; + copy_backup => "true"; + #/false/timestamp + purge => "false"; + type_check => "true"; + force_ipv4 => "true"; } - ######################################################### # Server config ######################################################### - -body server control - +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 server access_rules() - { access: - - "/home/mark/LapTop" - - handle => "update_rule", - admit => { "127.0.0.1" }; + "/home/mark/LapTop" + handle => "update_rule", + admit => { "127.0.0.1" }; } diff --git a/examples/inform.cf b/examples/inform.cf index f47d69830a..f63cfb29ff 100644 --- a/examples/inform.cf +++ b/examples/inform.cf @@ -4,13 +4,14 @@ # etc. Since commands promises CAN modify the system, they create INFO # messages by default. However, not all commands promises do change the # system, so we let the policy writer customize this. - bundle agent main { commands: - "/bin/touch /tmp/module_cache" - inform => "true"; # Default + "/bin/touch /tmp/module_cache" inform => "true"; + + # Default "/bin/cat /tmp/module_cache" - inform => "false", # Read-only promise, no INFO logging wanted + inform => "false", + # Read-only promise, no INFO logging wanted module => "true"; } diff --git a/examples/inherit.cf b/examples/inherit.cf index a2127d583f..04909cb635 100644 --- a/examples/inherit.cf +++ b/examples/inherit.cf @@ -1,98 +1,71 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - ###################################################################### # # Inheritance of classes # ###################################################################### - body common control - { - version => "1.2.3"; - bundlesequence => { "parent" }; + version => "1.2.3"; + bundlesequence => { "parent" }; } - ######################################################## - bundle agent parent - { classes: - - "parent_private" expression => "any"; + "parent_private" expression => "any"; methods: - - "any" usebundle => child, + "any" + usebundle => child, inherit => "true"; files: - - "/tmp/bla" - + "/tmp/bla" create => "true", edit_line => edit_child, edit_defaults => inherit_all; - } - ######################################################## - bundle agent child - { reports: - parent_private:: - "Parent class is inherited"; !parent_private:: - "Parent class is not inherited"; - } -# - bundle edit_line edit_child { reports: - parent_private:: - "Parent editclass is inherited"; !parent_private:: - "Parent editclass is not inherited"; - } -# - body edit_defaults inherit_all { - inherit => "true"; + inherit => "true"; } diff --git a/examples/inherit_from.cf b/examples/inherit_from.cf index 2882b7189a..86f490dd6d 100644 --- a/examples/inherit_from.cf +++ b/examples/inherit_from.cf @@ -5,31 +5,30 @@ bundle agent __main__ { files: - "$(this.promise_filename).txt" - content => "Hello World$(const.n)2$(const.n)3$(const.n)4$(const.n)half-way + "$(this.promise_filename).txt" + content => "Hello World$(const.n)2$(const.n)3$(const.n)4$(const.n)half-way 6$(const.n)7$(const.n)8$(const.n)9$(const.n)Byeeeeeee", - create => "true"; + create => "true"; reports: - "The first 3 lines of this file are:" - printfile => head_n( "$(this.promise_filename).txt", "3" ); + "The first 3 lines of this file are:" + printfile => head_n("$(this.promise_filename).txt", "3"); - "The whole file contains:" - printfile => cat( "$(this.promise_filename).txt" ); + "The whole file contains:" printfile => cat("$(this.promise_filename).txt"); } body printfile head_n(file, lines) { - # Sets file_to_print the same as cat - inherit_from => cat( $(file) ); - - # Overrides number_of_lines from cat - number_of_lines => "$(lines)"; + # Sets file_to_print the same as cat + inherit_from => cat($(file)); + # Overrides number_of_lines from cat + number_of_lines => "$(lines)"; } + body printfile cat(file) { - file_to_print => "$(file)"; - number_of_lines => "inf"; + file_to_print => "$(file)"; + number_of_lines => "inf"; } ############################################################################### #+begin_src example_output @@ -51,5 +50,3 @@ body printfile cat(file) #@ R: Byeeeeeee #@ ``` #+end_src - - diff --git a/examples/inherit_from_classes.cf b/examples/inherit_from_classes.cf index 5e1debb83c..81532a6fb3 100644 --- a/examples/inherit_from_classes.cf +++ b/examples/inherit_from_classes.cf @@ -5,39 +5,43 @@ bundle agent __main__ { commands: - "/bin/true" - handle => "some meaningful string", - classes => my_set_some_extra_fancy_classes( "$(this.promiser)", - "$(this.handle)", - "some_class_to_handle_dependencies" ); + "/bin/true" + handle => "some meaningful string", + classes => my_set_some_extra_fancy_classes( + "$(this.promiser)", + "$(this.handle)", + "some_class_to_handle_dependencies" + ); - "/bin/false" - handle => "some meaningless string", - classes => my_set_some_extra_fancy_classes( "$(this.promiser)", - "$(this.handle)", - "some_class_to_handle_dependencies" ); + "/bin/false" + handle => "some meaningless string", + classes => my_set_some_extra_fancy_classes( + "$(this.promiser)", + "$(this.handle)", + "some_class_to_handle_dependencies" + ); reports: - "Defined classes:$(const.n)$(with)" - with => join( "$(const.n)", sort( classesmatching( "some_.*"), "lex" )); + "Defined classes:$(const.n)$(with)" + with => join("$(const.n)", sort(classesmatching("some_.*"), "lex")); } body classes my_set_some_extra_fancy_classes(x, y, z) # @brief In addition to the classes set by `set_some_fancy_classes` define `z` when the promise is repaired { - inherit_from => set_some_fancy_classes( $(x), $(y) ); - promise_repaired => { "some_fancy_class_${x}_${y}_repaired", $(z) }; + inherit_from => set_some_fancy_classes($(x), $(y)); + promise_repaired => { "some_fancy_class_${x}_${y}_repaired", $(z) }; } body classes set_some_fancy_classes(x, y) # @brief Define a class prefixed with `some_fancy_class_` followed by expansion # of `x`_`y` and suffixed with the promise outcome for each promise outcome. { - promise_kept => { "some_fancy_class_${x}_${y}_kept" }; - promise_repaired => { "some_fancy_class_${x}_${y}_repaired" }; - repair_failed => { "some_fancy_class_${x}_${y}_notkept" }; - repair_denied => { "some_fancy_class_${x}_${y}_notkept" }; - repair_timeout => { "some_fancy_class_${x}_${y}_notkept" }; + promise_kept => { "some_fancy_class_${x}_${y}_kept" }; + promise_repaired => { "some_fancy_class_${x}_${y}_repaired" }; + repair_failed => { "some_fancy_class_${x}_${y}_notkept" }; + repair_denied => { "some_fancy_class_${x}_${y}_notkept" }; + repair_timeout => { "some_fancy_class_${x}_${y}_notkept" }; } #+end_src ############################################################################### diff --git a/examples/inline-json.cf b/examples/inline-json.cf index 0d633592be..4224c193fe 100644 --- a/examples/inline-json.cf +++ b/examples/inline-json.cf @@ -3,7 +3,8 @@ bundle agent example_inline_json # @brief Example illustrating inline json { vars: - "json_multi_line" data => '{ + "json_multi_line" + data => '{ "CFEngine Champions": [ { "Name": "Aleksey Tsalolikhin", @@ -16,20 +17,20 @@ bundle agent example_inline_json ] }'; - - "json_single_line" data => '[{"key1":"value1"},{"key2":"value2"}]'; + "json_single_line" data => '[{"key1":"value1"},{"key2":"value2"}]'; reports: - "Data container defined from json_multi_line: $(with)" - with => storejson( @(json_multi_line) ); + "Data container defined from json_multi_line: $(with)" + with => storejson(@(json_multi_line)); - "Data container defined from json_single_line: $(with)" - with => storejson( @(json_single_line) ); + "Data container defined from json_single_line: $(with)" + with => storejson(@(json_single_line)); } + bundle agent __main__ { methods: - "example_inline_json"; + "example_inline_json"; } #+end_src ############################################################################### diff --git a/examples/inline-yaml.cf b/examples/inline-yaml.cf index 231b3fe890..19a211defd 100644 --- a/examples/inline-yaml.cf +++ b/examples/inline-yaml.cf @@ -3,30 +3,31 @@ bundle agent example_inline_yaml # @brief Example illustrating inline yaml { vars: - # YAML requires "---" header (followed by newline) - # NOTE \n is not interpreted as a newline, instead use $(const.n) - - "yaml_multi_line" data => '--- + # YAML requires "---" header (followed by newline) + # NOTE \n is not interpreted as a newline, instead use $(const.n) + "yaml_multi_line" + data => '--- - "CFEngine Champions": - Name: "Aleksey Tsalolikhin" Year: 2011 - Name: "Ted Zlatanov" Year : 2013'; - - "yaml_single_line" data => '---$(const.n)- key1: value1$(const.n)- key2: value2'; + "yaml_single_line" + data => '---$(const.n)- key1: value1$(const.n)- key2: value2'; reports: - "Data container defined from yaml_multi_line: $(with)" - with => storejson( @(yaml_multi_line) ); + "Data container defined from yaml_multi_line: $(with)" + with => storejson(@(yaml_multi_line)); - "Data container defined from yaml_single_line: $(with)" - with => storejson( @(yaml_single_line) ); + "Data container defined from yaml_single_line: $(with)" + with => storejson(@(yaml_single_line)); } + bundle agent __main__ { methods: - "example_inline_yaml"; + "example_inline_yaml"; } #+end_src ############################################################################### diff --git a/examples/insert_users.cf b/examples/insert_users.cf index 99433fc759..676c904796 100644 --- a/examples/insert_users.cf +++ b/examples/insert_users.cf @@ -1,25 +1,22 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - ######################################################## # # Insert users into the passwd file of a system by @@ -27,108 +24,68 @@ # for /etc/shadow # ######################################################## - body common control - { - bundlesequence => { "updateusers" }; + bundlesequence => { "updateusers" }; } - ######################################################## - bundle agent updateusers - { vars: - - # Set $(testing) to "" for production - - "testing" string => "/home/mark/tmp"; - "tmp" string => "$(testing)/etc/passwd_tmp"; - - "extract_users" slist => { "mark", "root", "at", "www-run" }; + # Set $(testing) to "" for production + "testing" string => "/home/mark/tmp"; + "tmp" string => "$(testing)/etc/passwd_tmp"; + "extract_users" slist => { "mark", "root", "at", "www-run" }; files: + # Take the passwed entries from source and add them to real_passwd + "$(tmp)" + create => "true", + edit_line => SelectUsers( + "$(testing)/masterfiles/passwd", "@(this.extract_users)" + ); - # - # Take the passwed entries from source and add them to real_passwd - # - - "$(tmp)" - - create => "true", - edit_line => SelectUsers("$(testing)/masterfiles/passwd","@(this.extract_users)"); - - # - # Intermediate file - should be secure - not in /tmp - # - - "$(testing)/etc/passwd" - - edit_line => ReplaceUsers("$(tmp)","@(this.extract_users)"); - - # - - "$(testing)/home/$(extract_users)/." + # Intermediate file - should be secure - not in /tmp + "$(testing)/etc/passwd" + edit_line => ReplaceUsers("$(tmp)", "@(this.extract_users)"); + "$(testing)/home/$(extract_users)/." create => "true", perms => userdir("$(extract_users)"); } - - - - - - ######################################################## # Library stuff ######################################################## - body perms userdir(u) { - mode => "755"; - owners => { "$(u)" }; - groups => { "users" }; + mode => "755"; + owners => { "$(u)" }; + groups => { "users" }; } - ######################################################## - -bundle edit_line SelectUsers(f,l) +bundle edit_line SelectUsers(f, l) { insert_lines: - - "$(f)" - + "$(f)" insert_type => "file", insert_select => keep("@(l)"); } - ######################################################## - -bundle edit_line ReplaceUsers(f,l) +bundle edit_line ReplaceUsers(f, l) { delete_lines: - - "$(f)" - delete_select => discard("@(l)"); + "$(f)" delete_select => discard("@(l)"); insert_lines: - - "$(f)" - - insert_type => "file"; + "$(f)" insert_type => "file"; } - ######################################################## - body insert_select keep(s) { - insert_if_startwith_from_list => { @(s) }; + insert_if_startwith_from_list => { @(s) }; } - ######################################################## - body delete_select discard(s) { - delete_if_not_startwith_from_list => { @(s) }; + delete_if_not_startwith_from_list => { @(s) }; } diff --git a/examples/int.cf b/examples/int.cf index ef372dc62b..3e601e631d 100644 --- a/examples/int.cf +++ b/examples/int.cf @@ -2,18 +2,18 @@ bundle agent main { vars: - "data" data => '{"acft_name": "A320neo", + "data" + data => '{"acft_name": "A320neo", "engine_num": "2", "price_in_USD": "123.456789k"}'; - "engines" int => int("$(data[engine_num])"); - "ballpark_price" int => int("$(data[price_in_USD])"); + "engines" int => int("$(data[engine_num])"); + "ballpark_price" int => int("$(data[price_in_USD])"); reports: - "A320neo has $(engines) engines and costs about $(ballpark_price) USD."; + "A320neo has $(engines) engines and costs about $(ballpark_price) USD."; } #+end_src - #+begin_src example_output #@ ``` #@ R: A320neo has 2 engines and costs about 123456 USD. diff --git a/examples/intarray.cf b/examples/intarray.cf index 7dd0dc25e6..86ac70fc42 100644 --- a/examples/intarray.cf +++ b/examples/intarray.cf @@ -1,43 +1,32 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - - body common control - { - bundlesequence => { "example" }; + bundlesequence => { "example" }; } - ########################################################### - bundle agent example - -{ +{ vars: - - "dim_array" - - int => readstringarray("array_name","/tmp/array","#[^\n]*",":",10,4000); - - + "dim_array" + int => readstringarray( + "array_name", "/tmp/array", "#[^\n]*", ":", 10, 4000 + ); } - diff --git a/examples/intersection.cf b/examples/intersection.cf index ece7c2e99b..b501166808 100644 --- a/examples/intersection.cf +++ b/examples/intersection.cf @@ -1,46 +1,43 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - #+begin_src cfengine3 body common control { - bundlesequence => { "test" }; + bundlesequence => { "test" }; } bundle agent test { vars: - "a" slist => { 1,2,3,"x" }; - "b" slist => { "x" }; - - "mylist1" slist => { "a", "b" }; - "mylist2" slist => { "a", "b" }; - "$(mylist1)_str" string => join(",", $(mylist1)); + "a" slist => { 1, 2, 3, "x" }; + "b" slist => { "x" }; + "mylist1" slist => { "a", "b" }; + "mylist2" slist => { "a", "b" }; + "$(mylist1)_str" string => join(",", $(mylist1)); + "int_$(mylist1)_$(mylist2)" slist => intersection($(mylist1), $(mylist2)); - "int_$(mylist1)_$(mylist2)" slist => intersection($(mylist1), $(mylist2)); - "int_$(mylist1)_$(mylist2)_str" string => join(",", "int_$(mylist1)_$(mylist2)"); + "int_$(mylist1)_$(mylist2)_str" + string => join(",", "int_$(mylist1)_$(mylist2)"); reports: - "The intersection of list '$($(mylist1)_str)' with '$($(mylist2)_str)' is '$(int_$(mylist1)_$(mylist2)_str)'"; + "The intersection of list '$($(mylist1)_str)' with '$($(mylist2)_str)' is '$(int_$(mylist1)_$(mylist2)_str)'"; } #+end_src ############################################################################### diff --git a/examples/inventory_cpu.cf b/examples/inventory_cpu.cf index 8734152f56..970f113aba 100644 --- a/examples/inventory_cpu.cf +++ b/examples/inventory_cpu.cf @@ -1,28 +1,26 @@ # Demo on how to extract the first "model name" field from /proc/cpuinfo # into a variable. # Can be used for inventory information in CFEngine Nova and above. - body common control { - bundlesequence => { "inventory" }; + bundlesequence => { "inventory" }; } - ### - bundle common inventory { vars: - "cpuinfo" string => execresult("/bin/grep \"model name\" /proc/cpuinfo", "noshell"); - + "cpuinfo" + string => execresult( + "/bin/grep \"model name\" /proc/cpuinfo", "noshell" + ); + got_model_name:: - "cpu" string => "$(myarray[1])"; + "cpu" string => "$(myarray[1])"; classes: - - "got_model_name" expression => regextract( - "model\s+name\s+:\s+([^\n]*)\n?.*", - "$(cpuinfo)", - "myarray" + "got_model_name" + expression => regextract( + "model\s+name\s+:\s+([^\n]*)\n?.*", "$(cpuinfo)", "myarray" ); reports: @@ -32,4 +30,3 @@ bundle common inventory !got_model_name:: "Did not match CPU model name"; } - diff --git a/examples/ip2host.cf b/examples/ip2host.cf index 414b7528eb..b81da60ad4 100644 --- a/examples/ip2host.cf +++ b/examples/ip2host.cf @@ -1,38 +1,35 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - #+begin_src cfengine3 body common control { - bundlesequence => { "reverse_lookup" }; + bundlesequence => { "reverse_lookup" }; } bundle agent reverse_lookup { vars: - "local4" string => ip2host("127.0.0.1"); + "local4" string => ip2host("127.0.0.1"); - # this will be localhost on some systems, ip6-localhost on others... - "local6" string => ip2host("::1"); + # this will be localhost on some systems, ip6-localhost on others... + "local6" string => ip2host("::1"); reports: _cfe_output_testing:: diff --git a/examples/iprange.cf b/examples/iprange.cf index d08f697ec2..554f599449 100644 --- a/examples/iprange.cf +++ b/examples/iprange.cf @@ -1,50 +1,37 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - - body common control - { - bundlesequence => { "example" }; + bundlesequence => { "example" }; } - ########################################################### - bundle agent example - -{ +{ classes: - - "adhoc_group_1" expression => iprange("192.168.1.50-140"); - "adhoc_group_2" expression => iprange("192.168.1.0/24"); + "adhoc_group_1" expression => iprange("192.168.1.50-140"); + "adhoc_group_2" expression => iprange("192.168.1.0/24"); reports: - adhoc_group_1:: - "Some numerology"; adhoc_group_2:: - "The masked warriors"; } - diff --git a/examples/irange.cf b/examples/irange.cf index ec8c32b904..82ebb3711e 100644 --- a/examples/irange.cf +++ b/examples/irange.cf @@ -1,59 +1,53 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - body common control { - bundlesequence => { "cleanup" }; + bundlesequence => { "cleanup" }; } bundle agent cleanup { files: - # This will not delete the parent - - "/home/mark/tmp/testcopy" + # This will not delete the parent + "/home/mark/tmp/testcopy" delete => tidyfiles, file_select => changed_within_1_year, depth_search => recurse; - #Now delete the parent. - - "/home/mark/tmp/testcopy" - delete => tidyfiles; + #Now delete the parent. + "/home/mark/tmp/testcopy" delete => tidyfiles; } body delete tidyfiles { - dirlinks => "delete"; - rmdirs => "true"; + dirlinks => "delete"; + rmdirs => "true"; } body file_select changed_within_1_year { - 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 depth_search recurse { - depth => "inf"; + depth => "inf"; } diff --git a/examples/is_type.cf b/examples/is_type.cf index 8e6d39830d..1abbbac3b7 100644 --- a/examples/is_type.cf +++ b/examples/is_type.cf @@ -7,32 +7,28 @@ body common control bundle agent example { vars: - "foo" - data => '{ "bar": true }'; - "a" - string => "hello"; + "foo" data => '{ "bar": true }'; + "a" string => "hello"; classes: - "isdata" - expression => is_type("foo", "data"); - "isdata_boolean" - expression => is_type("foo[bar]", "data boolean"); - "isstring" - expression => is_type("a", "string"); - "isint" - expression => is_type("a", "int"); + "isdata" expression => is_type("foo", "data"); + "isdata_boolean" expression => is_type("foo[bar]", "data boolean"); + "isstring" expression => is_type("a", "string"); + "isint" expression => is_type("a", "int"); reports: isdata:: - "'foo' is of type 'data'"; + "'foo' is of type 'data'"; + isdata_boolean:: - "'foo[bar]' is of type 'data boolean'"; + "'foo[bar]' is of type 'data boolean'"; + isstring:: - "'a' is of type 'string'"; + "'a' is of type 'string'"; + isint:: - "'a' is of type 'int'"; + "'a' is of type 'int'"; } - #+end_src ############################################################################# #+begin_src example_output diff --git a/examples/isconnectable.cf b/examples/isconnectable.cf index c6a04eb0c0..8c9be63df2 100644 --- a/examples/isconnectable.cf +++ b/examples/isconnectable.cf @@ -6,12 +6,12 @@ body common control bundle agent example { classes: - "isconnectable" - expression => isconnectable("localhost", 22, "30"); + "isconnectable" expression => isconnectable("localhost", 22, "30"); reports: isconnectable:: "Port is connectable"; + !isconnectable:: "Port is not connectable"; } diff --git a/examples/isdir.cf b/examples/isdir.cf index db3ec14bf4..8d466002f6 100644 --- a/examples/isdir.cf +++ b/examples/isdir.cf @@ -1,43 +1,36 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - #+begin_src cfengine3 body common control { - bundlesequence => { "example" }; + bundlesequence => { "example" }; } bundle agent example { classes: - - "isdir" expression => isdir("/"); + "isdir" expression => isdir("/"); reports: - isdir:: - "Directory exists.."; - } #+end_src ############################################################################### diff --git a/examples/isexecutable.cf b/examples/isexecutable.cf index ff06e24368..bc870d83d6 100644 --- a/examples/isexecutable.cf +++ b/examples/isexecutable.cf @@ -1,36 +1,33 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - #+begin_src cfengine3 body common control { - bundlesequence => { "example" }; + bundlesequence => { "example" }; } bundle agent example { classes: + "yes" expression => isexecutable("/bin/ls"); - "yes" expression => isexecutable("/bin/ls"); reports: yes:: "/bin/ls is an executable file"; diff --git a/examples/isgreaterthan.cf b/examples/isgreaterthan.cf index c34c3df627..8923e6e8f7 100644 --- a/examples/isgreaterthan.cf +++ b/examples/isgreaterthan.cf @@ -1,47 +1,39 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - #+begin_src cfengine3 body common control { - bundlesequence => { "example" }; + bundlesequence => { "example" }; } bundle agent example { classes: - - "ok" expression => isgreaterthan("1","0"); + "ok" expression => isgreaterthan("1", "0"); reports: - ok:: - "Assertion is true"; !ok:: - "Assertion is false"; - } #+end_src ############################################################################### diff --git a/examples/isipinsubnet.cf b/examples/isipinsubnet.cf index e3cbd34208..d26ccc69f6 100644 --- a/examples/isipinsubnet.cf +++ b/examples/isipinsubnet.cf @@ -1,42 +1,37 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - ############################################################################### #+begin_src cfengine3 bundle agent main { classes: - - "in_192" expression => isipinsubnet("192.0.0.0/8", "192.1.2.3"); - "in_192_2_2_2" expression => isipinsubnet("192.2.2.0/24", "192.1.2.3"); + "in_192" expression => isipinsubnet("192.0.0.0/8", "192.1.2.3"); + "in_192_2_2_2" expression => isipinsubnet("192.2.2.0/24", "192.1.2.3"); reports: - in_192:: "The address 192.1.2.3 is in the 192/8 subnet"; + !in_192_2_2_2:: "The address 192.1.2.3 is not in the 192.2.2/24 subnet"; } - #+end_src ############################################################################### #+begin_src example_output diff --git a/examples/islessthan.cf b/examples/islessthan.cf index aaddd9892e..f1cd6f14b3 100644 --- a/examples/islessthan.cf +++ b/examples/islessthan.cf @@ -1,47 +1,39 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - #+begin_src cfengine3 body common control { - bundlesequence => { "test" }; + bundlesequence => { "test" }; } bundle agent test { classes: - - "ok" expression => islessthan("0","1"); + "ok" expression => islessthan("0", "1"); reports: - ok:: - "Assertion is true"; !ok:: - "Assertion is false"; - } #+end_src ############################################################################### diff --git a/examples/islink.cf b/examples/islink.cf index 52a12dba40..7926a3f517 100644 --- a/examples/islink.cf +++ b/examples/islink.cf @@ -1,25 +1,22 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - #+begin_src prep #@ ``` #@ ln -fs /tmp/cfe_testhere.txt /tmp/link @@ -29,21 +26,17 @@ #+begin_src cfengine3 body common control { - bundlesequence => { "example" }; + bundlesequence => { "example" }; } bundle agent example { classes: - - "islink" expression => islink("/tmp/link"); + "islink" expression => islink("/tmp/link"); reports: - islink:: - "It's a link."; - } #+end_src ############################################################################### diff --git a/examples/isnewerthan.cf b/examples/isnewerthan.cf index bb928c9d2c..8bf60f1b21 100644 --- a/examples/isnewerthan.cf +++ b/examples/isnewerthan.cf @@ -1,25 +1,22 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - #+begin_src prep #@ ``` #@ touch -t '200102031234.56' /tmp/earlier @@ -30,19 +27,16 @@ #+begin_src cfengine3 body common control { - bundlesequence => { "example" }; + bundlesequence => { "example" }; } bundle agent example { classes: - - "do_it" expression => isnewerthan("/tmp/later","/tmp/earlier"); + "do_it" expression => isnewerthan("/tmp/later", "/tmp/earlier"); reports: - do_it:: - "/tmp/later is older than /tmp/earlier"; } #+end_src diff --git a/examples/isnewerthantime.cf b/examples/isnewerthantime.cf index 514159c762..a0a041cc8a 100644 --- a/examples/isnewerthantime.cf +++ b/examples/isnewerthantime.cf @@ -20,6 +20,7 @@ bundle agent example reports: !is_file_a_new:: "/tmp/file_a is not newer than 2001-09-09 01:46:40"; + is_file_b_new:: "/tmp/file_b is newer than 2001-09-09 01:46:40"; } diff --git a/examples/isplain.cf b/examples/isplain.cf index a97f92742d..b860731d9f 100644 --- a/examples/isplain.cf +++ b/examples/isplain.cf @@ -1,46 +1,40 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - #+begin_src cfengine3 body common control { - bundlesequence => { "example" }; + bundlesequence => { "example" }; } bundle agent example { classes: - - "fileisplain" expression => isplain("/etc/passwd"); - "dirisnotplain" not => isplain("/"); + "fileisplain" expression => isplain("/etc/passwd"); + "dirisnotplain" not => isplain("/"); reports: - fileisplain:: "/etc/passwd is plain.."; dirisnotplain:: "/ is not plain.."; - } #+end_src ############################################################################### diff --git a/examples/isreadable.cf b/examples/isreadable.cf index 25fc7d7832..8a20d36f0c 100644 --- a/examples/isreadable.cf +++ b/examples/isreadable.cf @@ -8,13 +8,12 @@ bundle agent __main__ { vars: - "filename" - string => "/tmp/foo.txt"; - "timeout" - int => "3"; + "filename" string => "/tmp/foo.txt"; + "timeout" int => "3"; + reports: - "File '$(filename)' is readable" - if => isreadable("$(filename)", "$(timeout)"); + "File '$(filename)' is readable" + if => isreadable("$(filename)", "$(timeout)"); } #+end_src ############################################################################### diff --git a/examples/isvariable.cf b/examples/isvariable.cf index af7acc36b8..08f3c95f55 100644 --- a/examples/isvariable.cf +++ b/examples/isvariable.cf @@ -1,47 +1,39 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - #+begin_src cfengine3 body common control { - bundlesequence => { "example" }; + bundlesequence => { "example" }; } bundle agent example { vars: - - "bla" string => "xyz.."; + "bla" string => "xyz.."; classes: - - "exists" expression => isvariable("bla"); + "exists" expression => isvariable("bla"); reports: - exists:: - "Variable exists: \"$(bla)\".."; - } #+end_src ############################################################################### diff --git a/examples/iteration.cf b/examples/iteration.cf index ecc1e11b6a..3ecf7bbd5e 100644 --- a/examples/iteration.cf +++ b/examples/iteration.cf @@ -1,45 +1,36 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - # # Nested iteration -# - body common control { - bundlesequence => {"x"}; + bundlesequence => { "x" }; } bundle agent x { vars: - - "list1" slist => { "a", "b", "c" }; - - "list2" slist => { "1", "2", "3", "4" }; - - "list3" slist => { "x", "y", "z" }; + "list1" slist => { "a", "b", "c" }; + "list2" slist => { "1", "2", "3", "4" }; + "list3" slist => { "x", "y", "z" }; reports: - "Hello $(list1) $(list2) $(list3)"; + "Hello $(list1) $(list2) $(list3)"; } - diff --git a/examples/join.cf b/examples/join.cf index 310c081041..1790942737 100644 --- a/examples/join.cf +++ b/examples/join.cf @@ -1,50 +1,50 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - #+begin_src cfengine3 body common control { - bundlesequence => { "test" }; + bundlesequence => { "test" }; } bundle agent test { vars: + "mylist" slist => { "one", "two", "three", "four", "five" }; - "mylist" slist => { "one", "two", "three", "four", "five" }; - "datalist" data => parsejson('[1,2,3, + "datalist" + data => parsejson( + '[1,2,3, "one", "two", "three", "long string", "four", "fix", "six", - "one", "two", "three",]'); + "one", "two", "three",]' + ); - "mylist_str" string => format("%S", mylist); - "datalist_str" string => format("%S", datalist); - "myscalar" string => join("->", mylist); - "datascalar" string => join("->", datalist); + "mylist_str" string => format("%S", mylist); + "datalist_str" string => format("%S", datalist); + "myscalar" string => join("->", mylist); + "datascalar" string => join("->", datalist); reports: - "Concatenated $(mylist_str): $(myscalar)"; - "Concatenated $(datalist_str): $(datascalar)"; + "Concatenated $(mylist_str): $(myscalar)"; + "Concatenated $(datalist_str): $(datascalar)"; } #+end_src ############################################################################### diff --git a/examples/kill_process_running_wrong_user.cf b/examples/kill_process_running_wrong_user.cf index 2e2d3c1e13..b3a41ce6e0 100644 --- a/examples/kill_process_running_wrong_user.cf +++ b/examples/kill_process_running_wrong_user.cf @@ -1,37 +1,32 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - #+begin_src cfengine3 bundle agent main { - processes: - - # Any /usr/local/web/tomcat-logviewer processes not - # running as buildsrv should be killed on sight. - - "/usr/local/web/tomcat-logviewer" -> { "security" } - process_select => not_running_as("buildsrv"), - signals => { "kill" }, - comment => "It is against the security policy for this + processes: + # Any /usr/local/web/tomcat-logviewer processes not + # running as buildsrv should be killed on sight. + "/usr/local/web/tomcat-logviewer" -> { "security" } + process_select => not_running_as("buildsrv"), + signals => { "kill" }, + comment => "It is against the security policy for this service to run under the wrong user id."; } diff --git a/examples/lastnode.cf b/examples/lastnode.cf index ab2567f598..815a2c94fd 100644 --- a/examples/lastnode.cf +++ b/examples/lastnode.cf @@ -1,51 +1,44 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - #+begin_src cfengine3 body common control { - bundlesequence => { "yes" }; + bundlesequence => { "yes" }; } bundle agent yes { vars: - - "path1" string => "/one/two/last1"; - "path2" string => "one:two:last2"; - "path4" string => "/one/two/"; - - "last1" string => lastnode("$(path1)","/"); - "last2" string => lastnode("$(path2)",":"); - - "last3" string => lastnode("$(path2)","/"); - "last4" string => lastnode("$(path4)","/"); + "path1" string => "/one/two/last1"; + "path2" string => "one:two:last2"; + "path4" string => "/one/two/"; + "last1" string => lastnode("$(path1)", "/"); + "last2" string => lastnode("$(path2)", ":"); + "last3" string => lastnode("$(path2)", "/"); + "last4" string => lastnode("$(path4)", "/"); reports: - "Last / node in / path '$(path1)' = '$(last1)'"; - "Last : node in : path '$(path2)' = '$(last2)'"; - "Last / node in : path '$(path2)' = '$(last3)'"; - "Last / node in /-terminated path '$(path4)' = '$(last4)'"; - + "Last / node in / path '$(path1)' = '$(last1)'"; + "Last : node in : path '$(path2)' = '$(last2)'"; + "Last / node in : path '$(path2)' = '$(last3)'"; + "Last / node in /-terminated path '$(path4)' = '$(last4)'"; } #+end_src ############################################################################### diff --git a/examples/ldap.cf b/examples/ldap.cf index 06df601cd6..a3b7814e99 100644 --- a/examples/ldap.cf +++ b/examples/ldap.cf @@ -1,77 +1,91 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - - -# - body common control { - bundlesequence => { "ldap" , "followup"}; + bundlesequence => { "ldap", "followup" }; } - ################################################################################################### # NOTE!! relying on LDAP or other network data without validation is EXTREMELY dangerous. # You could destroy a system by assuming that the service will respond with a # sensible result. Cfengine does not recommend reliance on network services in configuration. ################################################################################################### - bundle agent ldap { vars: - - # Get the first matching value for "uid" - - "value" string => ldapvalue("ldap://eternity.iu.hio.no","dc=cfengine,dc=com","(sn=User)","uid","subtree","none"); - - # Geta all matching values for "uid" - should be a single record match - - "list" slist => ldaplist("ldap://eternity.iu.hio.no","dc=cfengine,dc=com","(sn=User)","uid","subtree","none"); + # Get the first matching value for "uid" + "value" + string => ldapvalue( + "ldap://eternity.iu.hio.no", + "dc=cfengine,dc=com", + "(sn=User)", + "uid", + "subtree", + "none" + ); + + # Geta all matching values for "uid" - should be a single record match + "list" + slist => ldaplist( + "ldap://eternity.iu.hio.no", + "dc=cfengine,dc=com", + "(sn=User)", + "uid", + "subtree", + "none" + ); classes: - - "gotdata" expression => ldaparray("myarray","ldap://eternity.iu.hio.no","dc=cfengine,dc=com","(uid=mark)","subtree","none"); - - "found" expression => regldap("ldap://eternity.iu.hio.no","dc=cfengine,dc=com","(sn=User)","uid","subtree","jon.*","none"); + "gotdata" + expression => ldaparray( + "myarray", + "ldap://eternity.iu.hio.no", + "dc=cfengine,dc=com", + "(uid=mark)", + "subtree", + "none" + ); + + "found" + expression => regldap( + "ldap://eternity.iu.hio.no", + "dc=cfengine,dc=com", + "(sn=User)", + "uid", + "subtree", + "jon.*", + "none" + ); reports: - - "LDAP VALUE $(value) found"; - "LDAP LIST VALUE $(list)"; + "LDAP VALUE $(value) found"; + "LDAP LIST VALUE $(list)"; gotdata:: - "Found specific entry data ...$(ldap.myarray[uid]),$(ldap.myarray[gecos]), etc"; found:: - "Matched regex"; - } bundle agent followup - { reports: - - "Different bundle ...$(ldap.myarray[uid]),$(ldap.myarray[gecos]), etc"; - + "Different bundle ...$(ldap.myarray[uid]),$(ldap.myarray[gecos]), etc"; } diff --git a/examples/length.cf b/examples/length.cf index 61f0a6ef30..718676ca3b 100644 --- a/examples/length.cf +++ b/examples/length.cf @@ -1,49 +1,54 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - #+begin_src cfengine3 body common control { - bundlesequence => { "test" }; + bundlesequence => { "test" }; } bundle agent test - { vars: - "test" slist => { - 1,2,3, - "one", "two", "three", - "long string", - "four", "fix", "six", - "one", "two", "three", + "test" + slist => { + 1, + 2, + 3, + "one", + "two", + "three", + "long string", + "four", + "fix", + "six", + "one", + "two", + "three", }; - "length" int => length("test"); - "test_str" string => join(",", "test"); + "length" int => length("test"); + "test_str" string => join(",", "test"); reports: - "The test list is $(test_str)"; - "The test list has $(length) elements"; + "The test list is $(test_str)"; + "The test list has $(length) elements"; } #+end_src ############################################################################### diff --git a/examples/linking.cf b/examples/linking.cf index addcd7e1b1..d12ecfcf44 100644 --- a/examples/linking.cf +++ b/examples/linking.cf @@ -1,25 +1,22 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - ###################################################################### # # File editing @@ -30,57 +27,39 @@ # - insert # ###################################################################### - - body common control - { - version => "1.2.3"; - bundlesequence => { "example" }; + version => "1.2.3"; + bundlesequence => { "example" }; } - ######################################################## - bundle agent example - { files: - - # Make a copy of the password file - - "/home/mark/tmp/passwd" - - link_from => linkdetails("/etc/passwd"), + # Make a copy of the password file + "/home/mark/tmp/passwd" + link_from => linkdetails("/etc/passwd"), move_obstructions => "true"; - - "/home/mark/tmp/linktest" - - link_from => linkchildren("/usr/local/sbin"); - - - #child links + "/home/mark/tmp/linktest" link_from => linkchildren("/usr/local/sbin"); + #child links } - ######################################################### - body link_from linkdetails(tofile) - { - source => "$(tofile)"; - link_type => "symlink"; - when_no_source => "force"; # kill + source => "$(tofile)"; + link_type => "symlink"; + when_no_source => "force"; + # kill } - ######################################################### - body link_from linkchildren(tofile) - { - source => "$(tofile)"; - link_type => "symlink"; - when_no_source => "force"; # kill - link_children => "true"; - when_linking_children => "if_no_such_file"; # "override_file"; + source => "$(tofile)"; + link_type => "symlink"; + when_no_source => "force"; + # kill + link_children => "true"; + when_linking_children => "if_no_such_file"; + # "override_file"; } - diff --git a/examples/literal_server.cf b/examples/literal_server.cf index e991f2df5e..b50ab7796f 100644 --- a/examples/literal_server.cf +++ b/examples/literal_server.cf @@ -1,31 +1,27 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - ######################################################## # # Remote value from server connection to cfServer # ######################################################## - # # run this as follows: # @@ -33,77 +29,57 @@ # cf-agent -f runtest_2.cf # # Notice that the same file configures all parts of cfengine - ######################################################## - body common control - { - bundlesequence => { "example" }; - - version => "1.2.3"; + bundlesequence => { "example" }; + version => "1.2.3"; } - ######################################################## - bundle agent example - { vars: + "encrypt" string => "yes"; + "x" string => "scalar2"; + "remote1" string => remotescalar("test_scalar1", "127.0.0.1", "$(encrypt)"); + "remote2" string => remotescalar("test_scalar2", "127.0.0.1", "$(encrypt)"); + "remote3" string => remotescalar("test_scalar3", "127.0.0.1", "$(encrypt)"); - "encrypt" string => "yes"; - - "x" string => "scalar2"; - "remote1" string => remotescalar("test_scalar1","127.0.0.1","$(encrypt)"); - "remote2" string => remotescalar("test_scalar2","127.0.0.1","$(encrypt)"); - "remote3" string => remotescalar("test_scalar3","127.0.0.1","$(encrypt)"); - "remote_error" string => remotescalar("test_$(x)","127.0.0.2","$(encrypt)"); + "remote_error" + string => remotescalar("test_$(x)", "127.0.0.2", "$(encrypt)"); reports: - - "Receive value $(remote1), $(remote2), $(remote3)"; - - "And an error gives: $(remote_error)"; + "Receive value $(remote1), $(remote2), $(remote3)"; + "And an error gives: $(remote_error)"; } - ######################################################### # Server config ######################################################### - -body server control - +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 access_rules() - { vars: - - "localvar" string => "literal string"; + "localvar" string => "literal string"; access: - - "Embed a $(localvar) for remote access" - - handle => "test_scalar1", + "Embed a $(localvar) for remote access" + handle => "test_scalar1", resource_type => "literal", - admit => { "127.0.0.1" }; - + admit => { "127.0.0.1" }; - "Mary had a little lamb whose fleece was white as snow and everywhere that Mary went she wore it lovingly" - - handle => "test_scalar2", + "Mary had a little lamb whose fleece was white as snow and everywhere that Mary went she wore it lovingly" + handle => "test_scalar2", resource_type => "literal", - admit => { "127.0.0.1" }; + admit => { "127.0.0.1" }; - "/etc/passwd" - handle => "test_scalar3", - admit => { "127.0.0.1" }; + "/etc/passwd" + handle => "test_scalar3", + admit => { "127.0.0.1" }; } diff --git a/examples/local_group_present.cf b/examples/local_group_present.cf index 4716797231..12b89cdd31 100644 --- a/examples/local_group_present.cf +++ b/examples/local_group_present.cf @@ -7,11 +7,9 @@ body file control bundle agent main { classes: - "group_cfengineers_absent" - not => groupexists("cfengineers"); + "group_cfengineers_absent" not => groupexists("cfengineers"); commands: linux.group_cfengineers_absent:: - "$(paths.groupadd)" - args => "cfengineers"; + "$(paths.groupadd)" args => "cfengineers"; } diff --git a/examples/local_user_password.cf b/examples/local_user_password.cf index 535c7cf915..c7b8494739 100644 --- a/examples/local_user_password.cf +++ b/examples/local_user_password.cf @@ -7,7 +7,7 @@ body file control bundle agent main { vars: - # This is the hashed password for 'vagrant' + # This is the hashed password for 'vagrant' debian_8:: "root_hash" string => "$6$1nRTeNoE$DpBSe.eDsuZaME0EydXBEf.DAwuzpSoIJhkhiIAPgRqVKlmI55EONfvjZorkxNQvK2VFfMm9txx93r2bma/4h/"; @@ -16,6 +16,6 @@ bundle agent main linux:: "root" policy => "present", - password => hashed_password( $(root_hash) ), + password => hashed_password($(root_hash)), if => isvariable("root_hash"); } diff --git a/examples/local_users_absent.cf b/examples/local_users_absent.cf index f6c8dc3c99..70e58ba709 100644 --- a/examples/local_users_absent.cf +++ b/examples/local_users_absent.cf @@ -5,6 +5,5 @@ bundle agent main users: linux:: - "$(users)" - policy => "absent"; + "$(users)" policy => "absent"; } diff --git a/examples/local_users_locked.cf b/examples/local_users_locked.cf index b3a6f30f1c..de22908b92 100644 --- a/examples/local_users_locked.cf +++ b/examples/local_users_locked.cf @@ -5,6 +5,5 @@ bundle agent main users: linux:: - "$(users)" - policy => "locked"; + "$(users)" policy => "locked"; } diff --git a/examples/local_users_present.cf b/examples/local_users_present.cf index 80ac180561..225a549e8b 100644 --- a/examples/local_users_present.cf +++ b/examples/local_users_present.cf @@ -15,7 +15,7 @@ bundle agent main "$(users)" home_dir => "/home/$(users)", policy => "present", - home_bundle => home_skel( $(users), $(skel) ); + home_bundle => home_skel($(users), $(skel)); } bundle agent home_skel(user, skel) @@ -26,6 +26,6 @@ bundle agent home_skel(user, skel) files: "/home/$(user)/." create => "true", - copy_from => seed_cp( $(skel) ), - depth_search => recurse( "inf" ); + copy_from => seed_cp($(skel)), + depth_search => recurse("inf"); } diff --git a/examples/locate_files_and_compress.cf b/examples/locate_files_and_compress.cf index 9d7935135d..8a2e7f3b9c 100644 --- a/examples/locate_files_and_compress.cf +++ b/examples/locate_files_and_compress.cf @@ -1,66 +1,48 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - ####################################################### # # Compressing files # ####################################################### - body common control - { - bundlesequence => { "example" }; + bundlesequence => { "example" }; } - ############################################ - bundle agent example - { files: - - "/home/mark/tmp/testcopy" - + "/home/mark/tmp/testcopy" file_select => pdf_files, transformer => "/usr/bin/gzip $(this.promiser)", depth_search => recurse("inf"); - } - ############################################ - body file_select pdf_files - { - leaf_name => { ".*.pdf" , ".*.fdf" }; - file_result => "leaf_name"; + leaf_name => { ".*.pdf", ".*.fdf" }; + file_result => "leaf_name"; } - ############################################ - body depth_search recurse(d) - { - depth => "$(d)"; + depth => "$(d)"; } - diff --git a/examples/log_private.cf b/examples/log_private.cf index a71937b67c..e1fe34ea77 100644 --- a/examples/log_private.cf +++ b/examples/log_private.cf @@ -1,52 +1,42 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - - body common control { - bundlesequence => { "example" }; + bundlesequence => { "example" }; } bundle agent example { vars: - - "software" slist => { "/root/xyz", "/tmp/xyz" }; + "software" slist => { "/root/xyz", "/tmp/xyz" }; files: - - "$(software)" - + "$(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"; } diff --git a/examples/loops.cf b/examples/loops.cf index e73cce22d1..595185e132 100644 --- a/examples/loops.cf +++ b/examples/loops.cf @@ -1,48 +1,35 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - - - 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"; + "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"; reports: - "/bin/echo $(component) is $(array[$(component)])"; - + "/bin/echo $(component) is $(array[$(component)])"; } - diff --git a/examples/lsdir.cf b/examples/lsdir.cf index 81f6a73941..6485f0aeb0 100644 --- a/examples/lsdir.cf +++ b/examples/lsdir.cf @@ -1,39 +1,36 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - #+begin_src cfengine3 body common control { - bundlesequence => { "example" }; + bundlesequence => { "example" }; } bundle agent example { vars: - "listfiles" slist => lsdir("/etc", "(p.sswd|gr[ou]+p)", "true"); - "sorted_listfiles" slist => sort(listfiles, "lex"); + "listfiles" slist => lsdir("/etc", "(p.sswd|gr[ou]+p)", "true"); + "sorted_listfiles" slist => sort(listfiles, "lex"); reports: - "files in list: $(sorted_listfiles)"; + "files in list: $(sorted_listfiles)"; } #+end_src ############################################################################### diff --git a/examples/main.cf b/examples/main.cf index d803c10c69..aa8a9b0e2e 100644 --- a/examples/main.cf +++ b/examples/main.cf @@ -1,14 +1,11 @@ # Example showing how the default bundlesequence runs bundle agent main - bundle agent main # @brief main is the default bundlesequence { reports: - "Hello, $(this.bundle) bundle."; + "Hello, $(this.bundle) bundle."; } - #@ The policy promises to report the name of the current bundle, and produces this output: - #+begin_src example_output #@ ``` #@ R: Hello, main bundle. diff --git a/examples/main_entry_point.cf b/examples/main_entry_point.cf index 3fc2181165..d7f383dc1c 100644 --- a/examples/main_entry_point.cf +++ b/examples/main_entry_point.cf @@ -2,19 +2,16 @@ # Example showing how bundle __main__ works # This file can be used as the main entry (`cf-agent -KIf ./main_entry_point.cf`) # This file can also be included from another policy file containing __main__ - body file control { - inputs => { "$(sys.policy_entry_dirname)/main_library.cf" }; + inputs => { "$(sys.policy_entry_dirname)/main_library.cf" }; } bundle agent __main__ { methods: - - "a" usebundle => libprint("Hello from $(sys.policy_entry_basename)"); + "a" usebundle => libprint("Hello from $(sys.policy_entry_basename)"); } - #+begin_src example_output #@ ``` #@ R: Library: Hello from main_entry_point.cf. diff --git a/examples/main_library.cf b/examples/main_library.cf index 9f6460639f..67f71e79ca 100644 --- a/examples/main_library.cf +++ b/examples/main_library.cf @@ -2,12 +2,11 @@ # Example showing how bundle __main__ works # This file can be used as the main entry (`cf-agent -KIf ./main_library.cf`) # This file can also be included from another policy file containing __main__ - bundle agent libprint(message) # @brief report `message` { reports: - "Library: $(message)."; + "Library: $(message)."; } bundle agent __main__ @@ -15,11 +14,9 @@ bundle agent __main__ # This bundle is special. It is ignored unless it is the policy entry file { methods: - "test" usebundle => libprint( "ok 1 - libprint works" ); + "test" usebundle => libprint("ok 1 - libprint works"); } - #@ The policy promises to call libprint to report that it works when the policy file is the main entry. - #+begin_src example_output #@ ``` #@ R: Library: ok 1 - libprint works diff --git a/examples/maparray.cf b/examples/maparray.cf index fceb0227d0..a9ee706b99 100644 --- a/examples/maparray.cf +++ b/examples/maparray.cf @@ -1,48 +1,49 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - #+begin_src cfengine3 body common control { - bundlesequence => { "run" }; + bundlesequence => { "run" }; } bundle agent run { vars: - "static[2]" string => "lookup 2"; - "static[two]" string => "lookup two"; - "static[big]" string => "lookup big"; - "static[small]" string => "lookup small"; + "static[2]" string => "lookup 2"; + "static[two]" string => "lookup two"; + "static[big]" string => "lookup big"; + "static[small]" string => "lookup small"; + "todo[1]" string => "2"; + "todo[one]" string => "two"; + "todo[3999]" slist => { "big", "small" }; + + "map" + slist => maparray( + "key='$(this.k)', static lookup = '$(static[$(this.v)])', value='$(this.v)'", + todo + ); - "todo[1]" string => "2"; - "todo[one]" string => "two"; - "todo[3999]" slist => { "big", "small" }; - "map" slist => - maparray("key='$(this.k)', static lookup = '$(static[$(this.v)])', value='$(this.v)'", - todo); - "map_sorted" slist => sort(map, lex); + "map_sorted" slist => sort(map, lex); - "mycontainer" data => parsejson(' + "mycontainer" + data => parsejson(' { "top": { @@ -50,16 +51,19 @@ bundle agent run "y": "big" } }'); - "mapc" slist => - maparray("key='$(this.k)', key2='$(this.k[1])', static lookup = '$(static[$(this.v)])', value='$(this.v)'", - mycontainer); - "mapc_str" string => format("%S", mapc); + + "mapc" + slist => maparray( + "key='$(this.k)', key2='$(this.k[1])', static lookup = '$(static[$(this.v)])', value='$(this.v)'", + mycontainer + ); + + "mapc_str" string => format("%S", mapc); reports: - "mapped array: $(map_sorted)"; - "mapped container: $(mapc_str)"; + "mapped array: $(map_sorted)"; + "mapped container: $(mapc_str)"; } - #+end_src ############################################################################### #+begin_src example_output diff --git a/examples/mapdata.cf b/examples/mapdata.cf index 19fe2c16e9..92b3d3e9a5 100644 --- a/examples/mapdata.cf +++ b/examples/mapdata.cf @@ -1,46 +1,56 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - #+begin_src cfengine3 body common control { - bundlesequence => { "run" }; + bundlesequence => { "run" }; } bundle agent run { vars: - "myarray[lookup][big]" string => "lookup big"; - "myarray[lookup][small]" string => "lookup small"; + "myarray[lookup][big]" string => "lookup big"; + "myarray[lookup][small]" string => "lookup small"; - # every item must parse as valid JSON when the interpretation is `json` - "mapa_json" data => mapdata("json", '{ "key": "$(this.k)", "key2": "$(this.k[1])", "value": "$(this.v)" }', myarray); - "mapa_json_str" string => format("%S", mapa_json); + # every item must parse as valid JSON when the interpretation is `json` + "mapa_json" + data => mapdata( + "json", + '{ "key": "$(this.k)", "key2": "$(this.k[1])", "value": "$(this.v)" }', + myarray + ); - # every item is just a string when the interpretation is `none` - "mapa_none" data => mapdata("none", 'key=$(this.k), level 2 key = $(this.k[1]), value=$(this.v)', myarray); - "mapa_none_str" string => format("%S", mapa_none); + "mapa_json_str" string => format("%S", mapa_json); - "mycontainer" data => parsejson(' + # every item is just a string when the interpretation is `none` + "mapa_none" + data => mapdata( + "none", + 'key=$(this.k), level 2 key = $(this.k[1]), value=$(this.v)', + myarray + ); + + "mapa_none_str" string => format("%S", mapa_none); + + "mycontainer" + data => parsejson(' { "top": { @@ -49,13 +59,25 @@ bundle agent run } }'); - # every item must parse as valid JSON when the interpretation is `json` - "mapc_json" data => mapdata("json", '{ "key": "$(this.k)", "key2": "$(this.k[1])", "value": "$(this.v)" }', mycontainer); - "mapc_json_str" string => format("%S", mapc_json); + # every item must parse as valid JSON when the interpretation is `json` + "mapc_json" + data => mapdata( + "json", + '{ "key": "$(this.k)", "key2": "$(this.k[1])", "value": "$(this.v)" }', + mycontainer + ); + + "mapc_json_str" string => format("%S", mapc_json); - # every item is just a string when the interpretation is `none` - "mapc_none" data => mapdata("none", 'key=$(this.k), level 2 key = $(this.k[1]), value=$(this.v)', mycontainer); - "mapc_none_str" string => format("%S", mapc_none); + # every item is just a string when the interpretation is `none` + "mapc_none" + data => mapdata( + "none", + 'key=$(this.k), level 2 key = $(this.k[1]), value=$(this.v)', + mycontainer + ); + + "mapc_none_str" string => format("%S", mapc_none); reports: show_example:: @@ -68,7 +90,6 @@ bundle agent run "Note that the output of the above reports is not deterministic,"; "because the order of the keys returned by mapdata() is not guaranteed."; } - #+end_src ############################################################################### #+begin_src show_example_example_output diff --git a/examples/mapdata_jsonpipe.cf b/examples/mapdata_jsonpipe.cf index c50ea18f30..231a39142d 100644 --- a/examples/mapdata_jsonpipe.cf +++ b/examples/mapdata_jsonpipe.cf @@ -1,69 +1,65 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - #+begin_src cfengine3 body common control { - bundlesequence => { "run" }; + bundlesequence => { "run" }; } bundle agent run { vars: - "tester" data => '{ "x": 100, "y": [ true, "a", "b" ] }'; + "tester" data => '{ "x": 100, "y": [ true, "a", "b" ] }'; - # "jq ." returns the same thing that was passed in - "pipe_passthrough" data => mapdata("json_pipe", '$(def.jq) .', tester); - "pipe_passthrough_str" string => format("%S", pipe_passthrough); + # "jq ." returns the same thing that was passed in + "pipe_passthrough" data => mapdata("json_pipe", '$(def.jq) .', tester); + "pipe_passthrough_str" string => format("%S", pipe_passthrough); - # "jq .x" returns what was under x wrapped in an array: [100] - "pipe_justx" data => mapdata("json_pipe", '$(def.jq) .x', tester); - "pipe_justx_str" string => format("%S", pipe_justx); + # "jq .x" returns what was under x wrapped in an array: [100] + "pipe_justx" data => mapdata("json_pipe", '$(def.jq) .x', tester); + "pipe_justx_str" string => format("%S", pipe_justx); - # "jq .y" returns what was under y wrapped in an array: [[true,"a","b"]] - "pipe_justy" data => mapdata("json_pipe", '$(def.jq) .y', tester); - "pipe_justy_str" string => format("%S", pipe_justy); + # "jq .y" returns what was under y wrapped in an array: [[true,"a","b"]] + "pipe_justy" data => mapdata("json_pipe", '$(def.jq) .y', tester); + "pipe_justy_str" string => format("%S", pipe_justy); - # "jq .y[]" returns each entry under y *separately*: [true,"a","b"] - "pipe_yarray" data => mapdata("json_pipe", '$(def.jq) .y[]', tester); - "pipe_yarray_str" string => format("%S", pipe_yarray); + # "jq .y[]" returns each entry under y *separately*: [true,"a","b"] + "pipe_yarray" data => mapdata("json_pipe", '$(def.jq) .y[]', tester); + "pipe_yarray_str" string => format("%S", pipe_yarray); - # "jq .z" returns null because the key "z" is missing: [null] - "pipe_justz" data => mapdata("json_pipe", '$(def.jq) .z', tester); - "pipe_justz_str" string => format("%S", pipe_justz); + # "jq .z" returns null because the key "z" is missing: [null] + "pipe_justz" data => mapdata("json_pipe", '$(def.jq) .z', tester); + "pipe_justz_str" string => format("%S", pipe_justz); - # "jq" can do math too! and much more! - "pipe_jqmath" data => mapdata("json_pipe", '$(def.jq) 1+2+3', tester); - "pipe_jqmath_str" string => format("%S", pipe_jqmath); + # "jq" can do math too! and much more! + "pipe_jqmath" data => mapdata("json_pipe", '$(def.jq) 1+2+3', tester); + "pipe_jqmath_str" string => format("%S", pipe_jqmath); reports: - "mapdata/json_pipe passthrough result: $(pipe_passthrough_str)"; - "mapdata/json_pipe just x result: $(pipe_justx_str)"; - "mapdata/json_pipe just y result: $(pipe_justy_str)"; - "mapdata/json_pipe array under y result: $(pipe_yarray_str)"; - "mapdata/json_pipe just z result: $(pipe_justz_str)"; - "mapdata/json_pipe math expression result: $(pipe_jqmath_str)"; + "mapdata/json_pipe passthrough result: $(pipe_passthrough_str)"; + "mapdata/json_pipe just x result: $(pipe_justx_str)"; + "mapdata/json_pipe just y result: $(pipe_justy_str)"; + "mapdata/json_pipe array under y result: $(pipe_yarray_str)"; + "mapdata/json_pipe just z result: $(pipe_justz_str)"; + "mapdata/json_pipe math expression result: $(pipe_jqmath_str)"; } - #+end_src ############################################################################### #+begin_src output diff --git a/examples/maplist.cf b/examples/maplist.cf index 11c20354c2..ab4d0603d3 100644 --- a/examples/maplist.cf +++ b/examples/maplist.cf @@ -1,53 +1,44 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - #+begin_src cfengine3 body common control { - bundlesequence => { "example" }; + bundlesequence => { "example" }; } bundle common g { vars: - - "otherlist" slist => { "x", "y", "z" }; + "otherlist" slist => { "x", "y", "z" }; } - ####################################################### - bundle agent example - { vars: - - "oldlist" slist => { "a", "b", "c" }; - - "newlist1" slist => maplist("Element ($(this))","@(g.otherlist)"); - "newlist2" slist => maplist("Element ($(this))",@(oldlist)); + "oldlist" slist => { "a", "b", "c" }; + "newlist1" slist => maplist("Element ($(this))", "@(g.otherlist)"); + "newlist2" slist => maplist("Element ($(this))", @(oldlist)); reports: - "Transform: $(newlist1)"; - "Transform: $(newlist2)"; + "Transform: $(newlist1)"; + "Transform: $(newlist2)"; } #+end_src ############################################################################### diff --git a/examples/max-min-mean-variance.cf b/examples/max-min-mean-variance.cf index 838779beb2..81438a991b 100644 --- a/examples/max-min-mean-variance.cf +++ b/examples/max-min-mean-variance.cf @@ -1,63 +1,56 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - #+begin_src cfengine3 body common control { - bundlesequence => { "test" }; + bundlesequence => { "test" }; } bundle agent test { vars: - # the behavior will be the same whether you use a data container or a list - # "mylist" slist => { "foo", "1", "2", "3000", "bar", "10.20.30.40" }; - "mylist" data => parsejson('["foo", "1", "2", "3000", "bar", "10.20.30.40"]'); - "mylist_str" string => format("%S", mylist); + # the behavior will be the same whether you use a data container or a list + # "mylist" slist => { "foo", "1", "2", "3000", "bar", "10.20.30.40" }; + "mylist" + data => parsejson('["foo", "1", "2", "3000", "bar", "10.20.30.40"]'); - "max_int" string => max(mylist, "int"); - "max_lex" string => max(mylist, "lex"); - "max_ip" string => max(mylist, "ip"); - - "min_int" string => min(mylist, "int"); - "min_lex" string => min(mylist, "lex"); - "min_ip" string => min(mylist, "ip"); - - "mean" real => mean(mylist); - "variance" real => variance(mylist); + "mylist_str" string => format("%S", mylist); + "max_int" string => max(mylist, "int"); + "max_lex" string => max(mylist, "lex"); + "max_ip" string => max(mylist, "ip"); + "min_int" string => min(mylist, "int"); + "min_lex" string => min(mylist, "lex"); + "min_ip" string => min(mylist, "ip"); + "mean" real => mean(mylist); + "variance" real => variance(mylist); reports: - "my list is $(mylist_str)"; - - "mean is $(mean)"; - "variance is $(variance) (use eval() to get the standard deviation)"; - - "max int is $(max_int)"; - "max IP is $(max_ip)"; - "max lexicographically is $(max_lex)"; - - "min int is $(min_int)"; - "min IP is $(min_ip)"; - "min lexicographically is $(min_lex)"; + "my list is $(mylist_str)"; + "mean is $(mean)"; + "variance is $(variance) (use eval() to get the standard deviation)"; + "max int is $(max_int)"; + "max IP is $(max_ip)"; + "max lexicographically is $(max_lex)"; + "min int is $(min_int)"; + "min IP is $(min_ip)"; + "min lexicographically is $(min_lex)"; } #+end_src ############################################################################### diff --git a/examples/measure_log.cf b/examples/measure_log.cf index 5bba071d79..a672548b58 100644 --- a/examples/measure_log.cf +++ b/examples/measure_log.cf @@ -1,42 +1,33 @@ #cop measurements,example - ####################################################### # # Test file: log scanner # ####################################################### - # # Look for a file in $STATEDIR/line_counter_measure.log # # $STATEDIR = $WORKDIR/state unless overridden at compile time. -# - bundle monitor watch { measurements: - - "/home/mark/tmp/file" - + "/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"); - } - ########################################################## - 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"; } diff --git a/examples/measurements.cf b/examples/measurements.cf index 911c0b068a..72c561ad85 100644 --- a/examples/measurements.cf +++ b/examples/measurements.cf @@ -1,27 +1,23 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - #cop measurements,example - ####################################################### # # Test file: @@ -30,41 +26,31 @@ # Blonk blonk bnklkygsuilnm # ####################################################### - body common control { - bundlesequence => { "report" }; + bundlesequence => { "report" }; } - ####################################################### - body monitor control { - forgetrate => "0.7"; - histograms => "true"; + forgetrate => "0.7"; + histograms => "true"; } - ####################################################### - bundle agent report { reports: - " + " Free memory read at $(mon.av_free_memory_watch) cf_monitord read $(mon.value_monitor_self_watch) "; } - ####################################################### - bundle monitor watch { measurements: - - # Test 1 - extract string matching - - "/home/mark/tmp/testmeasure" - + # Test 1 - extract string matching + "/home/mark/tmp/testmeasure" handle => "blonk_watch", stream_type => "file", data_type => "string", @@ -73,87 +59,70 @@ bundle monitor watch match_value => find_blonks, action => sample_min("10"); - # Test 2 - follow a special process over time - # using cfengine's process cache to avoid resampling - - "/var/cfengine/state/cf_rootprocs" - + # Test 2 - follow a special process over time + # using cfengine's process cache to avoid resampling + "/var/cfengine/state/cf_rootprocs" handle => "monitor_self_watch", stream_type => "file", data_type => "int", history_type => "static", units => "kB", - match_value => proc_value(".*cf-monitord.*", - "root\s+[0-9.]+\s+[0-9.]+\s+[0-9.]+\s+[0-9.]+\s+([0-9]+).*"); - - # Test 3, discover disk device information - - "/bin/df" + match_value => proc_value( + ".*cf-monitord.*", + "root\s+[0-9.]+\s+[0-9.]+\s+[0-9.]+\s+[0-9.]+\s+([0-9]+).*" + ); + # Test 3, discover disk device information + "/bin/df" handle => "free_disk_watch", stream_type => "pipe", data_type => "slist", history_type => "static", units => "device", match_value => file_system; - # Update this as often as possible - - # Test 4 - - "/tmp/file" + # Update this as often as possible + # Test 4 + "/tmp/file" handle => "line_counter", stream_type => "file", data_type => "counter", match_value => scanlines("MYLINE.*"), history_type => "log"; - } - ########################################################## - body match_value scanlines(x) { - select_line_matching => "^$(x)$"; + select_line_matching => "^$(x)$"; } - ########################################################## - body action sample_min(x) { - ifelapsed => "$(x)"; - expireafter => "$(x)"; + ifelapsed => "$(x)"; + expireafter => "$(x)"; } - ########################################################## - body match_value find_blonks { - select_line_number => "2"; - extraction_regex => "Blonk blonk ([blonk]+).*"; + select_line_number => "2"; + extraction_regex => "Blonk blonk ([blonk]+).*"; } - ########################################################## - -body match_value free_memory # not willy! +body match_value free_memory +# not willy! { - select_line_matching => "MemFree:.*"; - extraction_regex => "MemFree:\s+([0-9]+).*"; + select_line_matching => "MemFree:.*"; + extraction_regex => "MemFree:\s+([0-9]+).*"; } - ########################################################## - -body match_value proc_value(x,y) +body match_value proc_value(x, y) { - select_line_matching => "$(x)"; - extraction_regex => "$(y)"; + select_line_matching => "$(x)"; + extraction_regex => "$(y)"; } - ########################################################## - body match_value file_system { - select_line_matching => "/.*"; - extraction_regex => "(.*)"; + select_line_matching => "/.*"; + extraction_regex => "(.*)"; } - diff --git a/examples/menu.cf b/examples/menu.cf index eb17774e56..85b924d576 100644 --- a/examples/menu.cf +++ b/examples/menu.cf @@ -1,31 +1,27 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - ######################################################## # # Simple test copy from server connection to cfServer # ######################################################## - # # run this as follows: # @@ -33,46 +29,36 @@ # cf-agent -f runtest_2.cf # # Notice that the same file configures all parts of cfengine - ######################################################## - body common control { - bundlesequence => { "example" }; - version => "1.2.3"; + bundlesequence => { "example" }; + version => "1.2.3"; } - # cf-runagent -q - bundle agent example { files: } - ######################################################### # Server config ######################################################### - -body server control - +body server control { - allowconnects => { "127.0.0.1" , "::1" }; - allowallconnects => { "127.0.0.1" , "::1" }; - trustkeysfrom => { "127.0.0.1" , "::1" }; - allowusers => { "mark", "root" }; + allowconnects => { "127.0.0.1", "::1" }; + allowallconnects => { "127.0.0.1", "::1" }; + trustkeysfrom => { "127.0.0.1", "::1" }; + allowusers => { "mark", "root" }; } - ######################################################### - bundle server access_rules() - { access: - - "delta" + "delta" resource_type => "query", - admit => { "127.0.0.1" }; - "full" + admit => { "127.0.0.1" }; + + "full" resource_type => "query", - admit => { "127.0.0.1" }; + admit => { "127.0.0.1" }; } diff --git a/examples/mergedata-last-key-wins.cf b/examples/mergedata-last-key-wins.cf index fc75d4702c..a03adad5b1 100644 --- a/examples/mergedata-last-key-wins.cf +++ b/examples/mergedata-last-key-wins.cf @@ -3,17 +3,19 @@ bundle agent mergedata_last_key_wins # @brief Example illustrating how the last key wins when merging data containers with conflicting keys { vars: + "one" + data => '{ "color": "red", "stuff": [ "one", "two" ], "thing": "one" }'; - "one" data => '{ "color": "red", "stuff": [ "one", "two" ], "thing": "one" }'; - "two" data => '{ "color": "blue", "stuff": [ "three" ] }'; + "two" data => '{ "color": "blue", "stuff": [ "three" ] }'; reports: - "$(with)" with => storejson( mergedata( one, two ) ); - + "$(with)" with => storejson(mergedata(one, two)); } + bundle agent __main__ { - methods: "mergedata_last_key_wins"; + methods: + "mergedata_last_key_wins"; } #+end_src ############################################################################### diff --git a/examples/mergedata.cf b/examples/mergedata.cf index bfaa830912..f22af1e779 100644 --- a/examples/mergedata.cf +++ b/examples/mergedata.cf @@ -1,108 +1,151 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - #+begin_src cfengine3 body common control { - bundlesequence => { "test", "test2", "test3" }; + bundlesequence => { "test", "test2", "test3" }; } bundle agent test { vars: - "d1" data => parsejson('{ "a": [1,2,3], "b": [] }'); - "d2" data => parsejson('{ "b": [4,5,6] }'); - "d3" data => parsejson('[4,5,6]'); - "list1" slist => { "element1", "element2" }; - "array1[mykey]" slist => { "array_element1", "array_element2" }; - "array2[otherkey]" string => "hello"; - - "merged_d1_d2" data => mergedata("d1", "d2"); - "merged_d1_d3" data => mergedata("d1", "d3"); - "merged_d3_list1" data => mergedata("d3", "list1"); - - "merged_d1_array1" data => mergedata("d1", "array1"); - "merged_d2_array2" data => mergedata("d2", "array2"); - - "merged_d1_wrap_array_d2" data => mergedata("d1", "[ d2 ]"); - "merged_d1_wrap_map_d2" data => mergedata("d1", '{ "newkey": d2 }'); - - "merged_d1_d2_str" string => format("merging %S with %S produced %S", d1, d2, merged_d1_d2); - "merged_d1_wrap_array_d2_str" string => format("merging %S with wrapped [ %S ] produced %S", d1, d2, merged_d1_wrap_array_d2); - "merged_d1_wrap_map_d2_str" string => format('merging %S with wrapped { "newkey": %S produced %S', d1, d2, merged_d1_wrap_map_d2); - "merged_d1_d3_str" string => format("merging %S with %S produced %S", d1, d3, merged_d1_d3); - "merged_d3_list1_str" string => format("merging %S with %S produced %S", d3, list1, merged_d3_list1); - - "merged_d1_array1_str" string => format("merging %S with %s produced %S", d1, array1, merged_d1_array1); - "merged_d2_array2_str" string => format("merging %S with %s produced %S", d2, array2, merged_d2_array2); + "d1" data => parsejson('{ "a": [1,2,3], "b": [] }'); + "d2" data => parsejson('{ "b": [4,5,6] }'); + "d3" data => parsejson('[4,5,6]'); + "list1" slist => { "element1", "element2" }; + "array1[mykey]" slist => { "array_element1", "array_element2" }; + "array2[otherkey]" string => "hello"; + "merged_d1_d2" data => mergedata("d1", "d2"); + "merged_d1_d3" data => mergedata("d1", "d3"); + "merged_d3_list1" data => mergedata("d3", "list1"); + "merged_d1_array1" data => mergedata("d1", "array1"); + "merged_d2_array2" data => mergedata("d2", "array2"); + "merged_d1_wrap_array_d2" data => mergedata("d1", "[ d2 ]"); + "merged_d1_wrap_map_d2" data => mergedata("d1", '{ "newkey": d2 }'); + + "merged_d1_d2_str" + string => format("merging %S with %S produced %S", d1, d2, merged_d1_d2); + + "merged_d1_wrap_array_d2_str" + string => format( + "merging %S with wrapped [ %S ] produced %S", + d1, + d2, + merged_d1_wrap_array_d2 + ); + + "merged_d1_wrap_map_d2_str" + string => format( + 'merging %S with wrapped { "newkey": %S produced %S', + d1, + d2, + merged_d1_wrap_map_d2 + ); + + "merged_d1_d3_str" + string => format("merging %S with %S produced %S", d1, d3, merged_d1_d3); + + "merged_d3_list1_str" + string => format( + "merging %S with %S produced %S", d3, list1, merged_d3_list1 + ); + + "merged_d1_array1_str" + string => format( + "merging %S with %s produced %S", d1, array1, merged_d1_array1 + ); + + "merged_d2_array2_str" + string => format( + "merging %S with %s produced %S", d2, array2, merged_d2_array2 + ); + reports: - "$(merged_d1_d2_str)"; - "$(merged_d1_wrap_array_d2_str)"; - "$(merged_d1_wrap_map_d2_str)"; - "$(merged_d1_d3_str)"; - "$(merged_d3_list1_str)"; - "$(merged_d1_array1_str)"; - "$(merged_d2_array2_str)"; + "$(merged_d1_d2_str)"; + "$(merged_d1_wrap_array_d2_str)"; + "$(merged_d1_wrap_map_d2_str)"; + "$(merged_d1_d3_str)"; + "$(merged_d3_list1_str)"; + "$(merged_d1_array1_str)"; + "$(merged_d2_array2_str)"; } bundle agent test2 { vars: - "a" data => parsejson('{ "a": "1" }'), meta => { "mymerge" }; - "b" data => parsejson('{ "b": "2" }'), meta => { "mymerge" }; - "c" data => parsejson('{ "c": "3" }'), meta => { "mymerge" }; - "d" data => parsejson('{ "d": "4" }'), meta => { "mymerge" }; - "todo" slist => variablesmatching(".*", "mymerge"); + "a" + data => parsejson('{ "a": "1" }'), + meta => { "mymerge" }; - methods: - "go" usebundle => cmerge(@(todo)); # a, b, c, d + "b" + data => parsejson('{ "b": "2" }'), + meta => { "mymerge" }; + + "c" + data => parsejson('{ "c": "3" }'), + meta => { "mymerge" }; + + "d" + data => parsejson('{ "d": "4" }'), + meta => { "mymerge" }; + "todo" slist => variablesmatching(".*", "mymerge"); + + methods: + "go" usebundle => cmerge(@(todo)); + # a, b, c, d reports: - "$(this.bundle): merged containers with cmerge = $(cmerge.all_str)"; + "$(this.bundle): merged containers with cmerge = $(cmerge.all_str)"; } - # note this bundle is in the standard library, in lib/3.6/bundles.cf bundle agent cmerge(varlist) { vars: - "all" data => parsejson('[]'), policy => "free"; - "all" data => mergedata(all, $(varlist)), policy => "free"; - "all_str" string => format("%S", all), policy => "free"; + "all" + data => parsejson('[]'), + policy => "free"; + + "all" + data => mergedata(all, $(varlist)), + policy => "free"; + + "all_str" + string => format("%S", all), + policy => "free"; } bundle agent test3 { - vars: - "dest_files" slist => { "/tmp/default.json", "/tmp/epel.json" }; - "template_file" string => "repository.mustache"; + vars: + "dest_files" slist => { "/tmp/default.json", "/tmp/epel.json" }; + "template_file" string => "repository.mustache"; - "process_templates" data => mergedata('{ "$(template_file)" : dest_files }'); - "process__templates_str" string => format("%S", "process_templates"); + "process_templates" + data => mergedata('{ "$(template_file)" : dest_files }'); - reports: - "$(this.bundle) $(process__templates_str)"; - "$(this.bundle) $(process_templates[$(template_file)])"; -} + "process__templates_str" string => format("%S", "process_templates"); + reports: + "$(this.bundle) $(process__templates_str)"; + "$(this.bundle) $(process_templates[$(template_file)])"; +} #+end_src ############################################################################### #+begin_src example_output diff --git a/examples/meta.cf b/examples/meta.cf index 9e76e9d1de..36dd7427e4 100644 --- a/examples/meta.cf +++ b/examples/meta.cf @@ -1,62 +1,46 @@ - # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - # # Default values for variables and parameters, introduced 3.4.0 -# - body common control - { - bundlesequence => { "example" }; + bundlesequence => { "example" }; } - ########################################################### - bundle agent example - -{ +{ meta: - - "bundle_version" string => "1.2.3"; - "works_with_cfengine" string => "3.4.0"; + "bundle_version" string => "1.2.3"; + "works_with_cfengine" string => "3.4.0"; vars: - - "testvar" string => "x"; + "testvar" string => "x"; reports: - "Not a local variable: $(bundle_version)"; - "Not a local variable: $(other_bundle.something)"; - "Meta data (variable): $(example_meta.bundle_version)"; - + "Not a local variable: $(bundle_version)"; + "Not a local variable: $(other_bundle.something)"; + "Meta data (variable): $(example_meta.bundle_version)"; } - bundle agent other_bundle - { vars: - - "something" string => "I am defined in another bundle"; + "something" string => "I am defined in another bundle"; } diff --git a/examples/method.cf b/examples/method.cf index bef2705955..9f38af61b9 100644 --- a/examples/method.cf +++ b/examples/method.cf @@ -1,59 +1,42 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - - body common control - { - bundlesequence => { "example" }; - - version => "1.2.3"; + bundlesequence => { "example" }; + version => "1.2.3"; } - ########################################### - bundle agent example { vars: - - "userlist" slist => { "mark", "jeang", "jonhenrik", "thomas", "eben" }; + "userlist" slist => { "mark", "jeang", "jonhenrik", "thomas", "eben" }; methods: - - "any" usebundle => subtest("$(userlist)"); - + "any" usebundle => subtest("$(userlist)"); } - ########################################### - bundle agent subtest(user) - { commands: - - "/bin/echo Fix $(user)"; + "/bin/echo Fix $(user)"; reports: - - "Finished doing stuff for $(user)"; + "Finished doing stuff for $(user)"; } - diff --git a/examples/method_polymorph.cf b/examples/method_polymorph.cf index d3f437b4ff..e2ec7bcc3c 100644 --- a/examples/method_polymorph.cf +++ b/examples/method_polymorph.cf @@ -1,38 +1,25 @@ -# # Demonstrates the use of polymorphism to call bundles. -# - body common control { - bundlesequence => { "example" }; + bundlesequence => { "example" }; } - ########################################### - bundle agent example { methods: - - "Patch Group" - + "Patch Group" comment => "Apply OS specific patches and modifications", usebundle => "$(sys.class)_fix"; - } - ########################################### - bundle agent linux_fix { reports: - "Fixes for linux"; + "Fixes for linux"; } - ########################################### - bundle agent solaris_android { reports: - "Fixes for android"; + "Fixes for android"; } - diff --git a/examples/method_validate.cf b/examples/method_validate.cf index 03bcbb7508..55f5528f84 100644 --- a/examples/method_validate.cf +++ b/examples/method_validate.cf @@ -1,72 +1,52 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - - body common control - { - bundlesequence => { "example" }; - - version => "1.2.3"; + bundlesequence => { "example" }; + version => "1.2.3"; } - ########################################### - body agent control - { - abortbundleclasses => { "invalid" }; + abortbundleclasses => { "invalid" }; } - ########################################### - bundle agent example { vars: - - "userlist" slist => { "xyz", "mark", "jeang", "jonhenrik", "thomas", "eben" }; + "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][a-z][a-z][a-z]","$(user)"); + "invalid" not => regcmp("[a-z][a-z][a-z][a-z]", "$(user)"); reports: - !invalid:: - "User name $(user) is valid at 4 letters"; invalid:: - "User name $(user) is invalid"; } diff --git a/examples/method_var.cf b/examples/method_var.cf index 9d48783f7e..b1cdd8e161 100644 --- a/examples/method_var.cf +++ b/examples/method_var.cf @@ -1,47 +1,35 @@ -# # Demonstrates the use of variables to call bundles. # We can then filter variables on classes, for example. -# - body common control { - bundlesequence => { "example" }; + bundlesequence => { "example" }; } - ########################################### - bundle agent test { vars: - "run_bundles" slist => { "test_one", "test_two" }; - "run_a_bundle" string => "test_three"; + "run_bundles" slist => { "test_one", "test_two" }; + "run_a_bundle" string => "test_three"; methods: - "any" usebundle => "$(run_bundles)"; - "any" usebundle => "$(run_a_bundle)"; + "any" usebundle => "$(run_bundles)"; + "any" usebundle => "$(run_a_bundle)"; } - ########################################### - bundle agent test_one { reports: - "in test_one"; + "in test_one"; } - ########################################### - bundle agent test_two { reports: - "in test_two"; + "in test_two"; } - ########################################### - bundle agent test_three { reports: - "in test_three"; + "in test_three"; } - diff --git a/examples/method_var2.cf b/examples/method_var2.cf index b4a452b8ad..d60204a2da 100644 --- a/examples/method_var2.cf +++ b/examples/method_var2.cf @@ -1,47 +1,33 @@ -# # Demonstrates the use of polymorphism to call bundles. -# - body common control { - bundlesequence => { "example" }; + bundlesequence => { "example" }; } - ########################################### - bundle agent example { vars: - "m" slist => { "login", "ssh_keys", "environment" }; - "user" slist => { "diego", "mark", "neil" }; + "m" slist => { "login", "ssh_keys", "environment" }; + "user" slist => { "diego", "mark", "neil" }; methods: - "set of $(m)" usebundle => $(m)("$(user)"); - - + "set of $(m)" usebundle => $(m)("$(user)"); } - ########################################### - bundle agent login(x) { reports: - "Setup login for $(x)"; + "Setup login for $(x)"; } - ########################################### - bundle agent ssh_keys(x) { reports: - "Setup ssh keys for $(x)"; + "Setup ssh keys for $(x)"; } - ########################################### - bundle agent environment(x) { reports: - "Setup login environment for $(x)"; + "Setup login environment for $(x)"; } - diff --git a/examples/missing_ok.cf b/examples/missing_ok.cf index 63a10595d2..a674e42bf4 100644 --- a/examples/missing_ok.cf +++ b/examples/missing_ok.cf @@ -1,78 +1,77 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - # This example shows how to use the missing_ok attribute in copy from bodies. If # the source file is missing, the promise will be seen to be a promise kept # instead of a failure. The exception is that a remote copy that fails to make a # connection to the remote server will still be seen as a promise failure. - #+begin_src cfengine3 bundle agent main { files: "/tmp/copied_from_missing_ok" - copy_from => missing_ok( "/var/cfengine/masterfiles/missing" ), + copy_from => missing_ok("/var/cfengine/masterfiles/missing"), classes => results("bundle", "copy_from_missing_ok"); reports: "$(with)" - with => string_mustache( "{{%-top-}}", sort( classesmatching( "copy_from_.*" ), lex)); + with => string_mustache( + "{{%-top-}}", sort(classesmatching("copy_from_.*"), lex) + ); } -body copy_from missing_ok( file_path ) + +body copy_from missing_ok(file_path) { source => "$(file_path)"; missing_ok => "true"; - - # Run with these classes to try remote copies - remote_copy_self:: - servers => { "127.0.0.1" }; - - remote_copy_policy_hub:: - servers => { $(sys.policy_hub) }; + # Run with these classes to try remote copies + remote_copy_self:: + servers => { "127.0.0.1" }; + remote_copy_policy_hub:: + servers => { $(sys.policy_hub) }; } + body classes results(scope, class_prefix) { scope => "$(scope)"; - - promise_kept => { "$(class_prefix)_reached", - "$(class_prefix)_kept" }; - - promise_repaired => { "$(class_prefix)_reached", - "$(class_prefix)_repaired" }; - - repair_failed => { "$(class_prefix)_reached", - "$(class_prefix)_error", - "$(class_prefix)_not_kept", - "$(class_prefix)_failed" }; - - repair_denied => { "$(class_prefix)_reached", - "$(class_prefix)_error", - "$(class_prefix)_not_kept", - "$(class_prefix)_denied" }; - - repair_timeout => { "$(class_prefix)_reached", - "$(class_prefix)_error", - "$(class_prefix)_not_kept", - "$(class_prefix)_timeout" }; + promise_kept => { "$(class_prefix)_reached", "$(class_prefix)_kept" }; + promise_repaired => { + "$(class_prefix)_reached", "$(class_prefix)_repaired" + }; + repair_failed => { + "$(class_prefix)_reached", + "$(class_prefix)_error", + "$(class_prefix)_not_kept", + "$(class_prefix)_failed", + }; + repair_denied => { + "$(class_prefix)_reached", + "$(class_prefix)_error", + "$(class_prefix)_not_kept", + "$(class_prefix)_denied", + }; + repair_timeout => { + "$(class_prefix)_reached", + "$(class_prefix)_error", + "$(class_prefix)_not_kept", + "$(class_prefix)_timeout", + }; } #+end_src #@ In the above example `/tmp/copied_from_missing_ok` promises to be a copy of the local file diff --git a/examples/module_exec.cf b/examples/module_exec.cf index 07a40ef809..9581dc1976 100644 --- a/examples/module_exec.cf +++ b/examples/module_exec.cf @@ -1,45 +1,34 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - # # Test module execution as class function -# - body common control - { - bundlesequence => { "example" }; + bundlesequence => { "example" }; } - ################################################################### - bundle agent example - { classes: - - "done" or => { usemodule("module:getusers","") }; + "done" or => { usemodule("module:getusers", "") }; commands: - - "/bin/echo promiser text" args => "test $(user)"; + "/bin/echo promiser text" args => "test $(user)"; } diff --git a/examples/module_exec_2.cf b/examples/module_exec_2.cf index 1258f6ecca..e5bde7262d 100644 --- a/examples/module_exec_2.cf +++ b/examples/module_exec_2.cf @@ -1,73 +1,47 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - # # Test module execution as class function -# - body common control - { - bundlesequence => { "def", "example" }; + bundlesequence => { "def", "example" }; } - ################################################################### - bundle agent def - { commands: - - "$(sys.workdir)/modules/module_name" module => "true"; + "$(sys.workdir)/modules/module_name" module => "true"; reports: - - # - # Each module forms a private context with its name as id - # - + # Each module forms a private context with its name as id module_class:: - "Module set variable $(module_name.myscalar)"; - } - ################################################################### - bundle agent example - { vars: - - "mylist" slist => { @(module_name.mylist) }; + "mylist" slist => { @(module_name.mylist) }; reports: - - # - # Each module forms a private context with its name as id - # - + # Each module forms a private context with its name as id module_class:: - "Module set variable $(mylist)"; - } diff --git a/examples/monitord.cf b/examples/monitord.cf index 4e1e88941a..339ac41c5a 100644 --- a/examples/monitord.cf +++ b/examples/monitord.cf @@ -1,43 +1,31 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - ######################################################### - body monitor control { - #version => "1.2.3.4"; - - forgetrate => "0.7"; - - histograms => "true"; - - tcpdump => "false"; - - tcpdumpcommand => "/usr/sbin/tcpdump -i eth1 -n -t -v"; - - # on linux - - linux:: - - # sensor => readfile("/proc/cpu/temperature"); + #version => "1.2.3.4"; + forgetrate => "0.7"; + histograms => "true"; + tcpdump => "false"; + tcpdumpcommand => "/usr/sbin/tcpdump -i eth1 -n -t -v"; + # on linux + linux:: + # sensor => readfile("/proc/cpu/temperature"); } - diff --git a/examples/mount_fs.cf b/examples/mount_fs.cf index bd2d69c241..a723249c08 100644 --- a/examples/mount_fs.cf +++ b/examples/mount_fs.cf @@ -1,58 +1,43 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - - # # cfengine 3 # # cf-agent -f ./cftest.cf -K -# - body common control - { - bundlesequence => { "mounts" }; + bundlesequence => { "mounts" }; } -# - bundle agent mounts - { storage: - - "/mnt" mount => nfs("slogans.iu.hio.no","/home"); - + "/mnt" mount => nfs("slogans.iu.hio.no", "/home"); } - ###################################################################### - -body mount nfs(server,source) - +body mount nfs(server, source) { - mount_type => "nfs"; - mount_source => "$(source)"; - mount_server => "$(server)"; - #mount_options => { "rw" }; - edit_fstab => "true"; - unmount => "true"; + mount_type => "nfs"; + mount_source => "$(source)"; + mount_server => "$(server)"; + #mount_options => { "rw" }; + edit_fstab => "true"; + unmount => "true"; } diff --git a/examples/multipassvars.cf b/examples/multipassvars.cf index d962fcf32c..9faac9f3f0 100644 --- a/examples/multipassvars.cf +++ b/examples/multipassvars.cf @@ -1,35 +1,33 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - -body common control +body common control { - bundlesequence => { "example" }; + bundlesequence => { "example" }; } -bundle agent example +bundle agent example { vars: any:: "tempdir" string => execresult("/bin/mktemp -d", "noshell"); + reports: - "tempdir: ${tempdir}"; + "tempdir: ${tempdir}"; } diff --git a/examples/multiple_outcomes.cf b/examples/multiple_outcomes.cf index 604d023dba..63855a7392 100644 --- a/examples/multiple_outcomes.cf +++ b/examples/multiple_outcomes.cf @@ -1,39 +1,35 @@ # Note: This is NOT an automatically tested example. The difference between # dry-run and normal run output makes it problematic to do so. - #+begin_src cfengine3 bundle agent main { meta: - "description" string => " + "description" + string => " Illustrate how a promise can have multiple outcomes"; vars: !windows:: - "repaired_and_kept" - string => "/tmp/repaired_and_not_kept.txt"; + "repaired_and_kept" string => "/tmp/repaired_and_not_kept.txt"; files: # We make sure our test file is absent so that we # can show consistent outcomes. - "$(repaired_and_kept)" - handle => "testfile_absent", - delete => tidy; - - "$(repaired_and_kept)" - handle => "test_outcomes", - depends_on => { "testfile_absent" }, - create => "true", - edit_template => "$(this.promsie_filename).broken_mustache", - template_method => "mustache", - classes => results("bundle", "outcome"); + "$(repaired_and_kept)" + handle => "testfile_absent", + delete => tidy; + + "$(repaired_and_kept)" + handle => "test_outcomes", + depends_on => { "testfile_absent" }, + create => "true", + edit_template => "$(this.promsie_filename).broken_mustache", + template_method => "mustache", + classes => results("bundle", "outcome"); vars: - "result_classes" - slist => classesmatching("outcome_.*"); - - "s_result_classes" - slist => sort( result_classes, "lex"); + "result_classes" slist => classesmatching("outcome_.*"); + "s_result_classes" slist => sort(result_classes, "lex"); reports: outcome_repaired:: @@ -55,8 +51,8 @@ body delete tidy # repository at commit # 6244c16e6934546d069052f953e597c4b95747df { - dirlinks => "delete"; - rmdirs => "true"; + dirlinks => "delete"; + rmdirs => "true"; } body classes results(scope, class_prefix) @@ -66,30 +62,30 @@ body classes results(scope, class_prefix) # 206a8b2e6bf277c3df9b57bf5c535b0b6dba963a { scope => "$(scope)"; - - promise_kept => { "$(class_prefix)_reached", - "$(class_prefix)_kept" }; - - promise_repaired => { "$(class_prefix)_reached", - "$(class_prefix)_repaired" }; - - repair_failed => { "$(class_prefix)_reached", - "$(class_prefix)_error", - "$(class_prefix)_not_kept", - "$(class_prefix)_failed" }; - - repair_denied => { "$(class_prefix)_reached", - "$(class_prefix)_error", - "$(class_prefix)_not_kept", - "$(class_prefix)_denied" }; - - repair_timeout => { "$(class_prefix)_reached", - "$(class_prefix)_error", - "$(class_prefix)_not_kept", - "$(class_prefix)_timeout" }; + promise_kept => { "$(class_prefix)_reached", "$(class_prefix)_kept" }; + promise_repaired => { + "$(class_prefix)_reached", "$(class_prefix)_repaired" + }; + repair_failed => { + "$(class_prefix)_reached", + "$(class_prefix)_error", + "$(class_prefix)_not_kept", + "$(class_prefix)_failed", + }; + repair_denied => { + "$(class_prefix)_reached", + "$(class_prefix)_error", + "$(class_prefix)_not_kept", + "$(class_prefix)_denied", + }; + repair_timeout => { + "$(class_prefix)_reached", + "$(class_prefix)_error", + "$(class_prefix)_not_kept", + "$(class_prefix)_timeout", + }; } #+end_src - ######################### #+begin_src do_not_test_example_output #@ ``` diff --git a/examples/mustache_classes.cf b/examples/mustache_classes.cf index c4fe623307..7fcf9c6f81 100644 --- a/examples/mustache_classes.cf +++ b/examples/mustache_classes.cf @@ -1,34 +1,30 @@ # Example showing how sections are rendered using cfengine classes - # Being a logicless templating system, mustache is not able to leverage # CFEngine's powerful class expression logic. Only singular classes can be used # to conditionally render a block in mustache. This example shows how you can # define a singular cfengine class based on a complex expression, and then use # that singular class for conditional rendering in a template. - #+begin_src cfengine3 bundle agent main { classes: - - "known_day_of_week" - expression => "(Monday|Tuesday|Wednesday|Thursday|Friday|Saturday|Sunday)"; + "known_day_of_week" + expression => "(Monday|Tuesday|Wednesday|Thursday|Friday|Saturday|Sunday)"; vars: - - "rendered" - string => string_mustache( -"{{#classes.known_day_of_week}}I recognize the day of the week.{{/classes.known_day_of_week}} + "rendered" + string => string_mustache( + "{{#classes.known_day_of_week}}I recognize the day of the week.{{/classes.known_day_of_week}} {{^classes.class_you_are_looking_for}} The class you are looking for is not defined. {{/classes.class_you_are_looking_for}}", - datastate()); - reports: - "$(rendered)"; + datastate() + ); + reports: + "$(rendered)"; } #+end_src - #+begin_src policy_description #@ Here we define the class `known_day_of_week` as long as there is a class #@ representing a known day. Then we render the value of the string variable diff --git a/examples/mustache_comments.cf b/examples/mustache_comments.cf index 1c6b9b92b0..7ab43f5bac 100644 --- a/examples/mustache_comments.cf +++ b/examples/mustache_comments.cf @@ -1,19 +1,15 @@ # Example showing how comments are not rendered - #+begin_src cfengine3 bundle agent main { reports: "$(with)" with => string_mustache("Render this.{{! But not -this}}", - datastate()); +this}}", datastate()); } #+end_src - #+begin_src example_output #@ ``` #@ R: Render this. #@ ``` #+end_src - diff --git a/examples/mustache_extension_compact_json.cf b/examples/mustache_extension_compact_json.cf index 87a4d8dc99..82e052fef0 100644 --- a/examples/mustache_extension_compact_json.cf +++ b/examples/mustache_extension_compact_json.cf @@ -2,19 +2,18 @@ bundle agent main { vars: - "msg" string => "Hello World"; - - "report" - string => string_mustache("{{$-top-}}", bundlestate( $(this.bundle) ) ), - unless => isvariable( $(this.promiser) ); # Careful to not include - # ourselves so we only grab the - # state of the first pass. + "msg" string => "Hello World"; + "report" + string => string_mustache("{{$-top-}}", bundlestate($(this.bundle))), + unless => isvariable($(this.promiser)); + # Careful to not include + # ourselves so we only grab the + # state of the first pass. reports: - "$(report)"; + "$(report)"; } #+end_src - #+begin_src example_output #@ ``` #@ R: {"msg":"Hello World"} diff --git a/examples/mustache_extension_expand_key.cf b/examples/mustache_extension_expand_key.cf index 8a2202d10a..1e57ce2c40 100644 --- a/examples/mustache_extension_expand_key.cf +++ b/examples/mustache_extension_expand_key.cf @@ -2,8 +2,10 @@ bundle agent main { reports: - "$(with)" - with => string_mustache("datastate() provides {{#-top-}} {{{@}}}{{/-top-}}", datastate() ); + "$(with)" + with => string_mustache( + "datastate() provides {{#-top-}} {{{@}}}{{/-top-}}", datastate() + ); } #+end_src ############################################################################### diff --git a/examples/mustache_extension_multiline_json.cf b/examples/mustache_extension_multiline_json.cf index 2b15b643e7..f97b644978 100644 --- a/examples/mustache_extension_multiline_json.cf +++ b/examples/mustache_extension_multiline_json.cf @@ -2,9 +2,10 @@ bundle agent main { reports: - "$(with)" - with => string_mustache( "{{%mykey}}", - '{ "mykey": { "msg": "Hello World" } }' ); + "$(with)" + with => string_mustache( + "{{%mykey}}", '{ "mykey": { "msg": "Hello World" } }' + ); } #+end_src ############################################################################### diff --git a/examples/mustache_extension_top.cf b/examples/mustache_extension_top.cf index a669cbab4b..dc2166b7d5 100644 --- a/examples/mustache_extension_top.cf +++ b/examples/mustache_extension_top.cf @@ -1,19 +1,16 @@ # Example showing how -top- gives access to the entire data provided to a mustache template. - #+begin_src cfengine3 bundle agent main { vars: - "data" data => '{ "key": "value", "list": [ "1", "2" ] }'; + "data" data => '{ "key": "value", "list": [ "1", "2" ] }'; reports: - "-top- contains$(const.n)$(with)" - with => string_mustache("{{%-top-}}", data ); + "-top- contains$(const.n)$(with)" + with => string_mustache("{{%-top-}}", data); } #+end_src - ############################################################################### - #+begin_src example_output #@ ``` #@ R: -top- contains diff --git a/examples/mustache_sections_empty_list.cf b/examples/mustache_sections_empty_list.cf index 4171459912..9c78ac5c8a 100644 --- a/examples/mustache_sections_empty_list.cf +++ b/examples/mustache_sections_empty_list.cf @@ -1,5 +1,4 @@ # Example showing how variables are rendered for empty lists. - #+begin_src cfengine3 bundle agent main { @@ -8,14 +7,11 @@ bundle agent main reports: "The list contains $(with)." - with => string_mustache("{{#list}} {{{.}}}{{/list}}", - data); + with => string_mustache("{{#list}} {{{.}}}{{/list}}", data); } #+end_src - #+begin_src example_output #@ ``` #@ R: The list contains . #@ ``` #+end_src - diff --git a/examples/mustache_sections_inverted.cf b/examples/mustache_sections_inverted.cf index 9151f5216f..1e4d39b2f6 100644 --- a/examples/mustache_sections_inverted.cf +++ b/examples/mustache_sections_inverted.cf @@ -1,18 +1,17 @@ # Example showing how inverted sections are rendered - #+begin_src cfengine3 bundle agent main { reports: "CFEngine $(with)" - with => string_mustache("{{^classes.enterprise_edition}}Community{{/classes.enterprise_edition}}{{#classes.enterprise_edition}}Enterprise{{/classes.example}}", - datastate()); + with => string_mustache( + "{{^classes.enterprise_edition}}Community{{/classes.enterprise_edition}}{{#classes.enterprise_edition}}Enterprise{{/classes.example}}", + datastate() + ); } #+end_src - #+begin_src example_output #@ ``` #@ R: CFEngine Community #@ ``` #+end_src - diff --git a/examples/mustache_sections_non_empty_list.cf b/examples/mustache_sections_non_empty_list.cf index 8b7477315f..525591ef60 100644 --- a/examples/mustache_sections_non_empty_list.cf +++ b/examples/mustache_sections_non_empty_list.cf @@ -1,5 +1,4 @@ # Example showing how variables are rendered for non empty lists. - #+begin_src cfengine3 bundle agent main { @@ -7,15 +6,11 @@ bundle agent main "data" data => '{ "list": [ "1", "2", "3" ] }'; reports: - "$(with)" - with => string_mustache("{{#list}} {{{.}}}{{/list}}", - data); + "$(with)" with => string_mustache("{{#list}} {{{.}}}{{/list}}", data); } #+end_src - #+begin_src example_output #@ ``` #@ R: 1 2 3 #@ ``` #+end_src - diff --git a/examples/mustache_sections_non_false_value.cf b/examples/mustache_sections_non_false_value.cf index 6ebfa28294..990ca130be 100644 --- a/examples/mustache_sections_non_false_value.cf +++ b/examples/mustache_sections_non_false_value.cf @@ -1,21 +1,19 @@ # Example showing how sections are rendered for non-false - #+begin_src cfengine3 bundle agent main { vars: - "data" data => parsejson('{ "classes": { "example": true } }'); + "data" data => parsejson('{ "classes": { "example": true } }'); reports: - "$(with)" - with => string_mustache("{{#classes.example}}This is an example.{{/classes.example}}", - data); + "$(with)" + with => string_mustache( + "{{#classes.example}}This is an example.{{/classes.example}}", data + ); } #+end_src - #+begin_src example_output #@ ``` #@ R: This is an example. #@ ``` #+end_src - diff --git a/examples/mustache_set_delimiters.cf b/examples/mustache_set_delimiters.cf index f56441d826..7ce1241b6c 100644 --- a/examples/mustache_set_delimiters.cf +++ b/examples/mustache_set_delimiters.cf @@ -1,5 +1,4 @@ # Example showing how delimeters can be customized - #+begin_src cfengine3 bundle agent main { @@ -7,15 +6,11 @@ bundle agent main "data" data => '{ "key": "value of key in data" }'; reports: - "$(with)" - with => string_mustache("{{=<% %>=}}key has <% key %>", - data); + "$(with)" with => string_mustache("{{=<% %>=}}key has <% key %>", data); } #+end_src - #+begin_src example_output #@ ``` #@ R: key has value of key in data #@ ``` #+end_src - diff --git a/examples/mustache_template_motd.cf b/examples/mustache_template_motd.cf index bd3816d4db..5aaf277e36 100644 --- a/examples/mustache_template_motd.cf +++ b/examples/mustache_template_motd.cf @@ -2,86 +2,91 @@ bundle agent env_classification # @brief Classify environment { vars: - # We use presence of key files to know the hosts environment - "environment_semaphores" slist => { "/etc/prod", "/etc/staging" }; - "environment" - string => ifelse( filesexist( @(environment_semaphores) ), "incoherent", - fileexists("/etc/prod"), "production", - fileexists("/etc/staging"), "staging", - "unknown" ); - "env_issue_msg" - string => ifelse( strcmp( "incoherent", $(environment) ), - "WARNING: Environment incoherent (multiple environment semaphores)", - strcmp( "unknown", $(environment) ), - "WARNING: Environment unknown (missing environment semaphores)", - "Host environment classified as $(environment)"); - - # This is to extract the cfengine role ( hub or client ) - "cf_role" - string => ifelse( "policy_server", "Policy Server", "Policy Client"); + # We use presence of key files to know the hosts environment + "environment_semaphores" slist => { "/etc/prod", "/etc/staging" }; + + "environment" + string => ifelse( + filesexist(@(environment_semaphores)), + "incoherent", + fileexists("/etc/prod"), + "production", + fileexists("/etc/staging"), + "staging", + "unknown" + ); + + "env_issue_msg" + string => ifelse( + strcmp("incoherent", $(environment)), + "WARNING: Environment incoherent (multiple environment semaphores)", + strcmp("unknown", $(environment)), + "WARNING: Environment unknown (missing environment semaphores)", + "Host environment classified as $(environment)" + ); + + # This is to extract the cfengine role ( hub or client ) + "cf_role" + string => ifelse("policy_server", "Policy Server", "Policy Client"); classes: - - # We define a class for the selected environment. It's useful for making - # decisions in other policies - - "env_$(environment)" - expression => "any", - scope => "namespace"; - + # We define a class for the selected environment. It's useful for making + # decisions in other policies + "env_$(environment)" + expression => "any", + scope => "namespace"; } + bundle agent env_info # @brief Relevant environment information { vars: - ## Based on the environment we define different contacts. - "admin_contact" - slist => { "admin@acme.com", "oncall@acme.com" }, - if => strcmp( $(env_classification.environment), "production" ); + ## Based on the environment we define different contacts. + "admin_contact" + slist => { "admin@acme.com", "oncall@acme.com" }, + if => strcmp($(env_classification.environment), "production"); - "admin_contact" - slist => { "dev@acme.com" }, - if => strcmp( $(env_classification.environment), "staging" ); + "admin_contact" + slist => { "dev@acme.com" }, + if => strcmp($(env_classification.environment), "staging"); - "admin_contact" - slist => { "root@localhost" }, - if => strcmp( $(env_classification.environment), "unknown" ); + "admin_contact" + slist => { "root@localhost" }, + if => strcmp($(env_classification.environment), "unknown"); - ## This is to extract the available package updates status - "updates_available" - data => packageupdatesmatching(".*", ".*", ".*", ".*"); - "count_updates" int => length("updates_available"); + ## This is to extract the available package updates status + "updates_available" data => packageupdatesmatching(".*", ".*", ".*", ".*"); + "count_updates" int => length("updates_available"); classes: - - # We define a class indicating there are updates available, it might be - # useful for various different policies. - - "have_updates_available" - expression => isgreaterthan( $(count_updates), 0), - scope => "namespace"; - + # We define a class indicating there are updates available, it might be + # useful for various different policies. + "have_updates_available" + expression => isgreaterthan($(count_updates), 0), + scope => "namespace"; } -bundle agent motd { +bundle agent motd +{ vars: - "motd_path" string => "/etc/motd"; - - # It's considered best practice to prepare a data container holding the - # information you need to render the template instead of relying on - # current datastate() - - # First we extract currently defined classes from datastate(), then we - # construct the template data. - - "_state" data => datastate(), - if => not( isvariable ( $(this.promiser) ) ); # Limit recursive growth - # and multiple calls to - # datastate() over - # multiple passes. - - "template_data" - data => mergedata('{ "fqhost": "$(sys.fqhost)", + "motd_path" string => "/etc/motd"; + + # It's considered best practice to prepare a data container holding the + # information you need to render the template instead of relying on + # current datastate() + # First we extract currently defined classes from datastate(), then we + # construct the template data. + "_state" + data => datastate(), + if => not(isvariable($(this.promiser))); + + # Limit recursive growth + # and multiple calls to + # datastate() over + # multiple passes. + "template_data" + data => mergedata( + '{ "fqhost": "$(sys.fqhost)", "primary_ip": "$(sys.ipv4)", "cf_version": "$(sys.cf_version)", "issue_msg": "$(env_classification.env_issue_msg)", @@ -89,14 +94,15 @@ bundle agent motd { "count_updates": "$(env_info.count_updates)", "contacts": env_info.admin_contact, "classes": _state[classes] - }'); + }' + ); files: - "$(motd_path)" - create => "true", - template_method => "inline_mustache", - template_data => @(template_data), - edit_template_string => '# Managed by CFEngine + "$(motd_path)" + create => "true", + template_method => "inline_mustache", + template_data => @(template_data), + edit_template_string => '# Managed by CFEngine {{{issue_msg}}} *** *** Welcome to {{{fqhost}}} @@ -112,12 +118,12 @@ bundle agent motd { * * For support contact:{{#contacts}} - {{{.}}}{{/contacts}}$(const.n)'; - } + bundle agent __main__ { methods: - "env_classification"; - "env_info"; - "motd"; + "env_classification"; + "env_info"; + "motd"; } diff --git a/examples/mustache_variables.cf b/examples/mustache_variables.cf index 72e083fc99..f037aa0697 100644 --- a/examples/mustache_variables.cf +++ b/examples/mustache_variables.cf @@ -1,5 +1,4 @@ # Example showing how sections are rendered. - #+begin_src cfengine3 bundle agent main { @@ -9,14 +8,14 @@ bundle agent main reports: "$(with)" with => string_mustache( -"{{key}} + "{{key}} {{{key}}} {{&key}} Missing '{{missing}}' varibles render empty strings.", - data); + data + ); } #+end_src - #+begin_src example_output #@ ``` #@ R: Hello World & 3>2! @@ -25,4 +24,3 @@ Missing '{{missing}}' varibles render empty strings.", #@ Missing '' varibles render empty strings. #@ ``` #+end_src - diff --git a/examples/namespace_bodies.cf b/examples/namespace_bodies.cf index dc2f18b16b..e88282f07b 100644 --- a/examples/namespace_bodies.cf +++ b/examples/namespace_bodies.cf @@ -1,44 +1,45 @@ bundle agent __main__ { methods: - "example_space:main"; + "example_space:main"; } + body file control { - namespace => "example_space"; + namespace => "example_space"; } bundle agent main { - reports: - # Use the 'first_line' printfile body from the current namespace - "Specifying a body without explict namespace assumes the same namespace.$(const.n)Show me the first 1 line of this file" - printfile => first_line( $(this.promise_filename) ); - - # Use the 'first_two_lines' printfile body from the 'default' namespace - "Forgetting to prefix bodies with 'default:' is a common mistake when using the standard library.$(const.n)Show me the first 2 line of this file" - printfile => default:first_two_lines( $(this.promise_filename) ); + # Use the 'first_line' printfile body from the current namespace + "Specifying a body without explict namespace assumes the same namespace.$(const.n)Show me the first 1 line of this file" + printfile => first_line($(this.promise_filename)); + # Use the 'first_two_lines' printfile body from the 'default' namespace + "Forgetting to prefix bodies with 'default:' is a common mistake when using the standard library.$(const.n)Show me the first 2 line of this file" + printfile => default:first_two_lines($(this.promise_filename)); } body printfile first_line(file) # @brief Report the first 1 lines of a file # @param file The full path of the file to report { - file_to_print => "$(file)"; - number_of_lines => "1"; + file_to_print => "$(file)"; + number_of_lines => "1"; } + body file control { - namespace => "default"; + namespace => "default"; } + body printfile first_two_lines(file) # @brief Report the first 2 lines of a file # @param file The full path of the file to report { - file_to_print => "$(file)"; - number_of_lines => "2"; + file_to_print => "$(file)"; + number_of_lines => "2"; } ############################################################################### #+begin_src example_output diff --git a/examples/namespace_classes.cf b/examples/namespace_classes.cf index 38681afd55..52eb45e913 100644 --- a/examples/namespace_classes.cf +++ b/examples/namespace_classes.cf @@ -1,10 +1,9 @@ bundle agent __main__ { methods: - "mynamespace:my_bundle"; + "mynamespace:my_bundle"; reports: - a_bundle_scoped_class_in_my_namespaced_bundle:: "In $(this.namespace):$(this.bundle) I see 'a_bundle_scoped_class_in_my_namespaced_bundle::'"; @@ -29,19 +28,16 @@ bundle agent __main__ body file control { - namespace => "mynamespace"; + namespace => "mynamespace"; } bundle agent my_bundle { classes: - "a_bundle_scoped_class_in_my_namespaced_bundle"; - - "a_namespace_scoped_class_in_my_namespaced_bundle" - scope => "namespace"; + "a_bundle_scoped_class_in_my_namespaced_bundle"; + "a_namespace_scoped_class_in_my_namespaced_bundle" scope => "namespace"; reports: - a_bundle_scoped_class_in_my_namespaced_bundle:: "In $(this.namespace):$(this.bundle) I see 'a_bundle_scoped_class_in_my_namespaced_bundle::'"; @@ -76,4 +72,3 @@ bundle agent my_bundle #@ R: In default:main I see 'mynamespace:a_namespace_scoped_class_in_my_namespaced_bundle::' #@ ``` #+end_src - diff --git a/examples/namespace_declaration.cf b/examples/namespace_declaration.cf index 1a85e5e5d8..43c0ed6372 100644 --- a/examples/namespace_declaration.cf +++ b/examples/namespace_declaration.cf @@ -1,57 +1,51 @@ # By default we are in the default namespace - bundle agent __main__ { methods: - "Main in my_namespace namespace" - usebundle => my_namespace:main; - - "Main in your_namespace namespace" - usebundle => your_namespace:main; - - "my_bundle in default namespace" - usebundle => my_bundle; + "Main in my_namespace namespace" usebundle => my_namespace:main; + "Main in your_namespace namespace" usebundle => your_namespace:main; + "my_bundle in default namespace" usebundle => my_bundle; reports: - "Inside $(this.namespace):$(this.bundle)"; + "Inside $(this.namespace):$(this.bundle)"; } body file control # From here until the next namespace declaration all bundles and bodies are # defined in my_namespace. { - namespace => "my_namespace"; + namespace => "my_namespace"; } bundle agent main { reports: - "Inside $(this.namespace):$(this.bundle)"; + "Inside $(this.namespace):$(this.bundle)"; } body file control # From here until the next namespace declaration all bundles and bodies are # defined in your_namespace. { - namespace => "your_namespace"; + namespace => "your_namespace"; } bundle agent main { reports: - "Inside $(this.namespace):$(this.bundle)"; + "Inside $(this.namespace):$(this.bundle)"; } body file control # From here until the next namespace declaration we return to the default namespace. { - namespace => "default"; + namespace => "default"; } bundle agent my_bundle { reports: - "Inside $(this.namespace):$(this.bundle)"; + "Inside $(this.namespace):$(this.bundle)"; } ############################################################################### #+begin_src example_output diff --git a/examples/namespace_hard_classes.cf b/examples/namespace_hard_classes.cf index 4a8bd578fd..fc47250045 100644 --- a/examples/namespace_hard_classes.cf +++ b/examples/namespace_hard_classes.cf @@ -1,7 +1,7 @@ bundle agent __main__ { methods: - "example:my_bundle"; + "example:my_bundle"; reports: cfengine:: @@ -11,12 +11,12 @@ bundle agent __main__ "From the '$(this.namespace)' namespace the class expression 'default:cfengine::' evaluates true"; "The class 'cfengine' has tags: $(with)" - with => join( ", ", getclassmetatags( "cfengine" ) ); + with => join(", ", getclassmetatags("cfengine")); } body file control { - namespace => "example"; + namespace => "example"; } bundle agent my_bundle diff --git a/examples/namespace_methods-usebundle.cf b/examples/namespace_methods-usebundle.cf index fe1d8f7d7d..d3f590a666 100644 --- a/examples/namespace_methods-usebundle.cf +++ b/examples/namespace_methods-usebundle.cf @@ -1,32 +1,36 @@ bundle agent __main__ { methods: - # Call the bundle named main within the example_space namespace. - "example_space:main"; + # Call the bundle named main within the example_space namespace. + "example_space:main"; } + body file control { - namespace => "example_space"; + namespace => "example_space"; } bundle agent main { methods: - # Call the bundle 'my_bundle' within the current namespace - "When not specified, we assume you are refering to a bundle or body within the same namespace" - usebundle => my_bundle( "Called 'my_bundle' from $(this.namespace):$(this.bundle) (the same namespace)."); + # Call the bundle 'my_bundle' within the current namespace + "When not specified, we assume you are refering to a bundle or body within the same namespace" + usebundle => my_bundle( + "Called 'my_bundle' from $(this.namespace):$(this.bundle) (the same namespace)." + ); - # Call the bundle 'my_bundle' from the 'example_space' namespace - "When explicitly specified, the policy reader has less congnitive burden" - usebundle => example_space:my_bundle( "Called 'example_space:my_bundle' $(this.namespace):$(this.bundle) (the same namespace)."); + # Call the bundle 'my_bundle' from the 'example_space' namespace + "When explicitly specified, the policy reader has less congnitive burden" + usebundle => example_space:my_bundle( + "Called 'example_space:my_bundle' $(this.namespace):$(this.bundle) (the same namespace)." + ); } bundle agent my_bundle(string) { reports: - "In $(this.namespace):$(this.bundle)" - handle => "$(string)"; - "$(string)"; + "In $(this.namespace):$(this.bundle)" handle => "$(string)"; + "$(string)"; } ############################################################################### #+begin_src example_output diff --git a/examples/namespace_special_var_exception.cf b/examples/namespace_special_var_exception.cf index c4ba9cc83b..55ae02ba4d 100644 --- a/examples/namespace_special_var_exception.cf +++ b/examples/namespace_special_var_exception.cf @@ -1,17 +1,20 @@ bundle agent __main__ { - methods: "special_variables_example:demo"; + methods: + "special_variables_example:demo"; } + body file control { - namespace => "special_variables_example"; + namespace => "special_variables_example"; } + bundle agent demo { reports: - "Special Variables live in the default namespace but don't have to be fully qualified when referenced ..."; - "In $(this.namespace):$(this.bundle) $(const.dollar)(sys.cf_version_major) == $(sys.cf_version_major)"; - "In $(this.namespace):$(this.bundle) $(default:const.dollar)(default:sys.cf_version_major) == $(default:sys.cf_version_major)"; + "Special Variables live in the default namespace but don't have to be fully qualified when referenced ..."; + "In $(this.namespace):$(this.bundle) $(const.dollar)(sys.cf_version_major) == $(sys.cf_version_major)"; + "In $(this.namespace):$(this.bundle) $(default:const.dollar)(default:sys.cf_version_major) == $(default:sys.cf_version_major)"; } ############################################################################### #+begin_src example_output diff --git a/examples/namespace_var_meta.cf b/examples/namespace_var_meta.cf index 09d6a95979..f2b8925557 100644 --- a/examples/namespace_var_meta.cf +++ b/examples/namespace_var_meta.cf @@ -1,24 +1,18 @@ - body common control { - bundlesequence => { "main" }; - version => "0.1"; - inputs => { "namespace_var_meta2.cf"}; + bundlesequence => { "main" }; + version => "0.1"; + inputs => { "namespace_var_meta2.cf" }; } bundle agent main { - classes: - - "abc" expression => "any"; - + "abc" expression => "any"; methods: - - "bla" usebundle => fred:example; + "bla" usebundle => fred:example; reports: - "remote var: $(fred:example.bundle_version)"; - + "remote var: $(fred:example.bundle_version)"; } diff --git a/examples/namespace_var_meta2.cf b/examples/namespace_var_meta2.cf index 63c723372c..0333181088 100644 --- a/examples/namespace_var_meta2.cf +++ b/examples/namespace_var_meta2.cf @@ -1,25 +1,18 @@ - body file control { - namespace => "fred"; + namespace => "fred"; } - bundle agent example - -{ +{ vars: - - "bundle_version" string => "4.5.6"; + "bundle_version" string => "4.5.6"; meta: - - "bundle_version" string => "1.2.3"; - "works_with_cfengine" string => "3.4.0"; + "bundle_version" string => "1.2.3"; + "works_with_cfengine" string => "3.4.0"; reports: - "Not a local variable: $(bundle_version)"; - "Meta data (variable): $(example_meta.bundle_version)"; - + "Not a local variable: $(bundle_version)"; + "Meta data (variable): $(example_meta.bundle_version)"; } - diff --git a/examples/namespace_variable_references.cf b/examples/namespace_variable_references.cf index b556f0afbb..58eb6dafe4 100644 --- a/examples/namespace_variable_references.cf +++ b/examples/namespace_variable_references.cf @@ -1,20 +1,24 @@ bundle agent __main__ { - methods: "example:demo"; + methods: + "example:demo"; } + body file control { - namespace => "example"; + namespace => "example"; } + bundle agent demo { vars: - "color" string => "#f5821f"; + "color" string => "#f5821f"; reports: - "Unqualified: The color is $(color)"; - # ENT-8817 "Bundle-qualified: The color is $(demo.color)"; - "Fully-qualified: The color is $(example:demo.color)"; + "Unqualified: The color is $(color)"; + + # ENT-8817 "Bundle-qualified: The color is $(demo.color)"; + "Fully-qualified: The color is $(example:demo.color)"; } ############################################################################### #+begin_src example_output diff --git a/examples/neighbourhood_watch.cf b/examples/neighbourhood_watch.cf index cc5282345a..9550b96298 100644 --- a/examples/neighbourhood_watch.cf +++ b/examples/neighbourhood_watch.cf @@ -1,96 +1,73 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - ######################################################## # # Change detect # ######################################################## - body common control - { - bundlesequence => { "neighbourhood_watch" }; + bundlesequence => { "neighbourhood_watch" }; } - ######################################################## - bundle agent neighbourhood_watch - { vars: - - "neighbours" slist => peers("/var/cfengine/inputs/hostlist","#.*",4); + "neighbours" slist => peers("/var/cfengine/inputs/hostlist", "#.*", 4); files: - - # Redundant cross monitoring ....................................... - - "$(sys.workdir)/nw/$(neighbours)_checksum_digests.db" - + # Redundant cross monitoring ....................................... + "$(sys.workdir)/nw/$(neighbours)_checksum_digests.db" comment => "Watch our peers remote hash tables and keep a local copy", - copy_from => rcp("$(sys.workdir)/checksum_digests.db",$(neighbours)), + copy_from => rcp("$(sys.workdir)/checksum_digests.db", $(neighbours)), depends_on => { "grant_hash_tables" }; - # Define the actual children to watch over ......................... - - "/usr/bin" - - comment => "Watch over the system binaries - changes are mostly updates", - changes => lay_trip_wire, + # Define the actual children to watch over ......................... + "/usr/bin" + comment => "Watch over the system binaries - changes are mostly updates", + changes => lay_trip_wire, depth_search => recurse("inf"), - action => measure; - + action => measure; } - ######################################################### - body changes lay_trip_wire { - hash => "best"; - report_changes => "content"; - update_hashes => "yes"; + hash => "best"; + report_changes => "content"; + update_hashes => "yes"; } - ######################################################### - -body copy_from rcp(from,server) - +body copy_from rcp(from, server) { - servers => { "$(server)" }; - source => "$(from)"; - compare => "digest"; - encrypt => "false"; + servers => { "$(server)" }; + source => "$(from)"; + compare => "digest"; + encrypt => "false"; } - ########################################################## - body depth_search recurse(d) - { - depth => "$(d)"; + depth => "$(d)"; } body action measure { - measurement_class => "$(this.promiser) long job scan of /usr"; + measurement_class => "$(this.promiser) long job scan of /usr"; } diff --git a/examples/none.cf b/examples/none.cf index faceb576a5..3b48051a1c 100644 --- a/examples/none.cf +++ b/examples/none.cf @@ -1,73 +1,88 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - #+begin_src cfengine3 body common control { - bundlesequence => { "example" }; + bundlesequence => { "example" }; } bundle agent example { classes: - "none11" expression => none("jebadiah", test1); - "none12" expression => none("2", test1); - "none21" expression => none("jebadiah", test2); - "none22" expression => none("2", test2); + "none11" expression => none("jebadiah", test1); + "none12" expression => none("2", test1); + "none21" expression => none("jebadiah", test2); + "none22" expression => none("2", test2); vars: - "test1" slist => { - 1,2,3, - "one", "two", "three", - "long string", - "four", "fix", "six", - "one", "two", "three", + "test1" + slist => { + 1, + 2, + 3, + "one", + "two", + "three", + "long string", + "four", + "fix", + "six", + "one", + "two", + "three", }; - - "test2" data => parsejson('[1,2,3, + "test2" + data => parsejson( + '[1,2,3, "one", "two", "three", "long string", "four", "fix", "six", - "one", "two", "three",]'); + "one", "two", "three",]' + ); reports: - "The test1 list is $(test1)"; + "The test1 list is $(test1)"; + none11:: "none() test1 1 passed"; + !none11:: "none() test1 1 failed"; + none12:: "none() test1 2 failed"; + !none12:: "none() test1 2 passed"; - "The test2 list is $(test2)"; + none21:: "none() test2 1 passed"; + !none21:: "none() test2 1 failed"; + none22:: "none() test2 2 failed"; + !none22:: "none() test2 2 passed"; } diff --git a/examples/nth-key.cf b/examples/nth-key.cf index e9363c9e17..4f87ae873b 100644 --- a/examples/nth-key.cf +++ b/examples/nth-key.cf @@ -2,13 +2,13 @@ bundle agent main { vars: - "d" data => '{ "key1": "dvalue1", "key2": "dvalue2" }'; - "a[key1]" string => "value1"; - "a[key2]" string => "value2"; + "d" data => '{ "key1": "dvalue1", "key2": "dvalue2" }'; + "a[key1]" string => "value1"; + "a[key2]" string => "value2"; reports: - "$(with)" with => nth( a, "key1" ); - "$(with)" with => nth( d, "key1" ); + "$(with)" with => nth(a, "key1"); + "$(with)" with => nth(d, "key1"); } #+end_src ############################################################################### diff --git a/examples/nth.cf b/examples/nth.cf index 2e36739cb4..1d6a72a4a2 100644 --- a/examples/nth.cf +++ b/examples/nth.cf @@ -1,76 +1,75 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - #+begin_src cfengine3 body common control { - bundlesequence => { "test" }; + bundlesequence => { "test" }; } bundle agent test { vars: - "test" slist => { - 1,2,3, - "one", "two", "three", - "long string", - "four", "fix", "six", - "one", "two", "three", + "test" + slist => { + 1, + 2, + 3, + "one", + "two", + "three", + "long string", + "four", + "fix", + "six", + "one", + "two", + "three", }; - "test_str" string => format("%S", test); - - "test2" data => parsejson("[1, 2, 3, null]"); - "test2_str" string => format("%S", test2); - - "test3" data => parsejson('{ "x": true, "y": "z" }'); - "test3_str" string => format("%S", test3); - - "nth" slist => { 1, 2, 6, 10, 11, 1000 }; - "nth2" slist => getindices(test2); - "nth3" slist => getindices(test3); - - "access[$(nth)]" string => nth(test, $(nth)); - "access[0]" string => nth(test, 0); - - "access2[$(nth2)]" string => nth(test2, $(nth2)); - "access3[$(nth3)]" string => nth(test3, $(nth3)); - - "nth_neg1" string => nth(test, "-1"); - "nth_neg100" string => nth(test, "-100"); # invalid index position requested + "test_str" string => format("%S", test); + "test2" data => parsejson("[1, 2, 3, null]"); + "test2_str" string => format("%S", test2); + "test3" data => parsejson('{ "x": true, "y": "z" }'); + "test3_str" string => format("%S", test3); + "nth" slist => { 1, 2, 6, 10, 11, 1000 }; + "nth2" slist => getindices(test2); + "nth3" slist => getindices(test3); + "access[$(nth)]" string => nth(test, $(nth)); + "access[0]" string => nth(test, 0); + "access2[$(nth2)]" string => nth(test2, $(nth2)); + "access3[$(nth3)]" string => nth(test3, $(nth3)); + "nth_neg1" string => nth(test, "-1"); + "nth_neg100" string => nth(test, "-100"); + # invalid index position requested reports: - "The test list is $(test_str)"; - "element #$(nth) of the test list: $(access[$(nth)])"; - "element #0 of the test list: $(access[0])"; - - "The test2 data container is $(test2_str)"; - "element #$(nth2) of the test2 data container: $(access2[$(nth2)])"; - - "The test3 data container is $(test3_str)"; - "element #$(nth3) of the test3 data container: $(access3[$(nth3)])"; - - "The last element of test is $(nth_neg1)"; - "nth_neg100 is not defined, because an invalid index was requested" - if => not( isvariable( nth_neg100 )); + "The test list is $(test_str)"; + "element #$(nth) of the test list: $(access[$(nth)])"; + "element #0 of the test list: $(access[0])"; + "The test2 data container is $(test2_str)"; + "element #$(nth2) of the test2 data container: $(access2[$(nth2)])"; + "The test3 data container is $(test3_str)"; + "element #$(nth3) of the test3 data container: $(access3[$(nth3)])"; + "The last element of test is $(nth_neg1)"; + + "nth_neg100 is not defined, because an invalid index was requested" + if => not(isvariable(nth_neg100)); } #+end_src ############################################################################### diff --git a/examples/null_config.cf b/examples/null_config.cf index 7a8ac3d705..fd1850b5fb 100644 --- a/examples/null_config.cf +++ b/examples/null_config.cf @@ -1,42 +1,34 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - ####################################################### # # The starting point for every configuration # ####################################################### - body common control - { - bundlesequence => { "example" }; + bundlesequence => { "example" }; } - ####################################################### - bundle agent example - { reports: - "This is a test bundle"; + "This is a test bundle"; } diff --git a/examples/orchestrate_chain1.cf b/examples/orchestrate_chain1.cf index 474f9f2bc0..36f85d18d1 100644 --- a/examples/orchestrate_chain1.cf +++ b/examples/orchestrate_chain1.cf @@ -8,61 +8,60 @@ # to add host1 host2 host3 host4 as aliases to localhost # ############################################################ - body common control { - bundlesequence => { "weak_dependency_symphony" }; - inputs => { "$(sys.libdir)/stdlib.cf" }; + bundlesequence => { "weak_dependency_symphony" }; + inputs => { "$(sys.libdir)/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 - + # We have to seed the beginning by creating the tower + # /tmp/tower_localhost host1:: - "tower" usebundle => tier1, - classes => publish_ok("ok_O"); + "tower" + usebundle => tier1, + classes => publish_ok("ok_O"); host2:: - "tower" usebundle => tier2, - classes => publish_ok("ok_1"); + "tower" + usebundle => tier2, + classes => publish_ok("ok_1"); host3:: - "tower" usebundle => tier3, - classes => publish_ok("ok_2"); + "tower" + usebundle => tier3, + classes => publish_ok("ok_2"); host4:: - "tower" usebundle => tier4, - classes => publish_ok("ok_f"); + "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"); + 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"; @@ -72,62 +71,43 @@ bundle agent weak_dependency_symphony !(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"; + "/tmp/something_to_do_1" create => "true"; } bundle agent tier2 { files: - - "/tmp/something_to_do_2" - create => "true"; + "/tmp/something_to_do_2" create => "true"; } bundle agent tier3 { files: - - "/tmp/something_to_do_3" - create => "true"; - + "/tmp/something_to_do_3" create => "true"; } bundle agent tier4 { files: - - "/tmp/something_to_do_4" - create => "true"; + "/tmp/something_to_do_4" create => "true"; } - ############################################################ - - bundle server access_rules() { access: - - "ok.*" + "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"; } - diff --git a/examples/orchestrate_chain2.cf b/examples/orchestrate_chain2.cf index 8a6ad85bd1..cea3e1af89 100644 --- a/examples/orchestrate_chain2.cf +++ b/examples/orchestrate_chain2.cf @@ -8,119 +8,94 @@ # to add host1 host2 host3 host4 as aliases to localhost # ############################################################ - body common control { - bundlesequence => { "weak_dependency_symphony" }; - inputs => { "$(sys.libdir)/stdlib.cf" }; + bundlesequence => { "weak_dependency_symphony" }; + inputs => { "$(sys.libdir)/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 - + # We have to seed the beginning by creating the tower + # /tmp/tower_localhost host1:: - "tower" usebundle => tier1, - classes => publish_ok("ok_O"); + "tower" + usebundle => tier1, + classes => publish_ok("ok_O"); host2:: - "tower" usebundle => tier2, - classes => publish_ok("ok_1"); + "tower" + usebundle => tier2, + classes => publish_ok("ok_1"); host3:: - "tower" usebundle => tier3, - classes => publish_ok("ok_2"); + "tower" + usebundle => tier3, + classes => publish_ok("ok_2"); host4:: - "tower" usebundle => tier4, - classes => publish_ok("ok_f"); + "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"); + 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&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"; + "/tmp/something_to_do_1" create => "true"; } bundle agent tier2 { files: - - "/tmp/something_to_do_2" - create => "true"; + "/tmp/something_to_do_2" create => "true"; } bundle agent tier3 { files: - - "/tmp/something_to_do_3" - create => "true"; - + "/tmp/something_to_do_3" create => "true"; } bundle agent tier4 { files: - - "/tmp/something_to_do_4" - create => "true"; + "/tmp/something_to_do_4" create => "true"; } - ############################################################ - - bundle server access_rules() { access: - - "ok.*" + "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 => "5"; + promise_repaired => { "$(x)" }; + promise_kept => { "$(x)" }; + cancel_notkept => { "$(x)" }; + persist_time => "5"; } - diff --git a/examples/orchestrate_delay_trigger.cf b/examples/orchestrate_delay_trigger.cf index d4c1a202dc..26a9f7c784 100644 --- a/examples/orchestrate_delay_trigger.cf +++ b/examples/orchestrate_delay_trigger.cf @@ -1,81 +1,66 @@ -# # Time based orchestration -# - body common control { - bundlesequence => { "example" }; - inputs => { "$(sys.libdir)/stdlib.cf" }; + bundlesequence => { "example" }; + inputs => { "$(sys.libdir)/stdlib.cf" }; } - ########################################### - bundle common orchestrate { vars: - - # Must have delay < reset_time - - "reset_time" int => "2"; - "delay" int => "1"; + # Must have delay < reset_time + "reset_time" int => "2"; + "delay" int => "1"; } - ########################################### - bundle agent example { methods: - - "immediate" usebundle => one, + "immediate" + usebundle => one, classes => if_repaired_persist("countdown", "$(orchestrate.delay)"), if => "!one"; - "delayed" usebundle => two, + "delayed" + usebundle => two, if => "one.!countdown"; reports: - countdown:: "Counting down ... $(sys.date)"; } - ########################################### - bundle agent one { reports: - - "One = $(this.bundle) at $(sys.date)" - classes => if_repaired_persist("$(this.bundle)", "$(orchestrate.reset_time)"), + "One = $(this.bundle) at $(sys.date)" + classes => if_repaired_persist( + "$(this.bundle)", "$(orchestrate.reset_time)" + ), action => if_elapsed("0"); - "Set class $(this.bundle)" - if => "$(this.bundle)"; + "Set class $(this.bundle)" if => "$(this.bundle)"; } - ########################################## - bundle agent two { reports: - - "Two = $(this.bundle) at $(sys.date)" - classes => if_repaired_persist("$(this.bundle)", "$(orchestrate.reset_time)"), + "Two = $(this.bundle) at $(sys.date)" + classes => if_repaired_persist( + "$(this.bundle)", "$(orchestrate.reset_time)" + ), action => if_elapsed("0"); - "Set class $(this.bundle)" - if => "$(this.bundle)"; + "Set class $(this.bundle)" if => "$(this.bundle)"; } - ########################################### - -body classes if_repaired_persist(x,t) +body classes if_repaired_persist(x, t) { - promise_repaired => { "$(x)" }; - persist_time => "$(t)"; + promise_repaired => { "$(x)" }; + persist_time => "$(t)"; } body classes cancel_persist(x) { - cancel_repaired => { "$(x)" }; + cancel_repaired => { "$(x)" }; } diff --git a/examples/orchestrate_dominoes1.cf b/examples/orchestrate_dominoes1.cf index 2eba58658b..f13979c5b8 100644 --- a/examples/orchestrate_dominoes1.cf +++ b/examples/orchestrate_dominoes1.cf @@ -8,101 +8,79 @@ # to add host1 host2 host3 host4 as aliases to localhost # ############################################################ - body common control { - bundlesequence => { "dominoes_symphony" }; - inputs => { "$(sys.libdir)/stdlib.cf" }; + bundlesequence => { "dominoes_symphony" }; + inputs => { "$(sys.libdir)/stdlib.cf" }; } - ############################################################ - bundle agent dominoes_symphony { methods: - - # We have to seed the beginning by creating the dominoes - # /tmp/dominoes_localhost - + # We have to seed the beginning by creating the dominoes + # /tmp/dominoes_localhost host1:: - "dominoes" usebundle => hand_over("localhost","host1","overture"); + "dominoes" usebundle => hand_over("localhost", "host1", "overture"); host2:: - "dominoes" usebundle => hand_over("host1","host2","first movement"); + "dominoes" usebundle => hand_over("host1", "host2", "first movement"); host3:: - "dominoes" usebundle => hand_over("host2","host3","second movement"); + "dominoes" usebundle => hand_over("host2", "host3", "second movement"); host4:: - "dominoes" usebundle => hand_over("host3","host4","final movement"), - classes => if_ok("finale"); + "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"); - + 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 - + # This is a wrapper for the orchestration files: - - "/tmp/tip_the_dominoes" - + "/tmp/tip_the_dominoes" comment => "Wait for our cue or relay/conductor baton", - copy_from => secure_cp("/tmp/dominoes_$(predecessor)","$(predecessor)"), + copy_from => secure_cp("/tmp/dominoes_$(predecessor)", "$(predecessor)"), classes => if_repaired("cue_action"); cue_action:: - "/tmp/outcome_of_part" - - comment => "One off activity", - create => "true", - edit_line => append_if_no_line("Do something meaningful by calling $(method)"), - classes => if_ok("pass_the_stick"); + comment => "One off activity", + create => "true", + edit_line => append_if_no_line( + "Do something meaningful by calling $(method)" + ), + classes => if_ok("pass_the_stick"); 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)"); + 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"); - + comment => "Dominoes in position to be beamed up by next agent", + copy_from => local_cp("/tmp/tip_the_dominoes"); } - ############################################################ - bundle server access_rules() { access: + "/tmp" admit => { "127.0.0.1" }; - "/tmp" - - admit => { "127.0.0.1" }; - - "did.*" + "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"; } - diff --git a/examples/orchestrate_dominoes2.cf b/examples/orchestrate_dominoes2.cf index 612cf8165a..675c2ab316 100644 --- a/examples/orchestrate_dominoes2.cf +++ b/examples/orchestrate_dominoes2.cf @@ -8,133 +8,102 @@ # to add host1 host2 host3 host4 as aliases to localhost # ############################################################ - body common control { - bundlesequence => { "dominoes_symphony" }; - inputs => { "$(sys.libdir)/stdlib.cf" }; + bundlesequence => { "dominoes_symphony" }; + inputs => { "$(sys.libdir)/stdlib.cf" }; } - ############################################################ - bundle agent dominoes_symphony { methods: - - # We have to seed the beginning by creating the dominoes - # /tmp/dominoes_localhost - + # We have to seed the beginning by creating the dominoes + # /tmp/dominoes_localhost host1:: - "dominoes" usebundle => hand_over("localhost","host1","overture"); + "dominoes" usebundle => hand_over("localhost", "host1", "overture"); host2:: - "dominoes" usebundle => hand_over("host1","host2","first_movement"); + "dominoes" usebundle => hand_over("host1", "host2", "first_movement"); host3:: - "dominoes" usebundle => hand_over("host2","host3","second_movement"); + "dominoes" usebundle => hand_over("host2", "host3", "second_movement"); host4:: - "dominoes" usebundle => hand_over("host3","host4","final_movement"), - classes => if_ok("finale"); + "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"); - + 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 - + # This is a wrapper for the orchestration files: - - "/tmp/tip_the_dominoes" - + "/tmp/tip_the_dominoes" comment => "Wait for our cue or relay/conductor baton", - copy_from => secure_cp("/tmp/dominoes_$(predecessor)","$(predecessor)"), + 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"); + 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)"); + 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"); - + comment => "Dominoes in position to be beamed up by next agent", + copy_from => local_cp("/tmp/tip_the_dominoes"); } - ############################################################ - bundle agent overture { reports: - "Singing the overture..."; + "Singing the overture..."; } bundle agent first_movement { reports: - "Singing the first adagio..."; + "Singing the first adagio..."; } bundle agent second_movement { reports: - "Singing second allegro..."; - + "Singing second allegro..."; } bundle agent final_movement { reports: - "Trumpets for the finale"; - + "Trumpets for the finale"; } - ############################################################ - - bundle server access_rules() { access: + "/tmp" admit => { "127.0.0.1" }; - "/tmp" - - admit => { "127.0.0.1" }; - - "did.*" + "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"; } - diff --git a/examples/orchestrate_dragon.cf b/examples/orchestrate_dragon.cf index 714e84037d..88ff02b64e 100644 --- a/examples/orchestrate_dragon.cf +++ b/examples/orchestrate_dragon.cf @@ -9,223 +9,165 @@ # to add host1 host2 host3 host4 as aliases to localhost # ############################################################ - body common control { - bundlesequence => { "dragon_symphony" }; - inputs => { "$(sys.libdir)/stdlib.cf" }; + bundlesequence => { "dragon_symphony" }; + inputs => { "$(sys.libdir)/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"), + # 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"); + printfile => visitors_book("/tmp/shoo_dragon_host4"); } - ############################################################ # Define the ############################################################ - bundle agent chapter1(x) { - # Do something significant here - + # Do something significant here reports: - host1:: " ----> Breathing fire on $(x)"; } - ################################ - bundle agent chapter2(x) { - # Do something significant here - + # Do something significant here reports: - host2:: " ----> Breathing fire on $(x)"; - } - ################################ - bundle agent chapter3(x) { - # Do something significant here - + # Do something significant here reports: - host3:: " ----> Breathing fire on $(x)"; - } - ################################ - bundle agent chapter4(x) { - # Do something significant here - + # 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 - + # 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"; + "dragons_lair" string => "host0"; files: - - # We start in the dragon's lair .. - - "/tmp/unleash_dragon" - + # 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" - + # 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)"), + 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" + # 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)"), + copy_from => secure_cp("/tmp/dragon_$(satellite)", "$(dragons_lair)"), classes => if_repaired("cue_action_on_$(satellite)"), if => "$(satellite)"; methods: - - "check in at home" + "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)"; - "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)" + # 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)" + # 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)"), + edit_line => sign_visitor_book( + "Dragon visited $(satellite) and did: $(method)" + ), if => "send_the_dragon_back_from_$(satellite)"; reports: - "Done $(satellite)"; - + "Done $(satellite)"; } - ############################################################ - bundle agent switch_satellite(name) { files: - - "/tmp/enter_the_dragon" + "/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: - " X Switching new dragon's target $(name)"; + " X Switching new dragon's target $(name)"; } - - ############################################################ - bundle edit_line sign_visitor_book(s) { insert_lines: - - "/tmp/enter_the_dragon" + "/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 access_rules() { access: + "/tmp" admit => { "127.0.0.1" }; - "/tmp" - - admit => { "127.0.0.1" }; - - "did.*" + "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/examples/orchestrate_dragon_load_balancer.cf b/examples/orchestrate_dragon_load_balancer.cf index be8f07d44f..25610645bb 100644 --- a/examples/orchestrate_dragon_load_balancer.cf +++ b/examples/orchestrate_dragon_load_balancer.cf @@ -12,296 +12,217 @@ # host1 ON # host2 ON # host3 ON etc - - ############################################################ - body common control { - bundlesequence => { "dragon_symphony" }; - inputs => { "$(sys.libdir)/stdlib.cf" }; + bundlesequence => { "dragon_symphony" }; + inputs => { "$(sys.libdir)/stdlib.cf" }; } - ############################################################ - bundle agent dragon_symphony { methods: - - # We have to seed the beginning by creating the dragon - # /tmp/dragon_localhost - - "dragon" usebundle => upgrade_host("localhost","host1","chapter1"); - - "dragon" usebundle => upgrade_host("host1","host2","chapter2"); - - "dragon" usebundle => upgrade_host("host2","host3","chapter3"); - - "dragon" usebundle => upgrade_host("host3","host4","chapter4"), + # We have to seed the beginning by creating the dragon + # /tmp/dragon_localhost + "dragon" usebundle => upgrade_host("localhost", "host1", "chapter1"); + "dragon" usebundle => upgrade_host("host1", "host2", "chapter2"); + "dragon" usebundle => upgrade_host("host2", "host3", "chapter3"); + + "dragon" + usebundle => upgrade_host("host3", "host4", "chapter4"), classes => if_ok("finale"); finale:: - - "dragon" usebundle => restore_final("host4"), - comment => "Restore all the deactivated satellites"; - + "dragon" + usebundle => restore_final("host4"), + comment => "Restore all the deactivated satellites"; reports: - finale:: - "The dragon is slain!!!" - printfile => visitors_book("/tmp/shoo_dragon_host4"); + printfile => visitors_book("/tmp/shoo_dragon_host4"); "And the switch state is..." - printfile => visitors_book("/tmp/switch_file"); + printfile => visitors_book("/tmp/switch_file"); } - ############################################################ # Define the ############################################################ - bundle agent chapter1(x) { - # Do something significant here - + # Do something significant here reports: - host1:: " ----> Breathing fire on $(x)"; } - ################################ - bundle agent chapter2(x) { - # Do something significant here - + # Do something significant here reports: - host2:: " ----> Breathing fire on $(x)"; - } - ################################ - bundle agent chapter3(x) { - # Do something significant here - + # Do something significant here reports: - host3:: " ----> Breathing fire on $(x)"; - } - ################################ - bundle agent chapter4(x) { - # Do something significant here - + # Do something significant here reports: - host4:: " ----> Breathing fire on $(x)"; - } - ############################################################ # Orchestration wrappers ############################################################ - -bundle agent upgrade_host(predecessor,satellite,method) +bundle agent upgrade_host(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 - + # 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"; + "dragons_lair" string => "host0"; files: - - # We start in the dragon's lair .. - - "/tmp/unleash_dragon" - + # 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" - + # 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)"), + 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" + # 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)"), + copy_from => secure_cp("/tmp/dragon_$(satellite)", "$(dragons_lair)"), classes => if_repaired("cue_action_on_$(satellite)"), if => "$(satellite)"; methods: - - "check in at home" + "check in at home" comment => "Edit the load balancer?", - usebundle => next_host("$(satellite)","$(predecessor)"), + usebundle => next_host("$(satellite)", "$(predecessor)"), classes => if_repaired("send_the_dragon_to_$(satellite)"), if => "dispatch_dragon_$(satellite)"; - "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)" + # 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)" + # 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)"), + edit_line => sign_visitor_book( + "Dragon visited $(satellite) and did: $(method)" + ), if => "send_the_dragon_back_from_$(satellite)"; reports: - - "Done $(satellite)" - if => "$(satellite)"; + "Done $(satellite)" if => "$(satellite)"; } - ############################################################ - -bundle agent next_host(name,pred) +bundle agent next_host(name, pred) { files: - - "/tmp/enter_the_dragon" + "/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)"); - # Edit the switch file - - "/tmp/switch_file" + # Edit the switch file + "/tmp/switch_file" comment => "Restore whatever is missing and comment out", - edit_line => restore_and_comment("$(name)","$(pred)"), + edit_line => restore_and_comment("$(name)", "$(pred)"), classes => if_repaired("reload_switch_$(name)"); reports: - !problem:: - "Returned from $(pred), heading out to $(name)"; " X Restoring $(pred) and switching new dragon's target $(name)" - if => "reload_switch_$(name)"; + if => "reload_switch_$(name)"; } - ############################################################ - bundle agent restore_final(name) { files: - host0:: - "/tmp/switch_file" - comment => "Restore whatever is missing and comment out", - edit_line => restore_and_comment("NONE","$(name)"), - classes => if_repaired("reload_switch"); + comment => "Restore whatever is missing and comment out", + edit_line => restore_and_comment("NONE", "$(name)"), + classes => if_repaired("reload_switch"); reports: - reload_switch:: " X Restoring $(name) to tidy up loose ends"; - } - ############################################################ - bundle edit_line sign_visitor_book(s) { insert_lines: - - "/tmp/enter_the_dragon" + "/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 edit_line restore_and_comment(name,pred) +bundle edit_line restore_and_comment(name, pred) { replace_patterns: - - "$(name) ON" - + "$(name) ON" replace_with => value("$(name) OFF"), comment => "Uncomment the predecessor to reactivate"; - "$(pred) OFF" - + "$(pred) OFF" replace_with => value("$(pred) ON"), comment => "Comment out the new host", classes => if_repaired("show_switch_$(name)"); reports: - !problem:: - "The state of the switch was:" - printfile => visitors_book("/tmp/switch_file"), - if => "show_switch_$(name)"; - - + printfile => visitors_book("/tmp/switch_file"), + if => "show_switch_$(name)"; } - ############################################################ - - bundle server access_rules() { access: + "/tmp" admit => { "127.0.0.1" }; - "/tmp" - - admit => { "127.0.0.1" }; - - "did.*" + "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/examples/orchestrate_n_of_m.cf b/examples/orchestrate_n_of_m.cf index 39ac0a1d41..e06566995b 100644 --- a/examples/orchestrate_n_of_m.cf +++ b/examples/orchestrate_n_of_m.cf @@ -9,54 +9,40 @@ # to add host1 host2 host3 host4 as aliases to localhost # ############################################################ - body common control { - bundlesequence => { "n_of_m_symphony" }; - inputs => { "$(sys.libdir)/stdlib.cf" }; + bundlesequence => { "n_of_m_symphony" }; + inputs => { "$(sys.libdir)/stdlib.cf" }; } - ############################################################ - bundle agent n_of_m_symphony { vars: - - "count_compliant_hosts" string => hubknowledge("running_myprocess"); + "count_compliant_hosts" string => hubknowledge("running_myprocess"); classes: - - "reboot" expression => isgreaterthan("$(count_compliant_hosts)","20"); + "reboot" expression => isgreaterthan("$(count_compliant_hosts)", "20"); processes: - - "myprocess" - + "myprocess" comment => "Count this host if a job is matched", classes => enumerate("running_myprocess"); commands: - reboot:: - "/bin/shutdown now"; } - - ####################################################### - bundle server access_rules() { access: - - "value of my test_scalar, can expand variables here - $(sys.host)" + "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" + "running_myprocess" resource_type => "variable", admit => { "127.0.0.1" }; - } diff --git a/examples/orchestration_hostlist.cf b/examples/orchestration_hostlist.cf index a3381a394b..9bb3773ff2 100644 --- a/examples/orchestration_hostlist.cf +++ b/examples/orchestration_hostlist.cf @@ -1,4 +1,3 @@ -# # Make list of hosts available to all clients, and use it on clients # in order to configure a sample monitoring application that checks # health of all clients. @@ -14,16 +13,14 @@ # # Note that your copy_from statement in failsafe.cf or update.cf must # copy this file also (e.g. not only copy *.cf files in any file_select) - - - body common control { - inputs => { "$(sys.libdir)/stdlib.cf" }; - bundlesequence => { "orchestration_hostlist_update", "orchestration_hostlist_use"}; + inputs => { "$(sys.libdir)/stdlib.cf" }; + bundlesequence => { + "orchestration_hostlist_update", "orchestration_hostlist_use" + }; } - bundle agent orchestration_hostlist_update { vars: @@ -31,28 +28,34 @@ bundle agent orchestration_hostlist_update "host_list" slist => hostsseen("inf", "lastseen", "address"); files: - am_policy_hub:: "$(sys.workdir)/masterfiles/host_list" - comment => "Write the addresses of all hosts to a file", - handle => "orchestration_hostlit_update_files_host_list_write", - edit_line => insert_lines( "@(orchestration_hostlist_update.host_list)" ), - create => "true", - edit_defaults => empty; + comment => "Write the addresses of all hosts to a file", + handle => "orchestration_hostlit_update_files_host_list_write", + edit_line => insert_lines( + "@(orchestration_hostlist_update.host_list)" + ), + create => "true", + edit_defaults => empty; } - bundle agent orchestration_hostlist_use { vars: - "host_list" slist => readstringlist("$(sys.workdir)/inputs/host_list", "#.*", "\n", 1000, 40000); - "host_string" string => join(", ", "host_list"); + "host_list" + slist => readstringlist( + "$(sys.workdir)/inputs/host_list", "#.*", "\n", 1000, 40000 + ); + + "host_string" string => join(", ", "host_list"); files: - "/tmp/monitoring" - comment => "Update application configuration to reflect all hosts on this hub", - handle => "orchestration_read_files_host_list_configuration", - edit_line => expand_template("$(sys.workdir)/inputs/template_monitoring"), - create => "true", + "/tmp/monitoring" + comment => "Update application configuration to reflect all hosts on this hub", + handle => "orchestration_read_files_host_list_configuration", + edit_line => expand_template( + "$(sys.workdir)/inputs/template_monitoring" + ), + create => "true", edit_defaults => empty; } diff --git a/examples/ordering.cf b/examples/ordering.cf index 30206fab45..53ec8e305a 100644 --- a/examples/ordering.cf +++ b/examples/ordering.cf @@ -1,25 +1,22 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - ################################################################## # # cfengine 3 - ordering promises into dependent chains @@ -29,51 +26,35 @@ # cf-agent -f ./cftest.cf -K # ################################################################## - body common control - { - bundlesequence => { "order" }; + bundlesequence => { "order" }; } - ################################################################## - bundle agent order - { vars: - - "list" slist => { "three", "four" }; + "list" slist => { "three", "four" }; commands: - ok_later:: - "/bin/echo five"; otherthing:: - "/bin/echo six"; any:: - - - "/bin/echo one" classes => d("ok_later","otherthing"); + "/bin/echo one" classes => d("ok_later", "otherthing"); "/bin/echo two"; "/bin/echo $(list)"; preserved_class:: - "/bin/echo seven"; - } - ############################################ - -body classes d(if,else) - +body classes d(if, else) { - promise_repaired => { "$(if)" }; - repair_failed => { "$(else)" }; - persist_time => "0"; + promise_repaired => { "$(if)" }; + repair_failed => { "$(else)" }; + persist_time => "0"; } diff --git a/examples/package_apt.cf b/examples/package_apt.cf index e377756334..ed535c37f0 100644 --- a/examples/package_apt.cf +++ b/examples/package_apt.cf @@ -1,94 +1,73 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - # to see list of packages type "apt-cache pkgnames" # to see list of installed packages type "dpkg --get-selections" # # Package management -# - body common control { - bundlesequence => { "packages" }; + bundlesequence => { "packages" }; } body agent control { - environment => { "DEBIAN_FRONTEND=noninteractive" }; + environment => { "DEBIAN_FRONTEND=noninteractive" }; } - ############################################# - 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" + # Test the simplest case -- leave everything to the yum smart manager + "match_package" + slist => { + "apache2", + # "apache2-mod_php5", + # "apache2-prefork", + # "php5" }; - packages: - - "$(match_package)" + packages: + "$(match_package)" package_policy => "add", package_method => apt; - } - ############################################# - body package_method apt - { - any:: - - # ii acpi 0.09-3ubuntu1 - - package_changes => "bulk"; - package_list_command => "/usr/bin/dpkg -l"; - - package_list_name_regex => "ii\s+([^\s]+).*"; - package_list_version_regex => "ii\s+[^\s]+\s+([^\s]+).*"; - - # package_list_arch_regex => "none"; - - package_installed_regex => ".*"; # all reported are installed - - #package_name_convention => "$(name)_$(version)_$(arch)"; - package_name_convention => "$(name)"; - - # Use these only if not using a separate version/arch string - # package_version_regex => ""; - # package_name_regex => ""; - # package_arch_regex => ""; - - package_add_command => "/usr/bin/apt-get --yes install"; - package_delete_command => "/usr/bin/apt-get --yes remove"; - package_update_command => "/usr/bin/apt-get --yes dist-upgrade"; - #package_verify_command => "/bin/rpm -V"; + any:: + # ii acpi 0.09-3ubuntu1 + package_changes => "bulk"; + package_list_command => "/usr/bin/dpkg -l"; + package_list_name_regex => "ii\s+([^\s]+).*"; + package_list_version_regex => "ii\s+[^\s]+\s+([^\s]+).*"; + # package_list_arch_regex => "none"; + package_installed_regex => ".*"; + # all reported are installed + #package_name_convention => "$(name)_$(version)_$(arch)"; + package_name_convention => "$(name)"; + # Use these only if not using a separate version/arch string + # package_version_regex => ""; + # package_name_regex => ""; + # package_arch_regex => ""; + package_add_command => "/usr/bin/apt-get --yes install"; + package_delete_command => "/usr/bin/apt-get --yes remove"; + package_update_command => "/usr/bin/apt-get --yes dist-upgrade"; + #package_verify_command => "/bin/rpm -V"; } - diff --git a/examples/package_bundles.cf b/examples/package_bundles.cf index 18a3525247..e449e82ac3 100644 --- a/examples/package_bundles.cf +++ b/examples/package_bundles.cf @@ -1,72 +1,70 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. # - #+begin_src cfengine3 body common control { - inputs => { "$(sys.libdir)/packages.cf" }; - bundlesequence => { "runme" }; + inputs => { "$(sys.libdir)/packages.cf" }; + bundlesequence => { "runme" }; } - bundle agent runme { methods: - "nozip" usebundle => package_absent("zip"); # delete - "pleasezip" usebundle => package_present("zip"); # add - "latestzip" usebundle => package_latest("zip"); # add/update + "nozip" usebundle => package_absent("zip"); + + # delete + "pleasezip" usebundle => package_present("zip"); + + # add + "latestzip" usebundle => package_latest("zip"); - # add a package from a file with a specific selection method, - # version, and architecture - "addfilezip" - usebundle => package_specific_present("/mydir/zip.deb-or-rpm", - "3.0-7", - ifelse("debian", "amd64", - "x86_64")); + # add/update + # add a package from a file with a specific selection method, + # version, and architecture + "addfilezip" + usebundle => package_specific_present( + "/mydir/zip.deb-or-rpm", "3.0-7", ifelse("debian", "amd64", "x86_64") + ); - # add a package with a specific selection method, version, and - # architecture - "addzip" - usebundle => package_specific_present("zip", - ifelse("redhat", "3.0-7", - "2.99"), - ifelse("debian", "amd64", - "x86_64")); + # add a package with a specific selection method, version, and + # architecture + "addzip" + usebundle => package_specific_present( + "zip", + ifelse("redhat", "3.0-7", "2.99"), + ifelse("debian", "amd64", "x86_64") + ); - # add or update a package from a file with a specific selection - # method, version, and architecture - "upgradefilezip" - usebundle => package_specific_latest("/mydir/zip.deb-or-rpm", - "3.0-7", - ifelse("debian", "amd64", - "x86_64")); + # add or update a package from a file with a specific selection + # method, version, and architecture + "upgradefilezip" + usebundle => package_specific_latest( + "/mydir/zip.deb-or-rpm", "3.0-7", ifelse("debian", "amd64", "x86_64") + ); - # add or update a package with a specific selection method, - # version, and architecture - "upgradezip" - usebundle => package_specific_latest("zip", - "3.0-7", - ifelse("debian", "amd64", - "x86_64")); + # add or update a package with a specific selection method, + # version, and architecture + "upgradezip" + usebundle => package_specific_latest( + "zip", "3.0-7", ifelse("debian", "amd64", "x86_64") + ); } #+end_src diff --git a/examples/package_freebsd.cf b/examples/package_freebsd.cf index ad006bd781..9e1fbe1bd6 100644 --- a/examples/package_freebsd.cf +++ b/examples/package_freebsd.cf @@ -1,86 +1,61 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - - # # Package management -# - body common control { - bundlesequence => { "packages" }; + bundlesequence => { "packages" }; } - ############################################# - body agent control { - environment => { "PACKAGESITE=ftp://freebsd-src.es.net/pub/FreeBSD/ports/i386/packages-7.2-release/All/" }; + environment => { + "PACKAGESITE=ftp://freebsd-src.es.net/pub/FreeBSD/ports/i386/packages-7.2-release/All/", + }; } - ############################################# - bundle agent packages { vars: + # Test the simplest case -- leave everything to the yum smart manager + "match_package" slist => { "wget-1.11.4" }; - # Test the simplest case -- leave everything to the yum smart manager - - "match_package" slist => { - "wget-1.11.4" - }; packages: - - "$(match_package)" - + "$(match_package)" package_policy => "add", package_method => freebsd; - } ############################################# - body package_method freebsd - { - any:: - - package_changes => "individual"; - - # Could use rpm for this - package_list_command => "/usr/sbin/pkg_info"; - - # Remember to escape special characters like | - - package_list_name_regex => "([^-]+).*"; - package_list_version_regex => "[^-]+-([^\s]+).*"; - - package_name_regex => "([^-]+).*"; - package_version_regex => "[^-]+-([^\s]+).*"; - - package_installed_regex => ".*"; - - package_name_convention => "$(name)-$(version)"; - - - package_add_command => "/usr/sbin/pkg_add -r"; - package_delete_command => "/usr/sbin/pkg_delete"; + any:: + package_changes => "individual"; + # Could use rpm for this + package_list_command => "/usr/sbin/pkg_info"; + # Remember to escape special characters like | + package_list_name_regex => "([^-]+).*"; + package_list_version_regex => "[^-]+-([^\s]+).*"; + package_name_regex => "([^-]+).*"; + package_version_regex => "[^-]+-([^\s]+).*"; + package_installed_regex => ".*"; + package_name_convention => "$(name)-$(version)"; + package_add_command => "/usr/sbin/pkg_add -r"; + package_delete_command => "/usr/sbin/pkg_delete"; } diff --git a/examples/package_latest.cf b/examples/package_latest.cf index 42c5ba9cba..0cb158b339 100644 --- a/examples/package_latest.cf +++ b/examples/package_latest.cf @@ -1,24 +1,18 @@ -# # Makes sure a package is installed at latest version. # Does not take any action if the package has already # reached the version given in package_version. -# - body common control { - inputs => { "$(sys.libdir)/stdlib.cf" }; - bundlesequence => { "example" }; + inputs => { "$(sys.libdir)/stdlib.cf" }; + bundlesequence => { "example" }; } - bundle agent example { packages: - - "apache2" + "apache2" package_method => generic, package_version => "2.2.00", package_select => ">=", package_policy => "addupdate"; } - diff --git a/examples/package_msi_file.cf b/examples/package_msi_file.cf index 47d238378d..03ab30f793 100644 --- a/examples/package_msi_file.cf +++ b/examples/package_msi_file.cf @@ -1,67 +1,48 @@ # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - # # MSI package management using file name -# - -body common control -{ - bundlesequence => { "packages" }; -} - +body common control +{ + bundlesequence => { "packages" }; +} ############################################# - -bundle agent packages -{ - vars: - - "match_package" slist => { - "7zip-4.65-x86_64.msi" - }; - packages: - - "$(match_package)" - - package_policy => "add", - package_method => msi_fmatch; - -} - +bundle agent packages +{ + vars: + "match_package" slist => { "7zip-4.65-x86_64.msi" }; + + packages: + "$(match_package)" + package_policy => "add", + package_method => msi_fmatch; +} ############################################# - -body package_method msi_fmatch - -{ - package_changes => "individual"; - package_file_repositories => { "$(sys.workdir)\software_updates\windows", "s:\su" }; - - package_installed_regex => ".*"; - - package_name_regex => "^(\S+)-(\d+\.?)+"; - package_version_regex => "^\S+-((\d+\.?)+)"; - package_arch_regex => "^\S+-(\d+\.?)+(^.+)"; - - package_name_convention => "$(name)-$(version)-$(arch).msi"; - - package_add_command => "\"$(sys.winsysdir)\msiexec.exe\" /qn /i"; - package_update_command => "\"$(sys.winsysdir)\msiexec.exe\" /qn /i"; - package_delete_command => "\"$(sys.winsysdir)\msiexec.exe\" /qn /x"; -} +body package_method msi_fmatch +{ + package_changes => "individual"; + package_file_repositories => { + "$(sys.workdir)\software_updates\windows", "s:\su" + }; + package_installed_regex => ".*"; + package_name_regex => "^(\S+)-(\d+\.?)+"; + package_version_regex => "^\S+-((\d+\.?)+)"; + package_arch_regex => "^\S+-(\d+\.?)+(^.+)"; + package_name_convention => "$(name)-$(version)-$(arch).msi"; + package_add_command => "\"$(sys.winsysdir)\msiexec.exe\" /qn /i"; + package_update_command => "\"$(sys.winsysdir)\msiexec.exe\" /qn /i"; + package_delete_command => "\"$(sys.winsysdir)\msiexec.exe\" /qn /x"; +} diff --git a/examples/package_msi_version.cf b/examples/package_msi_version.cf index 38c4d74f95..4b217cc044 100644 --- a/examples/package_msi_version.cf +++ b/examples/package_msi_version.cf @@ -1,67 +1,48 @@ # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - # # MSI package management using version criteria -# - body common control { - bundlesequence => { "packages" }; + bundlesequence => { "packages" }; } - ############################################# - bundle agent packages { vars: + "match_package" slist => { "7zip" }; - "match_package" slist => { - "7zip" - }; packages: - - "$(match_package)" - + "$(match_package)" package_policy => "update", package_select => ">=", package_architectures => { "x86_64" }, package_version => "3.00", package_method => msi_vmatch; - } - ############################################# - body package_method msi_vmatch - { - package_changes => "individual"; - package_file_repositories => { "$(sys.workdir)\software_updates\windows", "s:\su" }; - - package_installed_regex => ".*"; - - package_name_convention => "$(name)-$(version)-$(arch).msi"; - - package_add_command => "\"$(sys.winsysdir)\msiexec.exe\" /qn /i"; - package_update_command => "\"$(sys.winsysdir)\msiexec.exe\" /qn /i"; - package_delete_command => "\"$(sys.winsysdir)\msiexec.exe\" /qn /x"; + package_changes => "individual"; + package_file_repositories => { + "$(sys.workdir)\software_updates\windows", "s:\su" + }; + package_installed_regex => ".*"; + package_name_convention => "$(name)-$(version)-$(arch).msi"; + package_add_command => "\"$(sys.winsysdir)\msiexec.exe\" /qn /i"; + package_update_command => "\"$(sys.winsysdir)\msiexec.exe\" /qn /i"; + package_delete_command => "\"$(sys.winsysdir)\msiexec.exe\" /qn /x"; } - diff --git a/examples/package_rpm.cf b/examples/package_rpm.cf index 5c4d7daa94..d7590f25fa 100644 --- a/examples/package_rpm.cf +++ b/examples/package_rpm.cf @@ -1,85 +1,59 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - # # Package management -# - body common control { - bundlesequence => { "packages" }; + bundlesequence => { "packages" }; } - ############################################# - bundle agent packages { vars: - - "exact_package" slist => { - "apache2", - "kernel-default" - }; - - "version[OpenOffice_org-hyphen]" string => "1.2.3"; - "version[kernel-default]" string => "2.6.27.7-9.1"; + "exact_package" slist => { "apache2", "kernel-default" }; + "version[OpenOffice_org-hyphen]" string => "1.2.3"; + "version[kernel-default]" string => "2.6.27.7-9.1"; packages: - - "$(exact_package)" - + "$(exact_package)" package_policy => "verify", package_method => rpm, package_select => ">=", package_architectures => { "x86_64" }, package_version => "$(version[$(exact_package)])"; - } - ############################################# - body package_method rpm - { - any:: - - package_changes => "individual"; - - package_list_command => "/bin/rpm -qa --queryformat \"i | repos | %{name} | %{version}-%{release} | %{arch}\n\""; - - # Remember to escape special characters like | - - package_list_name_regex => "[^|]+\|[^|]+\|\s+([^\s|]+).*"; - package_list_version_regex => "[^|]+\|[^|]+\|[^|]+\|\s+([^\s|]+).*"; - package_list_arch_regex => "[^|]+\|[^|]+\|[^|]+\|[^|]+\|\s+([^\s]+).*"; - - package_installed_regex => "i.*"; - - package_name_convention => "$(name).$(arch)"; - - package_add_command => "/bin echo /bin/rpm -i "; - package_delete_command => "/bin/rpm -e --nodeps"; - package_verify_command => "/bin/rpm -V"; - package_noverify_regex => ".*[^\s].*"; - #package_noverify_returncode => "-1"; - + any:: + package_changes => "individual"; + package_list_command => "/bin/rpm -qa --queryformat \"i | repos | %{name} | %{version}-%{release} | %{arch}\n\""; + # Remember to escape special characters like | + package_list_name_regex => "[^|]+\|[^|]+\|\s+([^\s|]+).*"; + package_list_version_regex => "[^|]+\|[^|]+\|[^|]+\|\s+([^\s|]+).*"; + package_list_arch_regex => "[^|]+\|[^|]+\|[^|]+\|[^|]+\|\s+([^\s]+).*"; + package_installed_regex => "i.*"; + package_name_convention => "$(name).$(arch)"; + package_add_command => "/bin echo /bin/rpm -i "; + package_delete_command => "/bin/rpm -e --nodeps"; + package_verify_command => "/bin/rpm -V"; + package_noverify_regex => ".*[^\s].*"; + #package_noverify_returncode => "-1"; } diff --git a/examples/package_solaris.cf b/examples/package_solaris.cf index 82aad7f52c..e8336321d6 100644 --- a/examples/package_solaris.cf +++ b/examples/package_solaris.cf @@ -1,60 +1,49 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - - # # Package management -# - body common control { - bundlesequence => { "packages" }; - inputs => { "$(sys.libdir)/stdlib.cf" }; + bundlesequence => { "packages" }; + inputs => { "$(sys.libdir)/stdlib.cf" }; } - ############################################# - bundle agent packages { vars: - - "solaris_packages[SMCzlib]" string => "zlib-1.2.3-sol10-sparc-local"; - "admin_file" string => "cfengine_admin_file"; - - "package_names" slist => getindices("solaris_packages"); + "solaris_packages[SMCzlib]" string => "zlib-1.2.3-sol10-sparc-local"; + "admin_file" string => "cfengine_admin_file"; + "package_names" slist => getindices("solaris_packages"); files: - - "/tmp/$(admin_file)" + "/tmp/$(admin_file)" create => "true", edit_defaults => empty, edit_line => create_solaris_admin_file; packages: - - "$(package_names)" - + "$(package_names)" package_policy => "add", - package_method => solaris("$(package_names)", "$(solaris_packages[$(package_names)])", "$(admin_file)"); - + package_method => solaris( + "$(package_names)", + "$(solaris_packages[$(package_names)])", + "$(admin_file)" + ); } - diff --git a/examples/package_windows_feature.cf b/examples/package_windows_feature.cf index 20997f4bfa..412a5baa38 100644 --- a/examples/package_windows_feature.cf +++ b/examples/package_windows_feature.cf @@ -1,34 +1,29 @@ body common control { - bundlesequence => { "example" }; + bundlesequence => { "example" }; } bundle agent example { packages: - Windows_Server_2008_R2:: "Telnet-Client" - comment => "Install the telnet client", - package_policy => "add", - package_method => windows_feature; - + comment => "Install the telnet client", + package_policy => "add", + package_method => windows_feature; } - body package_method windows_feature # NOTE: Windows feature names are case-sensitive { - package_changes => "individual"; - - package_name_convention => "$(name)"; - package_delete_convention => "$(name)"; - - package_installed_regex => ".*"; - package_list_name_regex => "(.*)"; - package_list_version_regex => "(.*)"; # FIXME: the listing does not give version, so takes name for version too now - - package_add_command => "$(sys.winsysdir)\\WindowsPowerShell\\v1.0\\powershell.exe -Command \"Import-Module ServerManager; Add-WindowsFeature -Name\""; - package_delete_command => "$(sys.winsysdir)\\WindowsPowerShell\\v1.0\\powershell.exe -Command \"Import-Module ServerManager; Remove-WindowsFeature -confirm:$false -Name\""; - package_list_command => "$(sys.winsysdir)\\WindowsPowerShell\\v1.0\\powershell.exe -Command \"Import-Module ServerManager; Get-WindowsFeature | where {$_.installed -eq $True} |foreach {$_.Name}\""; + package_changes => "individual"; + package_name_convention => "$(name)"; + package_delete_convention => "$(name)"; + package_installed_regex => ".*"; + package_list_name_regex => "(.*)"; + package_list_version_regex => "(.*)"; + # FIXME: the listing does not give version, so takes name for version too now + package_add_command => "$(sys.winsysdir)\\WindowsPowerShell\\v1.0\\powershell.exe -Command \"Import-Module ServerManager; Add-WindowsFeature -Name\""; + package_delete_command => "$(sys.winsysdir)\\WindowsPowerShell\\v1.0\\powershell.exe -Command \"Import-Module ServerManager; Remove-WindowsFeature -confirm:$false -Name\""; + package_list_command => "$(sys.winsysdir)\\WindowsPowerShell\\v1.0\\powershell.exe -Command \"Import-Module ServerManager; Get-WindowsFeature | where {$_.installed -eq $True} |foreach {$_.Name}\""; } diff --git a/examples/package_yum.cf b/examples/package_yum.cf index 56f61b8185..e01c44af09 100644 --- a/examples/package_yum.cf +++ b/examples/package_yum.cf @@ -1,56 +1,39 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - - # # Package management -# - body common control { - bundlesequence => { "packages" }; - inputs => { "$(sys.libdir)/stdlib.cf" }; + bundlesequence => { "packages" }; + inputs => { "$(sys.libdir)/stdlib.cf" }; } - ############################################# - 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" }; - # Test the simplest case -- leave everything to the yum smart manager - - "match_package" slist => { - "apache2", - "apache2-mod_php5", - "apache2-prefork", - "php5" - }; packages: - - "$(match_package)" - + "$(match_package)" package_policy => "add", package_method => yum; - } - diff --git a/examples/package_zypper.cf b/examples/package_zypper.cf index 9c74441331..c8f8119837 100644 --- a/examples/package_zypper.cf +++ b/examples/package_zypper.cf @@ -1,56 +1,39 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - - # # Package management -# - body common control { - bundlesequence => { "packages" }; - inputs => { "$(sys.libdir)/stdlib.cf" }; + bundlesequence => { "packages" }; + inputs => { "$(sys.libdir)/stdlib.cf" }; } - ############################################# - bundle agent packages { vars: + # Test the simplest case -- leave everything to the zypper smart manager + "match_package" + slist => { "apache2", "apache2-mod_php5", "apache2-prefork", "php5" }; - # Test the simplest case -- leave everything to the zypper smart manager - - "match_package" slist => { - "apache2", - "apache2-mod_php5", - "apache2-prefork", - "php5" - }; packages: - - "$(match_package)" - + "$(match_package)" package_policy => "add", package_method => zypper; - } - diff --git a/examples/packagesmatching.cf b/examples/packagesmatching.cf index b07eb7403b..4431ee5846 100644 --- a/examples/packagesmatching.cf +++ b/examples/packagesmatching.cf @@ -1,35 +1,29 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - #[%-%] body common control - { - bundlesequence => { "missing_packages" }; + bundlesequence => { "missing_packages" }; } #[%-%] - ########################################### - #[%+%] bundle agent missing_packages { @@ -38,9 +32,9 @@ bundle agent missing_packages "desired" slist => { "mypackage1", "mypackage2" }; # Get info on all installed packages - "installed" data => packagesmatching(".*",".*",".*",".*"); + "installed" data => packagesmatching(".*", ".*", ".*", ".*"); "installed_indices" slist => getindices(installed); - + # Build a simple array of the package names so that we can use # getvalues to pull a unified list of package names that are installed. "installed_name[$(installed_indices)]" @@ -51,7 +45,7 @@ bundle agent missing_packages # Determine packages that are missing my differencing the list of # desired packages, against the list of installed packages - "missing_list" slist => difference(desired,installed_names); + "missing_list" slist => difference(desired, installed_names); reports: # Report on packages that are missing, installed diff --git a/examples/parallel_exec.cf b/examples/parallel_exec.cf index 4bf6102ef4..8bfcc6bda6 100644 --- a/examples/parallel_exec.cf +++ b/examples/parallel_exec.cf @@ -1,65 +1,48 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - ######################################################## # # Simple backgrounding - try this with background = true and false # ######################################################## - body common control - { - bundlesequence => { "example" }; + bundlesequence => { "example" }; } - ######################################################## - body agent control - { - agentaccess => { "mark", "root" }; + agentaccess => { "mark", "root" }; } - ######################################################## - bundle agent example - { commands: + "/bin/sleep 10" action => background; - "/bin/sleep 10" - action => background; - - "/bin/sleep" + "/bin/sleep" args => "20", - action => background; - + action => background; } - ######################################################### - body action background - { - background => "true"; + background => "true"; } diff --git a/examples/parseintarray.cf b/examples/parseintarray.cf index e3737426e9..7c3eec932b 100644 --- a/examples/parseintarray.cf +++ b/examples/parseintarray.cf @@ -1,53 +1,45 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - #+begin_src cfengine3 body common control { - bundlesequence => { "test" }; + bundlesequence => { "test" }; } bundle agent test(f) { vars: - # Define data inline for convenience - "table" string => - "1:2 + # Define data inline for convenience + "table" string => "1:2 3:4 5:6"; - "dim" int => parseintarray( - "items", - "$(table)", - "\s*#[^\n]*", - ":", - "1000", - "200000" + "dim" + int => parseintarray( + "items", "$(table)", "\s*#[^\n]*", ":", "1000", "200000" ); - "keys" slist => sort(getindices("items")); + "keys" slist => sort(getindices("items")); reports: - "$(keys)"; + "$(keys)"; } #+end_src ############################################################################### diff --git a/examples/parserealarray.cf b/examples/parserealarray.cf index a6096393df..b062ac0183 100644 --- a/examples/parserealarray.cf +++ b/examples/parserealarray.cf @@ -1,50 +1,40 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - #+begin_src cfengine3 bundle agent __main__ { vars: - # Define data inline for convenience - "table" - string => "1.0:2.718 + # Define data inline for convenience + "table" string => "1.0:2.718 3:4.6692 5.0:6.82"; - - "dim" - int => parserealarray( - "items", - "$(table)", - "\s*#[^\n]*", - ":", - "1000", - "200000" + "dim" + int => parserealarray( + "items", "$(table)", "\s*#[^\n]*", ":", "1000", "200000" ); - "keys" slist => sort(getindices("items")); + "keys" slist => sort(getindices("items")); reports: - "$(keys) - $(items[$(keys)][1])"; + "$(keys) - $(items[$(keys)][1])"; } #+end_src ############################################################################### diff --git a/examples/parsestringarray.cf b/examples/parsestringarray.cf index c5abf3fe56..d1210642f4 100644 --- a/examples/parsestringarray.cf +++ b/examples/parsestringarray.cf @@ -2,31 +2,24 @@ bundle agent __main__ { vars: - - ####################################### - # Define data inline for convenience - ####################################### - - "table" - string => "Eulers Number:2.718 + ####################################### + # Define data inline for convenience + ####################################### + "table" + string => "Eulers Number:2.718 A Feigenbaum constant:4.6692 Tau (2pi):6.28"; - ####################################### - - "dim" int => parsestringarray( - "items", - "$(table)", - "\s*#[^\n]*", - ":", - "1000", - "200000" + ####################################### + "dim" + int => parsestringarray( + "items", "$(table)", "\s*#[^\n]*", ":", "1000", "200000" ); - "keys" slist => sort(getindices("items")); + "keys" slist => sort(getindices("items")); reports: - "$(keys) - $(items[$(keys)][1])"; + "$(keys) - $(items[$(keys)][1])"; } #+end_src ############################################################################### diff --git a/examples/parsestringarrayidx.cf b/examples/parsestringarrayidx.cf index 019afab4ce..dcdc67afc8 100644 --- a/examples/parsestringarrayidx.cf +++ b/examples/parsestringarrayidx.cf @@ -1,55 +1,48 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - #+begin_src cfengine3 body common control { - bundlesequence => { "test" }; + bundlesequence => { "test" }; } bundle agent test(f) { vars: - # Define data inline for convenience - "table" string => "one: a + # Define data inline for convenience + "table" + string => "one: a two: b three: c"; - ####################################### - - "dim" int => parsestringarrayidx( - "items", - "$(table)", - "\s*#[^\n]*", - ":", - "1000", - "200000" + ####################################### + "dim" + int => parsestringarrayidx( + "items", "$(table)", "\s*#[^\n]*", ":", "1000", "200000" ); - "keys" slist => getindices("items"); - "sorted_keys" slist => sort(keys, "int"); + "keys" slist => getindices("items"); + "sorted_keys" slist => sort(keys, "int"); reports: - "item $(sorted_keys) has column 0 = $(items[$(sorted_keys)][0]) and column 1 = $(items[$(sorted_keys)][1])"; + "item $(sorted_keys) has column 0 = $(items[$(sorted_keys)][0]) and column 1 = $(items[$(sorted_keys)][1])"; } #+end_src ############################################################################### diff --git a/examples/pathtype.cf b/examples/pathtype.cf index b3c2fcf7df..01783dee12 100644 --- a/examples/pathtype.cf +++ b/examples/pathtype.cf @@ -1,76 +1,54 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - - ######################################################## # # Simple backgrounding # ######################################################## - body common control - { - bundlesequence => { "example" }; + bundlesequence => { "example" }; } - ######################################################## - bundle agent example - { files: - - "/home/mark/tmp" -> "me" - - changes => tripwire, - pathtype => "literal", + "/home/mark/tmp" -> "me" + changes => tripwire, + pathtype => "literal", depth_search => recurse("inf"); - } - - ######################################################### - body changes tripwire - { - hash => "md5"; - report_changes => "all"; - update_hashes => "true"; + hash => "md5"; + report_changes => "all"; + update_hashes => "true"; } - ######################################################### - body action background - { - background => "true"; + background => "true"; } - ######################################################### - body depth_search recurse(d) - { - depth => "$(d)"; + depth => "$(d)"; } diff --git a/examples/pattern_and_edit.cf b/examples/pattern_and_edit.cf index 457a60a258..82ed7c4b7d 100644 --- a/examples/pattern_and_edit.cf +++ b/examples/pattern_and_edit.cf @@ -1,60 +1,42 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - - body common control - { - bundlesequence => {"test"}; + bundlesequence => { "test" }; } - ######################################################## - bundle agent example - { - files: - - "/home/(.*)/testfile" - - create => "true", + "/home/(.*)/testfile" + create => "true", edit_line => AppendIfNoLine("key_$(match.1)"); - } - ######################################################## - bundle edit_line AppendIfNoLine(x) { insert_lines: - - "Line $(x)" location => append; + "Line $(x)" location => append; } - ######################################################## - body location append - { - before_after => "before"; + before_after => "before"; } diff --git a/examples/peerleader.cf b/examples/peerleader.cf index e2f5a4e184..ca253fcdff 100644 --- a/examples/peerleader.cf +++ b/examples/peerleader.cf @@ -1,20 +1,18 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See @@ -40,30 +38,28 @@ #+begin_src cfengine3 body common control { - bundlesequence => { "peers" }; + bundlesequence => { "peers" }; } bundle agent peers { vars: - - "mygroup" slist => peers("/tmp/cfe_hostlist","#.*",4); - - "myleader" string => peerleader("/tmp/cfe_hostlist","#.*",4); - - "all_leaders" slist => peerleaders("/tmp/cfe_hostlist","#.*",4); + "mygroup" slist => peers("/tmp/cfe_hostlist", "#.*", 4); + "myleader" string => peerleader("/tmp/cfe_hostlist", "#.*", 4); + "all_leaders" slist => peerleaders("/tmp/cfe_hostlist", "#.*", 4); reports: + # note that the current host name is fourth in the host list, so + # its peer group is the first 4-host group, minus the host itself. + "/tmp/cfe_hostlist mypeer $(mygroup)"; + + # note that the current host name is fourth in the host list, so + # the peer leader is "alpha" + "/tmp/cfe_hostlist myleader $(myleader)"; + "/tmp/cfe_hostlist another leader $(all_leaders)"; - # note that the current host name is fourth in the host list, so - # its peer group is the first 4-host group, minus the host itself. - "/tmp/cfe_hostlist mypeer $(mygroup)"; - # note that the current host name is fourth in the host list, so - # the peer leader is "alpha" - "/tmp/cfe_hostlist myleader $(myleader)"; - "/tmp/cfe_hostlist another leader $(all_leaders)"; - "Unable to find my fully qualified hostname $(sys.fqhost) in /tmp/cfe_hostlist. Can't determine peers." - if => not( regline( $(sys.fqhost), "/tmp/cfe_hostlist" ) ); + "Unable to find my fully qualified hostname $(sys.fqhost) in /tmp/cfe_hostlist. Can't determine peers." + if => not(regline($(sys.fqhost), "/tmp/cfe_hostlist")); } #+end_src ############################################################################### diff --git a/examples/peerleaders.cf b/examples/peerleaders.cf index e2f5a4e184..ca253fcdff 100644 --- a/examples/peerleaders.cf +++ b/examples/peerleaders.cf @@ -1,20 +1,18 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See @@ -40,30 +38,28 @@ #+begin_src cfengine3 body common control { - bundlesequence => { "peers" }; + bundlesequence => { "peers" }; } bundle agent peers { vars: - - "mygroup" slist => peers("/tmp/cfe_hostlist","#.*",4); - - "myleader" string => peerleader("/tmp/cfe_hostlist","#.*",4); - - "all_leaders" slist => peerleaders("/tmp/cfe_hostlist","#.*",4); + "mygroup" slist => peers("/tmp/cfe_hostlist", "#.*", 4); + "myleader" string => peerleader("/tmp/cfe_hostlist", "#.*", 4); + "all_leaders" slist => peerleaders("/tmp/cfe_hostlist", "#.*", 4); reports: + # note that the current host name is fourth in the host list, so + # its peer group is the first 4-host group, minus the host itself. + "/tmp/cfe_hostlist mypeer $(mygroup)"; + + # note that the current host name is fourth in the host list, so + # the peer leader is "alpha" + "/tmp/cfe_hostlist myleader $(myleader)"; + "/tmp/cfe_hostlist another leader $(all_leaders)"; - # note that the current host name is fourth in the host list, so - # its peer group is the first 4-host group, minus the host itself. - "/tmp/cfe_hostlist mypeer $(mygroup)"; - # note that the current host name is fourth in the host list, so - # the peer leader is "alpha" - "/tmp/cfe_hostlist myleader $(myleader)"; - "/tmp/cfe_hostlist another leader $(all_leaders)"; - "Unable to find my fully qualified hostname $(sys.fqhost) in /tmp/cfe_hostlist. Can't determine peers." - if => not( regline( $(sys.fqhost), "/tmp/cfe_hostlist" ) ); + "Unable to find my fully qualified hostname $(sys.fqhost) in /tmp/cfe_hostlist. Can't determine peers." + if => not(regline($(sys.fqhost), "/tmp/cfe_hostlist")); } #+end_src ############################################################################### diff --git a/examples/peers.cf b/examples/peers.cf index e2f5a4e184..ca253fcdff 100644 --- a/examples/peers.cf +++ b/examples/peers.cf @@ -1,20 +1,18 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See @@ -40,30 +38,28 @@ #+begin_src cfengine3 body common control { - bundlesequence => { "peers" }; + bundlesequence => { "peers" }; } bundle agent peers { vars: - - "mygroup" slist => peers("/tmp/cfe_hostlist","#.*",4); - - "myleader" string => peerleader("/tmp/cfe_hostlist","#.*",4); - - "all_leaders" slist => peerleaders("/tmp/cfe_hostlist","#.*",4); + "mygroup" slist => peers("/tmp/cfe_hostlist", "#.*", 4); + "myleader" string => peerleader("/tmp/cfe_hostlist", "#.*", 4); + "all_leaders" slist => peerleaders("/tmp/cfe_hostlist", "#.*", 4); reports: + # note that the current host name is fourth in the host list, so + # its peer group is the first 4-host group, minus the host itself. + "/tmp/cfe_hostlist mypeer $(mygroup)"; + + # note that the current host name is fourth in the host list, so + # the peer leader is "alpha" + "/tmp/cfe_hostlist myleader $(myleader)"; + "/tmp/cfe_hostlist another leader $(all_leaders)"; - # note that the current host name is fourth in the host list, so - # its peer group is the first 4-host group, minus the host itself. - "/tmp/cfe_hostlist mypeer $(mygroup)"; - # note that the current host name is fourth in the host list, so - # the peer leader is "alpha" - "/tmp/cfe_hostlist myleader $(myleader)"; - "/tmp/cfe_hostlist another leader $(all_leaders)"; - "Unable to find my fully qualified hostname $(sys.fqhost) in /tmp/cfe_hostlist. Can't determine peers." - if => not( regline( $(sys.fqhost), "/tmp/cfe_hostlist" ) ); + "Unable to find my fully qualified hostname $(sys.fqhost) in /tmp/cfe_hostlist. Can't determine peers." + if => not(regline($(sys.fqhost), "/tmp/cfe_hostlist")); } #+end_src ############################################################################### diff --git a/examples/postfix.cf b/examples/postfix.cf index da5406e397..087bb8c047 100644 --- a/examples/postfix.cf +++ b/examples/postfix.cf @@ -1,124 +1,92 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - ####################################################### # # Postfix # ####################################################### - body common control - { - any:: - - bundlesequence => { - postfix - }; + any:: + bundlesequence => { postfix }; } - ####################################################### - bundle agent postfix - { vars: - - "prefix" string => "/home/mark/tmp"; - "smtpserver" string => "mailx.domain.tld"; - "mailrelay" string => "mailx.domain.tld"; + "prefix" string => "/home/mark/tmp"; + "smtpserver" string => "mailx.domain.tld"; + "mailrelay" string => "mailx.domain.tld"; files: - - "$(prefix)/main.cf" - edit_line => prefix_postfix; - - "$(prefix)/sasl-passwd" - create => "true", - perms => system("0600","root"), - edit_line => AppendIfNSL("$(smtpserver) _$(fqhost):chmsxrcynz4etzefabj9frejizhs22"); - - + "$(prefix)/main.cf" edit_line => prefix_postfix; + + "$(prefix)/sasl-passwd" + create => "true", + perms => system("0600", "root"), + edit_line => AppendIfNSL( + "$(smtpserver) _$(fqhost):chmsxrcynz4etzefabj9frejizhs22" + ); } - ####################################################### # For the library ####################################################### - bundle edit_line prefix_postfix - { - # - # Value have the form NAME = "quoted space separated list" - # + # Value have the form NAME = "quoted space separated list" vars: - - "ps[relayhost]" string => "[$(postfix.mailrelay)]:587"; - "ps[mydomain]" string => "iu.hio.no"; - "ps[smtp_sasl_auth_enable]" string => "yes"; - "ps[smtp_sasl_password_maps]" string => "hash:/etc/postfix/sasl-passwd"; - "ps[smtp_sasl_security_options]" string => ""; - "ps[smtp_use_tls]" string => "yes"; - "ps[default_privs]" string => "mailman"; - "ps[inet_protocols]" string => "all"; - "ps[inet_interfaces]" string => "127.0.0.1"; - - "parameter_name" slist => getindices("ps"); - - delete_lines: - - "$(parameter_name).*"; + "ps[relayhost]" string => "[$(postfix.mailrelay)]:587"; + "ps[mydomain]" string => "iu.hio.no"; + "ps[smtp_sasl_auth_enable]" string => "yes"; + "ps[smtp_sasl_password_maps]" string => "hash:/etc/postfix/sasl-passwd"; + "ps[smtp_sasl_security_options]" string => ""; + "ps[smtp_use_tls]" string => "yes"; + "ps[default_privs]" string => "mailman"; + "ps[inet_protocols]" string => "all"; + "ps[inet_interfaces]" string => "127.0.0.1"; + "parameter_name" slist => getindices("ps"); + + delete_lines: + "$(parameter_name).*"; insert_lines: - - "$(parameter_name) = $(ps[$(parameter_name)])"; - + "$(parameter_name) = $(ps[$(parameter_name)])"; } - ######################################################## - bundle edit_line AppendIfNSL(parameter) { insert_lines: - - "$(parameter)"; # This is default + "$(parameter)"; + # This is default } - ######################################## # Library Bodies ######################################## - body replace_with All(x) - { - replace_value => "$(x)"; - occurrences => "all"; + replace_value => "$(x)"; + occurrences => "all"; } - ######################################################### - -body perms system(x,owner) - +body perms system(x, owner) { - mode => "0640"; - owners => { "$(owner)", "root" }; + mode => "0640"; + owners => { "$(owner)", "root" }; } diff --git a/examples/printfile.cf b/examples/printfile.cf index bdc7b2846c..7ce0c097d8 100644 --- a/examples/printfile.cf +++ b/examples/printfile.cf @@ -15,18 +15,17 @@ #+begin_src cfengine3 body common control { - bundlesequence => { "example" }; + bundlesequence => { "example" }; } bundle agent example { vars: - "example_file" string => "/tmp/example_file.txt"; + "example_file" string => "/tmp/example_file.txt"; + reports: - "First three:" - printfile => first_three("$(example_file)"); - "Last three:" - printfile => last_three("$(example_file)"); + "First three:" printfile => first_three("$(example_file)"); + "Last three:" printfile => last_three("$(example_file)"); } body printfile first_three(file) diff --git a/examples/process_kill.cf b/examples/process_kill.cf index dc47e9cc4c..4667c37e9d 100644 --- a/examples/process_kill.cf +++ b/examples/process_kill.cf @@ -1,38 +1,29 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - body common control { - bundlesequence => { "kill_process" }; + bundlesequence => { "kill_process" }; } - - bundle agent kill_process { processes: - - "sleep" - - signals => { "term", "kill" }; - + "sleep" signals => { "term", "kill" }; } diff --git a/examples/process_matching.cf b/examples/process_matching.cf index de43e0fa32..f3e059bc0e 100644 --- a/examples/process_matching.cf +++ b/examples/process_matching.cf @@ -1,69 +1,52 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - ######################################################## # # Simple test processes # ######################################################## - body common control - { - bundlesequence => { "example" }; + bundlesequence => { "example" }; } - ######################################################## - bundle agent example - { processes: - - ".*" - - process_select => proc_finder("a.*"), - process_count => up("cfservd"); + ".*" + process_select => proc_finder("a.*"), + process_count => up("cfservd"); } - ######################################################## - body process_count up(s) - { - match_range => "1,10"; # or irange("1","10"); - out_of_range_define => { "$(s)_out_of_control" }; + match_range => "1,10"; + # or irange("1","10"); + out_of_range_define => { "$(s)_out_of_control" }; } - ######################################################## - body process_select proc_finder(p) - { - process_owner => { "avahi", "bin" }; - command => "$(p)"; - pid => "100,199"; - vsize => "0,1000"; - process_result => "command.(process_owner|vsize)"; + process_owner => { "avahi", "bin" }; + command => "$(p)"; + pid => "100,199"; + vsize => "0,1000"; + process_result => "command.(process_owner|vsize)"; } - - diff --git a/examples/process_matching2.cf b/examples/process_matching2.cf index 854b28e9d6..0527ec9689 100644 --- a/examples/process_matching2.cf +++ b/examples/process_matching2.cf @@ -1,61 +1,45 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - ######################################################## # # Simple test processes # ######################################################## - body common control - { - bundlesequence => { "example" }; + bundlesequence => { "example" }; } - ######################################################## - bundle agent example - { processes: - - "sleep" - - process_count => up("sleep"); + "sleep" process_count => up("sleep"); reports: - sleep_out_of_control:: - "Out of control"; } - ######################################################## - body process_count up(s) - { - match_range => "5,10"; # or irange("1","10"); - out_of_range_define => { "$(s)_out_of_control" }; + match_range => "5,10"; + # or irange("1","10"); + out_of_range_define => { "$(s)_out_of_control" }; } - diff --git a/examples/process_matching3.cf b/examples/process_matching3.cf index da4d2b686b..e88c1d23f2 100644 --- a/examples/process_matching3.cf +++ b/examples/process_matching3.cf @@ -1,66 +1,49 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - ######################################################## # # Simple test processes # ######################################################## - body common control - { - bundlesequence => { "example" }; + bundlesequence => { "example" }; } - ######################################################## - bundle agent example - { processes: - - ".*" - - process_select => proc_finder("a.*"), - process_count => up("cfservd"); + ".*" + process_select => proc_finder("a.*"), + process_count => up("cfservd"); } - ######################################################## - body process_count up(s) - { - match_range => "1,10"; # or irange("1","10"); - out_of_range_define => { "$(s)_out_of_control" }; + match_range => "1,10"; + # or irange("1","10"); + out_of_range_define => { "$(s)_out_of_control" }; } - ######################################################## - body process_select proc_finder(p) - { - stime_range => irange(ago("0","0","0","2","0","0"),now); - process_result => "stime"; + stime_range => irange(ago("0", "0", "0", "2", "0", "0"), now); + process_result => "stime"; } - - diff --git a/examples/process_restart.cf b/examples/process_restart.cf index 15f9248995..a1151b29cb 100644 --- a/examples/process_restart.cf +++ b/examples/process_restart.cf @@ -1,49 +1,35 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - body common control { - bundlesequence => { "process_restart" }; + bundlesequence => { "process_restart" }; } - ######################################################### - bundle agent process_restart { vars: + "component" slist => { "cf-monitord", "cf-serverd", "cf-execd" }; - "component" slist => { - "cf-monitord", - "cf-serverd", - "cf-execd" - }; processes: - - "$(component)" - restart_class => canonify("start_$(component)"); + "$(component)" restart_class => canonify("start_$(component)"); commands: - - "/var/cfengine/bin/$(component)" - if => canonify("start_$(component)"); - + "/var/cfengine/bin/$(component)" if => canonify("start_$(component)"); } diff --git a/examples/process_restart_basic.cf b/examples/process_restart_basic.cf index 7afc21c693..e723b6ef7b 100644 --- a/examples/process_restart_basic.cf +++ b/examples/process_restart_basic.cf @@ -1,43 +1,33 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - body common control { - bundlesequence => { "process_restart" }; + bundlesequence => { "process_restart" }; } - ######################################################### - bundle agent process_restart { processes: - - "/usr/bin/daemon" - restart_class => "launch"; + "/usr/bin/daemon" restart_class => "launch"; commands: - launch:: - "/usr/bin/daemon"; - } diff --git a/examples/process_signalling.cf b/examples/process_signalling.cf index 7e02662254..6612e9cdee 100644 --- a/examples/process_signalling.cf +++ b/examples/process_signalling.cf @@ -1,69 +1,50 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - ######################################################## # # Simple test process restart # ######################################################## - body common control - { - bundlesequence => { "example" }; + bundlesequence => { "example" }; } - ######################################################## - bundle agent example - { processes: - - "cfservd" - - process_count => up("cfservd"); + "cfservd" process_count => up("cfservd"); cfservd_out_of_control:: - "cfservd" - - signals => { "stop" , "term" }, - restart_class => "start_cfserv"; - + signals => { "stop", "term" }, + restart_class => "start_cfserv"; commands: - start_cfserv:: - "/usr/local/bin/cfservd"; - } - ######################################################## - body process_count up(s) - { - match_range => "1,10"; # or irange("1","10"); - out_of_range_define => { "$(s)_out_of_control" }; + match_range => "1,10"; + # or irange("1","10"); + out_of_range_define => { "$(s)_out_of_control" }; } diff --git a/examples/processes_define_class_based_on_process_runtime.cf b/examples/processes_define_class_based_on_process_runtime.cf index 8fac6ece08..f8d8debc2d 100644 --- a/examples/processes_define_class_based_on_process_runtime.cf +++ b/examples/processes_define_class_based_on_process_runtime.cf @@ -10,22 +10,17 @@ # - main is the default bundle executed if no bundlesequence is defined in # 3.7+ ######################################################## - bundle agent main - { processes: - - "init" - process_count => any_count("booted_over_1_day_ago"), - process_select => days_older_than(1), - comment => "Define a class indicating we found an init process running + "init" + process_count => any_count("booted_over_1_day_ago"), + process_select => days_older_than(1), + comment => "Define a class indicating we found an init process running for more than 1 day."; reports: - booted_over_1_day_ago:: - "This system was booted over 1 days ago since there is an init process that is older than 1 day."; @@ -33,31 +28,25 @@ bundle agent main "This system has been rebooted recently as the init process has been running for less than a day"; } - ######################################################## - ######################################################## # NOTE: These bundles were copied from the stdlib in # order to make this a standalone policy that requires # no external files. Because the standard library is # constantly evolving their definition may change ######################################################## - body process_count any_count(cl) # @brief Define class `cl` if one or more process is running # @param cl Name of the class to be defined { - match_range => "0,0"; - out_of_range_define => { "$(cl)" }; + match_range => "0,0"; + out_of_range_define => { "$(cl)" }; } - ######################################################## - body process_select days_older_than(d) # @brief Select all processes that are older than `d` days # @param d Days that processes need to be old to be selected { - stime_range => irange(ago(0,0,"$(d)",0,0,0),now); - process_result => "!stime"; + stime_range => irange(ago(0, 0, "$(d)", 0, 0, 0), now); + process_result => "!stime"; } - diff --git a/examples/product.cf b/examples/product.cf index d8ce18d8fc..b0f0f2049e 100644 --- a/examples/product.cf +++ b/examples/product.cf @@ -1,42 +1,37 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - #+begin_src cfengine3 body common control { - bundlesequence => { "test" }; + bundlesequence => { "test" }; } bundle agent test { vars: - - "series" rlist => { "1.1", "2.2", "3.3", "5.5", "7.7" }; - - "prod" real => product("series"); - "sum" real => sum("series"); + "series" rlist => { "1.1", "2.2", "3.3", "5.5", "7.7" }; + "prod" real => product("series"); + "sum" real => sum("series"); reports: - "Product result: $(prod) > $(sum)"; + "Product result: $(prod) > $(sum)"; } #+end_src ############################################################################### diff --git a/examples/promises.cf b/examples/promises.cf index bfa7b1bae7..f94431709f 100644 --- a/examples/promises.cf +++ b/examples/promises.cf @@ -1,69 +1,60 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - ####################################################### # # The starting point for every configuration # ####################################################### - body common control - { - inputs => { "$(sys.libdir)/stdlib.cf" }; - bundlesequence => { "main", "cfengine2" }; + inputs => { "$(sys.libdir)/stdlib.cf" }; + bundlesequence => { "main", "cfengine2" }; } - ####################################################### - bundle agent main - { - # do something + # do something vars: - "sys_files" slist => { - "/etc/passwd", - "/etc/services" - }; + "sys_files" slist => { "/etc/passwd", "/etc/services" }; + files: - "$(sys_files)" perms => mo("0644", "root"), - changes => detect_content; - "/etc/shadow" perms => mo("0600", "root"), - changes => detect_content; - "/usr" changes => detect_content, + "$(sys_files)" + perms => mo("0644", "root"), + changes => detect_content; + + "/etc/shadow" + perms => mo("0600", "root"), + changes => detect_content; + + "/usr" + changes => detect_content, depth_search => recurse("inf"); - "/tmp" delete => tidy, - file_select => days_old("2"), + + "/tmp" + delete => tidy, + file_select => days_old("2"), depth_search => recurse("inf"); } - ####################################################### - bundle agent cfengine2 - { commands: - - "/var/cfengine/bin/cfagent"; - - + "/var/cfengine/bin/cfagent"; } diff --git a/examples/quoting.cf b/examples/quoting.cf index e28dff0f4a..2acdc94187 100644 --- a/examples/quoting.cf +++ b/examples/quoting.cf @@ -17,7 +17,6 @@ bundle agent main "$(double_escape)"; `$(backtick_escape)`; } - ############################################################################### #+begin_src example_output #@ ``` @@ -29,6 +28,3 @@ bundle agent main #@ R: Note: You can't escape backtick quotes #@ ``` #+end_src - - - diff --git a/examples/randomint.cf b/examples/randomint.cf index c33cf4c064..43f77f96c1 100644 --- a/examples/randomint.cf +++ b/examples/randomint.cf @@ -1,35 +1,32 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - #+begin_src cfengine3 bundle agent main { vars: - "low" string => "4"; - "high" string => "60"; + "low" string => "4"; + "high" string => "60"; + "random" int => randomint($(low), $(high)); - "random" int => randomint($(low), $(high)); classes: - "isabove" expression => isgreaterthan($(random), 3); + "isabove" expression => isgreaterthan($(random), 3); reports: isabove:: diff --git a/examples/read_module_protocol.cf b/examples/read_module_protocol.cf index bffd155757..ed37cd9f98 100644 --- a/examples/read_module_protocol.cf +++ b/examples/read_module_protocol.cf @@ -1,13 +1,12 @@ bundle agent cache_maintenance # Creates a module protocol cache, refreshes it if minute is 30-35 { - vars: - "file" - string => "$(this.promise_dirname)/cached_module"; + vars: + "file" string => "$(this.promise_dirname)/cached_module"; classes: - "cache_refresh" - if => not(fileexists("$(file)")); + "cache_refresh" if => not(fileexists("$(file)")); + Min30_35:: "cache_refresh"; @@ -23,22 +22,18 @@ bundle agent cache_maintenance bundle agent demo # Demonstrates read_module_protocol function, prints a variable from it { - classes: - "cache_was_read" - if => read_module_protocol("$(cache_maintenance.file)"); + classes: + "cache_was_read" if => read_module_protocol("$(cache_maintenance.file)"); - reports: - cache_was_read:: - "Module cache was read!"; - "cached_module.my_variable = $(cached_module.my_variable)"; + reports: + cache_was_read:: + "Module cache was read!"; + "cached_module.my_variable = $(cached_module.my_variable)"; } - bundle agent __main__ { methods: - "cache_maintenance" - handle => "cache_maintenance_done"; - "demo" - depends_on => { "cache_maintenance_done" }; + "cache_maintenance" handle => "cache_maintenance_done"; + "demo" depends_on => { "cache_maintenance_done" }; } diff --git a/examples/readcsv.cf b/examples/readcsv.cf index e0fa7199ab..b9be625fef 100644 --- a/examples/readcsv.cf +++ b/examples/readcsv.cf @@ -1,25 +1,22 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - #+begin_src prep #@ ``` #@ echo -n 1,2,3 > /tmp/csv @@ -30,16 +27,13 @@ bundle agent main { vars: - - # note that the CSV file has to have ^M (DOS) EOL terminators - # thus the prep step uses `echo -n` and just one line, so it will work on Unix - "csv" data => readcsv("/tmp/csv"); - "csv_str" string => format("%S", csv); + # note that the CSV file has to have ^M (DOS) EOL terminators + # thus the prep step uses `echo -n` and just one line, so it will work on Unix + "csv" data => readcsv("/tmp/csv"); + "csv_str" string => format("%S", csv); reports: - - "From /tmp/csv, got data $(csv_str)"; - + "From /tmp/csv, got data $(csv_str)"; } #+end_src ############################################################################### diff --git a/examples/readdata.cf b/examples/readdata.cf index 38bc103820..021b3799d5 100644 --- a/examples/readdata.cf +++ b/examples/readdata.cf @@ -1,25 +1,22 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - #+begin_src prep #@ ``` #@ echo -n 1,2,3 > /tmp/file.csv @@ -33,25 +30,32 @@ bundle agent main { vars: + "csv" data => readdata("/tmp/file.csv", "auto"); - "csv" data => readdata("/tmp/file.csv", "auto"); # or file type "CSV" - "json" data => readdata("/tmp/file.json", "auto"); # or file type "JSON" + # or file type "CSV" + "json" data => readdata("/tmp/file.json", "auto"); - "csv_str" string => format("%S", csv); - "json_str" string => format("%S", json); + # or file type "JSON" + "csv_str" string => format("%S", csv); + "json_str" string => format("%S", json); - feature_yaml:: # we can only test YAML data if libyaml is compiled in - "yaml" data => readdata("/tmp/file.yaml", "auto"); # or file type "YAML" + feature_yaml:: + # we can only test YAML data if libyaml is compiled in + "yaml" data => readdata("/tmp/file.yaml", "auto"); + + # or file type "YAML" "yaml_str" string => format("%S", yaml); + reports: + "From /tmp/file.csv, got data $(csv_str)"; + "From /tmp/file.json, got data $(json_str)"; - "From /tmp/file.csv, got data $(csv_str)"; - "From /tmp/file.json, got data $(json_str)"; feature_yaml:: "From /tmp/file.yaml, we would get data $(yaml_str)"; - !feature_yaml:: # show the output anyway - 'From /tmp/file.yaml, we would get data ["a","b"]'; + !feature_yaml:: + # show the output anyway + 'From /tmp/file.yaml, we would get data ["a","b"]'; } #+end_src ############################################################################### diff --git a/examples/readenvfile.cf b/examples/readenvfile.cf index efaf2f4651..3ea4868be7 100644 --- a/examples/readenvfile.cf +++ b/examples/readenvfile.cf @@ -1,25 +1,22 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - #+begin_src prep #@ ``` #@ echo 'PRETTY_NAME="Ubuntu 14.04.5 LTS"' > /tmp/os-release @@ -30,49 +27,44 @@ # Definitions (from standard library): body edit_defaults empty { - empty_file_before_editing => "true"; - edit_backup => "false"; + empty_file_before_editing => "true"; + edit_backup => "false"; } bundle edit_line insert_lines(lines) { - insert_lines: - "$(lines)"; + insert_lines: + "$(lines)"; } body printfile cat(file) { - file_to_print => "$(file)"; - number_of_lines => "inf"; + file_to_print => "$(file)"; + number_of_lines => "inf"; } # empty, insert_lines() and cat() are part of the standard library # To import the standard library, remove them and uncomment this line: # body file control { inputs => { "$(sys.libdir)/stdlib.cf" }; } - bundle agent main { - classes: - "file_found" expression => fileexists("/tmp/os-release"); - - # Use readenvfile() to load /tmp/os-release, then convert to json: - vars: - file_found:: - "envdata" - data => readenvfile("/tmp/os-release"); - "jsonstring" - string => storejson(envdata); + classes: + "file_found" expression => fileexists("/tmp/os-release"); + # Use readenvfile() to load /tmp/os-release, then convert to json: + vars: + file_found:: + "envdata" data => readenvfile("/tmp/os-release"); + "jsonstring" string => storejson(envdata); + # Print input(os-release) and output(json) files: + reports: + file_found:: + "/tmp/os-release :" printfile => cat("/tmp/os-release"); + "/tmp/os-release converted to json:"; + "$(jsonstring)"; + "(The data for this system is available in sys.os_release)"; - # Print input(os-release) and output(json) files: - reports: - file_found:: - "/tmp/os-release :" - printfile => cat("/tmp/os-release"); - "/tmp/os-release converted to json:"; - "$(jsonstring)"; - "(The data for this system is available in sys.os_release)"; - !file_found:: - "/tmp/os-release doesn't exist, run this command:"; - "echo 'PRETTY_NAME=\"Ubuntu 14.04.5 LTS\"' > /tmp/os-release"; + !file_found:: + "/tmp/os-release doesn't exist, run this command:"; + "echo 'PRETTY_NAME=\"Ubuntu 14.04.5 LTS\"' > /tmp/os-release"; } #+end_src ############################################################################### diff --git a/examples/readfile.cf b/examples/readfile.cf index ca3a040e28..1076848a96 100644 --- a/examples/readfile.cf +++ b/examples/readfile.cf @@ -1,25 +1,22 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - #+begin_src prep #@ ``` #@ echo alpha > /tmp/cfe_hostlist @@ -31,17 +28,16 @@ #+begin_src cfengine3 body common control { - bundlesequence => { "example" }; + bundlesequence => { "example" }; } bundle agent example { vars: + "xxx" string => readfile("/tmp/cfe_hostlist", "5"); - "xxx" - string => readfile( "/tmp/cfe_hostlist" , "5" ); reports: - "first 5 characters of /tmp/cfe_hostlist: $(xxx)"; + "first 5 characters of /tmp/cfe_hostlist: $(xxx)"; } #+end_src ############################################################################### diff --git a/examples/readintarray.cf b/examples/readintarray.cf index 857063bda3..ab87c95a0c 100644 --- a/examples/readintarray.cf +++ b/examples/readintarray.cf @@ -1,25 +1,22 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - #+begin_src prep #@ ``` #@ echo 1: 5:7:21:13 > /tmp/readintarray.txt @@ -31,21 +28,16 @@ ############################################################################### #+begin_src cfengine3 bundle agent main - { vars: - - "lines" int => readintarray("array_name", - "/tmp/readintarray.txt", - "#[^\n]*", - ":", - 10, - 4000); + "lines" + int => readintarray( + "array_name", "/tmp/readintarray.txt", "#[^\n]*", ":", 10, 4000 + ); reports: - "array_name contains $(lines) keys$(const.n)$(with)" - with => string_mustache("{{%-top-}}", "array_name"); - + "array_name contains $(lines) keys$(const.n)$(with)" + with => string_mustache("{{%-top-}}", "array_name"); } #+end_src ############################################################################### diff --git a/examples/readintlist.cf b/examples/readintlist.cf index 5e38cc9eba..9b04755700 100644 --- a/examples/readintlist.cf +++ b/examples/readintlist.cf @@ -10,19 +10,27 @@ bundle agent example_readintlist # @brief Example showing function return types { vars: - "my_list_of_integers" - ilist => readintlist( "/tmp/list.txt", # File to read - "^(\D+)|(\d+[^\n]+)", # Ignore any lines that are not integers - "\n", # Split on newlines - inf, # Maximum number of entries - inf); # Maximum number of bytes to read - + "my_list_of_integers" + ilist => readintlist( + "/tmp/list.txt", + # File to read + "^(\D+)|(\d+[^\n]+)", + # Ignore any lines that are not integers + "\n", + # Split on newlines + inf, + # Maximum number of entries + inf + ); + # Maximum number of bytes to read reports: - "my_list_of_integers includes '$(my_list_of_integers)'"; + "my_list_of_integers includes '$(my_list_of_integers)'"; } + bundle agent __main__ { - methods: "example_readintlist"; + methods: + "example_readintlist"; } #+end_src #+begin_src example_output diff --git a/examples/readintrealstringlist.cf b/examples/readintrealstringlist.cf index d3456be414..6c137f270f 100644 --- a/examples/readintrealstringlist.cf +++ b/examples/readintrealstringlist.cf @@ -1,25 +1,22 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - #+begin_src prep #@ ``` #@ echo 1 > /tmp/cfe_list_ints @@ -43,23 +40,27 @@ #+begin_src cfengine3 body common control { - bundlesequence => { "example" }; + bundlesequence => { "example" }; } bundle agent example { vars: + "integers" + ilist => readintlist("/tmp/cfe_list_ints", "#[^\n]*", "[\n]", 10, 400); - "integers" ilist => readintlist("/tmp/cfe_list_ints","#[^\n]*","[\n]",10,400); - "strings" slist => readstringlist("/tmp/cfe_list_strings", "#[^\n]*", "\s", 10, 400); - "reals" rlist => readreallist("/tmp/cfe_list_reals","#[^\n]*","[\n]",10,400); - - reports: + "strings" + slist => readstringlist( + "/tmp/cfe_list_strings", "#[^\n]*", "\s", 10, 400 + ); - "integers in /tmp/cfe_list_ints: $(integers)"; - "strings in /tmp/cfe_list_strings: $(strings)"; - "reals in /tmp/cfe_list_reals: $(reals)"; + "reals" + rlist => readreallist("/tmp/cfe_list_reals", "#[^\n]*", "[\n]", 10, 400); + reports: + "integers in /tmp/cfe_list_ints: $(integers)"; + "strings in /tmp/cfe_list_strings: $(strings)"; + "reals in /tmp/cfe_list_reals: $(reals)"; } #+end_src ############################################################################### diff --git a/examples/readlist.cf b/examples/readlist.cf index 6cb581bd1c..8504947b92 100644 --- a/examples/readlist.cf +++ b/examples/readlist.cf @@ -1,45 +1,32 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - - - body common control - { - bundlesequence => { "example" }; + bundlesequence => { "example" }; } - ########################################################### - bundle agent example - -{ +{ vars: - - "mylist" ilist => { readintlist("/tmp/listofint","#.*","[\n]",10,400) }; + "mylist" ilist => { readintlist("/tmp/listofint", "#.*", "[\n]", 10, 400) }; reports: - - "List entry: $(mylist)"; - + "List entry: $(mylist)"; } - diff --git a/examples/readrealarray.cf b/examples/readrealarray.cf index 0191f294b6..fc96f1ec37 100644 --- a/examples/readrealarray.cf +++ b/examples/readrealarray.cf @@ -1,25 +1,22 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - #+begin_src prep #@ ``` #@ echo "1: 5.0:7:21:13" > /tmp/readrealarray.txt @@ -33,18 +30,14 @@ bundle agent main { vars: - - "lines" int => readrealarray("array_name", - "/tmp/readrealarray.txt", - "#[^\n]*", - ":", - 10, - 4000); + "lines" + int => readrealarray( + "array_name", "/tmp/readrealarray.txt", "#[^\n]*", ":", 10, 4000 + ); reports: - "array_name contains $(lines) keys$(const.n)$(with)" - with => string_mustache("{{%-top-}}", "array_name"); - + "array_name contains $(lines) keys$(const.n)$(with)" + with => string_mustache("{{%-top-}}", "array_name"); } #+end_src ############################################################################### diff --git a/examples/readreallist.cf b/examples/readreallist.cf index 1171026c02..879d7cd575 100644 --- a/examples/readreallist.cf +++ b/examples/readreallist.cf @@ -10,19 +10,27 @@ bundle agent example_readreallist # @brief Example showing function return types { vars: - "my_list_of_reals" - rlist => readreallist( "/tmp/list.txt", # File to read - "^(\D+)", # Ignore any non-digits - "\n", # Split on newlines - inf, # Maximum number of entries - inf ); # Maximum number of bytes to read - + "my_list_of_reals" + rlist => readreallist( + "/tmp/list.txt", + # File to read + "^(\D+)", + # Ignore any non-digits + "\n", + # Split on newlines + inf, + # Maximum number of entries + inf + ); + # Maximum number of bytes to read reports: - "my_list_of_reals includes '$(my_list_of_reals)'"; + "my_list_of_reals includes '$(my_list_of_reals)'"; } + bundle agent __main__ { - methods: "example_readreallist"; + methods: + "example_readreallist"; } #+end_src #+begin_src example_output diff --git a/examples/readstringarray.cf b/examples/readstringarray.cf index 36ab7745c8..fe291e2426 100644 --- a/examples/readstringarray.cf +++ b/examples/readstringarray.cf @@ -1,25 +1,22 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - #+begin_src prep #@ ``` #@ echo "at:x:25:25:Batch jobs daemon:/var/spool/atjobs:/bin/bash" > /tmp/readstringarray.txt @@ -35,18 +32,14 @@ bundle agent main { vars: - - "lines" int => readstringarray("array_name", - "/tmp/readstringarray.txt", - "#[^\n]*", - ":", - 10, - 4000); + "lines" + int => readstringarray( + "array_name", "/tmp/readstringarray.txt", "#[^\n]*", ":", 10, 4000 + ); reports: - "array_name contains $(lines) keys$(const.n)$(with)" - with => string_mustache("{{%-top-}}", "array_name"); - + "array_name contains $(lines) keys$(const.n)$(with)" + with => string_mustache("{{%-top-}}", "array_name"); } #+end_src ############################################################################### diff --git a/examples/readstringlist.cf b/examples/readstringlist.cf index 8a4c2fefb9..9258dc7965 100644 --- a/examples/readstringlist.cf +++ b/examples/readstringlist.cf @@ -13,19 +13,27 @@ bundle agent example_readstringlist # @brief Example showing readstringlist() { vars: - "my_list_of_strings" - slist => readstringlist( "/tmp/list.txt", # File to read - "^\s*#[^\n]*", # Exclude hash comment lines lines - "\n", # Split on newlines - inf, # Maximum number of entries - inf); # Maximum number of bytes to read - + "my_list_of_strings" + slist => readstringlist( + "/tmp/list.txt", + # File to read + "^\s*#[^\n]*", + # Exclude hash comment lines lines + "\n", + # Split on newlines + inf, + # Maximum number of entries + inf + ); + # Maximum number of bytes to read reports: - "my_list_of_strings includes '$(my_list_of_strings)'"; + "my_list_of_strings includes '$(my_list_of_strings)'"; } + bundle agent __main__ { - methods: "example_readstringlist"; + methods: + "example_readstringlist"; } #+end_src #+begin_src example_output diff --git a/examples/readtcp.cf b/examples/readtcp.cf index c0da53d756..94d3fcfca3 100644 --- a/examples/readtcp.cf +++ b/examples/readtcp.cf @@ -1,49 +1,47 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - #+begin_src cfengine3 body common control { - bundlesequence => { "example" }; + bundlesequence => { "example" }; } bundle agent example { vars: - - "my80" string => readtcp("myserver.com","80","GET /index.html HTTP/1.1$(const.r)$(const.n)Host: myserver.com$(const.r)$(const.n)$(const.r)$(const.n)",20); + "my80" + string => readtcp( + "myserver.com", + "80", + "GET /index.html HTTP/1.1$(const.r)$(const.n)Host: myserver.com$(const.r)$(const.n)$(const.r)$(const.n)", + 20 + ); classes: - - "server_ok" expression => regcmp("[^\n]*200 OK.*\n.*","$(my80)"); + "server_ok" expression => regcmp("[^\n]*200 OK.*\n.*", "$(my80)"); reports: - server_ok:: - "Server is alive"; !server_ok:: - "Server is not responding - got $(my80)"; } #+end_src diff --git a/examples/reference_values_inside_data.cf b/examples/reference_values_inside_data.cf index 9ea7507b55..b2a4838fdf 100755 --- a/examples/reference_values_inside_data.cf +++ b/examples/reference_values_inside_data.cf @@ -3,8 +3,8 @@ bundle agent example_reference_values_inside_data { vars: - - "data" data => '{ + "data" + data => '{ "Key1": "Value1", "Key2": "Value2", "Key3": [ @@ -18,9 +18,11 @@ bundle agent example_reference_values_inside_data "Key2 contains '$(data[Key2])'"; "Key3 iterates and contains '$(data[Key3])'"; } + bundle agent __main__ { - methods: "example_reference_values_inside_data"; + methods: + "example_reference_values_inside_data"; } #+end_src ############################################################################### diff --git a/examples/reg_multiline.cf b/examples/reg_multiline.cf index 3a3bd571f3..64eec68a84 100644 --- a/examples/reg_multiline.cf +++ b/examples/reg_multiline.cf @@ -1,30 +1,29 @@ ############################################# # Matching multiple lines in regexp (PCRE) ############################################## - body common control { - bundlesequence => { "example" }; + bundlesequence => { "example" }; } bundle agent example { vars: - "data" string => "Something boring is + "data" + string => "Something boring is written up here. This is the interesting part: KWYDK (know what you don't know)"; classes: - - # note the (?s) at the beginning of the pattern - this ensures newlines are matched by . - - "matched" expression => regextract("(?s).*: (.*)", "$(data)", "interesting"); + # note the (?s) at the beginning of the pattern - this ensures newlines are matched by . + "matched" + expression => regextract("(?s).*: (.*)", "$(data)", "interesting"); reports: matched:: "This is interesting: \"$(interesting[1])\""; - + !matched:: "Nothing was interesting!"; } diff --git a/examples/regarray.cf b/examples/regarray.cf index d1e4953b06..d217efa544 100644 --- a/examples/regarray.cf +++ b/examples/regarray.cf @@ -1,53 +1,44 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - #+begin_src cfengine3 body common control { - bundlesequence => { "example" }; + bundlesequence => { "example" }; } bundle agent example { vars: - - "myarray[0]" string => "bla1"; - "myarray[1]" string => "bla2"; - "myarray[3]" string => "bla"; + "myarray[0]" string => "bla1"; + "myarray[1]" string => "bla2"; + "myarray[3]" string => "bla"; classes: - - "ok" expression => regarray("myarray","b.*2"); + "ok" expression => regarray("myarray", "b.*2"); reports: - ok:: - "Found in list"; !ok:: - "Not found in list"; - } #+end_src ############################################################################### diff --git a/examples/regcmp.cf b/examples/regcmp.cf index 87988028ba..e1c429d025 100644 --- a/examples/regcmp.cf +++ b/examples/regcmp.cf @@ -1,45 +1,38 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - #+begin_src cfengine3 body common control { - bundlesequence => { subtest("mark") }; + bundlesequence => { subtest("mark") }; } 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"; invalid:: - "User name $(user) is invalid"; } #+end_src diff --git a/examples/regex_replace.cf b/examples/regex_replace.cf index 48fb79b6fc..e5886fe00e 100644 --- a/examples/regex_replace.cf +++ b/examples/regex_replace.cf @@ -1,44 +1,51 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - #+begin_src cfengine3 bundle agent main { vars: - # global regex replace A with B - "AB" string => regex_replace("This has AAA rating", "A", "B", "g"); - # global regex replace [Aa] with B (case insensitive) - "AaB" string => regex_replace("This has AAA rating", "A", "B", "gi"); - # global replace every three characters with [cap=thecharacters] using $1 - "cap123" string => regex_replace("abcdefghijklmn", "(...)", "[cap=$1]", "g"); - # multiple captures using \1 \2 (just like $1 $2 but can only go up to \9) - "path_breakdown" string => regex_replace("/a/b/c/example.txt", "(.+)/(.+)", "dirname = \1 file basename = \2", ""); + # global regex replace A with B + "AB" string => regex_replace("This has AAA rating", "A", "B", "g"); + + # global regex replace [Aa] with B (case insensitive) + "AaB" string => regex_replace("This has AAA rating", "A", "B", "gi"); + + # global replace every three characters with [cap=thecharacters] using $1 + "cap123" + string => regex_replace("abcdefghijklmn", "(...)", "[cap=$1]", "g"); + + # multiple captures using \1 \2 (just like $1 $2 but can only go up to \9) + "path_breakdown" + string => regex_replace( + "/a/b/c/example.txt", + "(.+)/(.+)", + "dirname = \1 file basename = \2", + "" + ); reports: - # in order, the above... - "AB replacement = '$(AB)'"; - "AaB replacement = '$(AaB)'"; - "cap123 replacement = '$(cap123)'"; - "path_breakdown replacement = '$(path_breakdown)'"; + # in order, the above... + "AB replacement = '$(AB)'"; + "AaB replacement = '$(AaB)'"; + "cap123 replacement = '$(cap123)'"; + "path_breakdown replacement = '$(path_breakdown)'"; } #+end_src ############################################################################### diff --git a/examples/regex_win.cf b/examples/regex_win.cf index e68f8c79f8..542d3b8945 100644 --- a/examples/regex_win.cf +++ b/examples/regex_win.cf @@ -1,26 +1,19 @@ ###################################################################### # Using path regular expressions on Windows (always forward slash) ###################################################################### - body common control { - bundlesequence => { "example" }; + bundlesequence => { "example" }; } - ######################################################## - bundle agent example { files: - "c:/test/.*.xml" - edit_line => add_information(); + "c:/test/.*.xml" edit_line => add_information(); } - ######################################################## - bundle edit_line add_information() { insert_lines: - "a line" - comment => "adding line"; + "a line" comment => "adding line"; } diff --git a/examples/regextract.cf b/examples/regextract.cf index ada8232f5a..56039c9846 100644 --- a/examples/regextract.cf +++ b/examples/regextract.cf @@ -1,46 +1,39 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - #+begin_src cfengine3 body common control { - bundlesequence => { "example" }; + bundlesequence => { "example" }; } bundle agent example { classes: - - # Extract regex backreferences and put them in an array - - "ok" expression => regextract( - "xx ([^\s]+) ([^\s]+).* xx", - "xx one two three four xx", - "myarray" + # Extract regex backreferences and put them in an array + "ok" + expression => regextract( + "xx ([^\s]+) ([^\s]+).* xx", "xx one two three four xx", "myarray" ); - reports: + reports: ok:: - "ok - \"$(myarray[0])\" = xx + \"$(myarray[1])\" + \"$(myarray[2])\" + .. + xx"; } #+end_src diff --git a/examples/registry.cf b/examples/registry.cf index ebda7ba8a3..0e4ef8048e 100644 --- a/examples/registry.cf +++ b/examples/registry.cf @@ -1,74 +1,49 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - - - - body common control { - - bundlesequence => { "databases" }; + bundlesequence => { "databases" }; } - bundle agent databases - { databases: - windows:: - # Regsitry has (value,data) pairs in "keys" which are directories - # "HKEY_LOCAL_MACHINE\SOFTWARE\Northern.tech AS" - # database_operation => "create", # database_type => "ms_registry"; - # "HKEY_LOCAL_MACHINE\SOFTWARE\Northern.tech AS\Cfengine" - # database_operation => "create", # database_rows => { "value1,REG_SZ,new value 1", "value2,REG_SZ,new val 2"} , # database_type => "ms_registry"; - - "HKEY_LOCAL_MACHINE\SOFTWARE\Northern.tech AS\Cfengine" - - database_operation => "delete", - database_columns => { "value1", "value2" } , - database_type => "ms_registry"; - + database_operation => "delete", + database_columns => { "value1", "value2" }, + database_type => "ms_registry"; # "HKEY_LOCAL_MACHINE\SOFTWARE\Northern.tech AS\Cfengine" - # database_operation => "cache", # cache,restore - # registry_exclude => { ".*Windows.*CurrentVersion.*", ".*Touchpad.*", ".*Capabilities.FileAssociations.*", ".*Rfc1766.*" , ".*Synaptics.SynTP.*", ".*SupportedDevices.*8086", ".*Microsoft.*ErrorThresholds" }, - # database_type => "ms_registry"; - "HKEY_LOCAL_MACHINE\SOFTWARE\Northern.tech AS" - - database_operation => "restore", - database_type => "ms_registry"; - + database_operation => "restore", + database_type => "ms_registry"; } diff --git a/examples/registry_cache.cf b/examples/registry_cache.cf index 729341d0cc..f09b032069 100644 --- a/examples/registry_cache.cf +++ b/examples/registry_cache.cf @@ -1,53 +1,41 @@ # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - body common control { - bundlesequence => { - # "registry_cache" - # "registry_restore" - }; + bundlesequence => { + # "registry_cache"# "registry_restore" + }; } - ######################################### - bundle agent registry_cache { databases: windows:: - "HKEY_LOCAL_MACHINE\SOFTWARE\Adobe" - database_operation => "cache", - database_type => "ms_registry", - comment => "Save correct registry settings for Adobe products"; + database_operation => "cache", + database_type => "ms_registry", + comment => "Save correct registry settings for Adobe products"; } - ######################################### - bundle agent registry_restore { databases: windows:: - "HKEY_LOCAL_MACHINE\SOFTWARE\Adobe" - database_operation => "restore", - database_type => "ms_registry", - comment => "Make sure Adobe products have correct registry settings"; + database_operation => "restore", + database_type => "ms_registry", + comment => "Make sure Adobe products have correct registry settings"; } diff --git a/examples/registryvalue.cf b/examples/registryvalue.cf index 685600459b..97104593ae 100644 --- a/examples/registryvalue.cf +++ b/examples/registryvalue.cf @@ -1,42 +1,42 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - #+begin_src cfengine3 body common control { - bundlesequence => { "reg" }; + bundlesequence => { "reg" }; } bundle agent reg { vars: windows:: - "value" string => registryvalue("HKEY_LOCAL_MACHINE\SOFTWARE\Northern.tech AS\CFEngine","value3"); + "value" + string => registryvalue( + "HKEY_LOCAL_MACHINE\SOFTWARE\Northern.tech AS\CFEngine", "value3" + ); + !windows:: "value" string => "Sorry, no registry data is available"; reports: - "Value extracted: $(value)"; - + "Value extracted: $(value)"; } #+end_src ############################################################################### diff --git a/examples/regline.cf b/examples/regline.cf index 2c91c067f8..8c2f0fec2b 100644 --- a/examples/regline.cf +++ b/examples/regline.cf @@ -1,56 +1,47 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - ###################################################################### # Function regline(regex,file) ###################################################################### - #+begin_src cfengine3 bundle agent main # @brief An example showing how to use regline to see if a pattern exists within # a file. { vars: - linux:: - "file" string => "/proc/sys/net/ipv4/ip_forward"; "reg_enabled" string => "^1$"; "reg_disabled" string => "^0$"; classes: - linux:: - "ipv4_forwarding_enabled" -> { "SecOps" } - expression => regline( $(reg_enabled) , $(file) ), + expression => regline($(reg_enabled), $(file)), comment => "We want to know if ip forwarding is enabled because it is a potential security issue."; "ipv4_forwarding_disabled" -> { "SecOps" } - expression => regline( $(reg_disabled) , $(file) ); + expression => regline($(reg_disabled), $(file)); reports: - ipv4_forwarding_enabled:: "I found that IPv4 forwarding is enabled!"; @@ -58,7 +49,6 @@ bundle agent main "I found that IPv4 forwarding is disabled."; } #+end_src - #+begin_src random_example_output #@ ``` #@ R: I found that IPv4 forwarding is disabled. diff --git a/examples/reglist.cf b/examples/reglist.cf index 5090c6dcf7..3c7d6cedd6 100644 --- a/examples/reglist.cf +++ b/examples/reglist.cf @@ -1,47 +1,43 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - #+begin_src cfengine3 body common control { - bundlesequence => { "example" }; + bundlesequence => { "example" }; } bundle agent example { vars: - - "nameservers" slist => { - "128.39.89.10", - "128.39.74.16", - "192.168.1.103", - "10.132.51.66" + "nameservers" + slist => { + "128.39.89.10", "128.39.74.16", "192.168.1.103", "10.132.51.66" }; + classes: + "am_name_server" expression => reglist(@(nameservers), "127\.0\.0\.1"); - "am_name_server" expression => reglist(@(nameservers), "127\.0\.0\.1"); reports: am_name_server:: "127.0.0.1 is currently set as a nameserver"; + !am_name_server:: "127.0.0.1 is NOT currently set as a nameserver"; } diff --git a/examples/remoteclasses.cf b/examples/remoteclasses.cf index 7e2b2f9280..f788b944da 100644 --- a/examples/remoteclasses.cf +++ b/examples/remoteclasses.cf @@ -1,32 +1,27 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - - ######################################################## # # Remote classes from server connection to cfServer # ######################################################## - # # run this as follows: # @@ -34,142 +29,99 @@ # cf-agent -f runtest_2.cf # # Notice that the same file configures all parts of cfengine - ######################################################## - body common control - { - bundlesequence => { job_chain("Hr16|Hr17") }; - - version => "1.2.3"; + bundlesequence => { job_chain("Hr16|Hr17") }; + version => "1.2.3"; } - ######################################################## - bundle common g { vars: - - # Signals are in scope of promiser and promisee - - "signal" string => "pack_a_name"; - + # Signals are in scope of promiser and promisee + "signal" string => "pack_a_name"; } - ######################################################## - bundle agent job_chain(time) - { vars: - - "client" string => "localhost"; - "server" string => "localhost"; - "margin" string => "5"; # mins deadtime - + "client" string => "localhost"; + "server" string => "localhost"; + "margin" string => "5"; + # mins deadtime classes: - - "client_primed" expression => classmatch(canonify("$(client)")), + "client_primed" + expression => classmatch(canonify("$(client)")), if => "$(time)"; - "server_primed" expression => classmatch(canonify("$(server)")), + "server_primed" + expression => classmatch(canonify("$(server)")), if => "$(time)"; client_primed:: - - "succeeded" expression => remoteclassesmatching("$(g.signal)","$(server)","yes","myprefix"); - - # - # Now the job itself - # - + "succeeded" + expression => remoteclassesmatching( + "$(g.signal)", "$(server)", "yes", "myprefix" + ); + # Now the job itself methods: - client_primed:: - - "downstream" usebundle => do_job("Starting local follow-up job"), - action => if_elapsed("$(margin)"), - if => "myprefix_$(g.signal)"; + "downstream" + usebundle => do_job("Starting local follow-up job"), + action => if_elapsed("$(margin)"), + if => "myprefix_$(g.signal)"; server_primed:: - - "upstream" usebundle => do_job("Starting remote job"), - action => if_elapsed("$(margin)"), - classes => signal_repaired("$(g.signal)"); + "upstream" + usebundle => do_job("Starting remote job"), + action => if_elapsed("$(margin)"), + classes => signal_repaired("$(g.signal)"); reports: - !succeeded:: - - "Server communication failed" - - if => "$(time)"; - - - "Job completed on the server..." - - if => "$(g.signal)"; - + "Server communication failed" if => "$(time)"; + "Job completed on the server..." if => "$(g.signal)"; } - ######################################################### - bundle agent do_job(job) { commands: - - # do whatever... - - "/bin/echo $(job)"; + # do whatever... + "/bin/echo $(job)"; } - - ######################################################### # Server config ######################################################### - -body server control - +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 access_rules() - { vars: - - "localvar" string => "literal string"; + "localvar" string => "literal string"; access: - - "$(g.signal)" - - handle => "test_class_signal", + "$(g.signal)" + handle => "test_class_signal", resource_type => "context", - admit => { "127.0.0.1" }; + admit => { "127.0.0.1" }; } - - ######################################################### # Standard library ######################################################### - body action if_elapsed(x) { - ifelapsed => "$(x)"; + ifelapsed => "$(x)"; } - ######################################################### - body classes signal_repaired(x) { - promise_repaired => { "$(x)" }; - persist_time => "10"; + promise_repaired => { "$(x)" }; + persist_time => "10"; } diff --git a/examples/remoteclasses2.cf b/examples/remoteclasses2.cf index 65b51bfa37..b19f80a5c2 100644 --- a/examples/remoteclasses2.cf +++ b/examples/remoteclasses2.cf @@ -1,28 +1,23 @@ -# - body common control { - bundlesequence => { "overture" }; - inputs => { "$(sys.libdir)/stdlib.cf" }; + bundlesequence => { "overture" }; + inputs => { "$(sys.libdir)/stdlib.cf" }; } - ####################################################### - bundle agent overture { classes: - "extended_context" - expression => remoteclassesmatching(".*did.*","127.0.0.1","yes","got"); + "extended_context" + expression => remoteclassesmatching( + ".*did.*", "127.0.0.1", "yes", "got" + ); files: - - "/etc/passwd" + "/etc/passwd" create => "true", classes => set_outcome_classes; - reports: - got_did_task_one:: "task 1 complete"; @@ -31,34 +26,27 @@ bundle agent overture 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"; } -body server control - +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 server access_rules() { access: - - "did.*" + "did.*" resource_type => "context", admit => { "127.0.0.1" }; - } diff --git a/examples/remotescalar.cf b/examples/remotescalar.cf index 3acdf1ac51..64b3291522 100644 --- a/examples/remotescalar.cf +++ b/examples/remotescalar.cf @@ -1,89 +1,70 @@ - # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - ######################################################################## # # Testing comms for remote orchestration # ######################################################################## - body common control { - bundlesequence => { "overture" }; - inputs => { "$(sys.libdir)/stdlib.cf" }; + bundlesequence => { "overture" }; + inputs => { "$(sys.libdir)/stdlib.cf" }; } -body server control - +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"); + "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" - + # 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: - "GOT remote scalar $(remote)"; - "GOT knowedge scalar $(know)"; - "GOT persistent scalar $(xyz)"; - + "GOT remote scalar $(remote)"; + "GOT knowedge scalar $(know)"; + "GOT persistent scalar $(xyz)"; } - ####################################################### - bundle server access_rules() { access: - - "value of my test_scalar, can expand variables here - $(sys.host)" + "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" + "XYZ" resource_type => "variable", handle => "XYZ", admit => { "127.0.0.1" }; - } diff --git a/examples/remove_deadlinks.cf b/examples/remove_deadlinks.cf index abc1d8aac6..ddbc93ba6f 100644 --- a/examples/remove_deadlinks.cf +++ b/examples/remove_deadlinks.cf @@ -1,74 +1,53 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - ####################################################### # # Test dead link removal # ####################################################### - body common control - { - bundlesequence => { "example" }; + bundlesequence => { "example" }; } - - ############################################ - bundle agent example - { files: - - "/home/mark/tmp/test_to" -> "someone" - + "/home/mark/tmp/test_to" -> "someone" depth_search => recurse("inf"), perms => modestuff, action => tell_me; - } - ############################################ - body depth_search recurse(d) - { - rmdeadlinks => "true"; - depth => "$(d)"; + rmdeadlinks => "true"; + depth => "$(d)"; } - ############################################ - body perms modestuff - { - mode => "o-w"; + mode => "o-w"; } - ############################################ - body action tell_me - { - report_level => "inform"; + report_level => "inform"; } diff --git a/examples/rename.cf b/examples/rename.cf index 2d0e4ad644..eea57b9083 100644 --- a/examples/rename.cf +++ b/examples/rename.cf @@ -1,42 +1,34 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - - body common control { - bundlesequence => {"test"}; + bundlesequence => { "test" }; } bundle agent example { files: - - "/tmp/foo" - - rename => moveit; - + "/tmp/foo" rename => moveit; } -body rename moveit +body rename moveit { - newname => "/tmp/foo_moved"; + newname => "/tmp/foo_moved"; } diff --git a/examples/repairedcommand.cf b/examples/repairedcommand.cf index cdaedd009f..911177df80 100644 --- a/examples/repairedcommand.cf +++ b/examples/repairedcommand.cf @@ -1,24 +1,20 @@ -body common control -{ - bundlesequence => { "cmdtest" }; -} - - -bundle agent cmdtest -{ - commands: - "/bin/false" - classes => example; - - reports: - wasrepaired:: - "The command-promise got repaired!"; -} - - - -body classes example -{ - repaired_returncodes => { "0", "1" }; - promise_repaired => { "wasrepaired" }; -} +body common control +{ + bundlesequence => { "cmdtest" }; +} + +bundle agent cmdtest +{ + commands: + "/bin/false" classes => example; + + reports: + wasrepaired:: + "The command-promise got repaired!"; +} + +body classes example +{ + repaired_returncodes => { "0", "1" }; + promise_repaired => { "wasrepaired" }; +} diff --git a/examples/report_custom.cf b/examples/report_custom.cf index 0dfd335476..0f4ec7c73d 100644 --- a/examples/report_custom.cf +++ b/examples/report_custom.cf @@ -1,70 +1,52 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - - - - body common control { - bundlesequence => { "example" }; + bundlesequence => { "example" }; } bundle agent example { vars: - - "software" slist => { "gpg", "zip", "rsync" }; + "software" slist => { "gpg", "zip", "rsync" }; classes: - - "noreport" expression => fileexists("/tmp/report.html"); - "have_$(software)" expression => fileexists("/usr/bin/$(software)"); + "noreport" 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)", - report_to_file => "/tmp/report.html"; - - # + if => "have_$(software)", + report_to_file => "/tmp/report.html"; " - " - report_to_file => "/tmp/report.html"; - + " report_to_file => "/tmp/report.html"; } diff --git a/examples/report_state.cf b/examples/report_state.cf index c0afd959ce..f72b134d0e 100644 --- a/examples/report_state.cf +++ b/examples/report_state.cf @@ -1,51 +1,37 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - - body common control - { - bundlesequence => { "report" }; + bundlesequence => { "report" }; } - ########################################################### - bundle agent report - -{ +{ reports: - "/etc/passwd except $(const.n)" - - printfile => pr("/etc/passwd","5"), - + "/etc/passwd except $(const.n)" + printfile => pr("/etc/passwd", "5"), showstate => { "otherprocs", "rootprocs" }; - } - ###################################################################### - -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)"; } diff --git a/examples/reports.cf b/examples/reports.cf index b2f7590c50..c8a0be4652 100644 --- a/examples/reports.cf +++ b/examples/reports.cf @@ -2,50 +2,49 @@ bundle agent main { reports: - "It's recommended that you always guard reports" - comment => "Remember by default output from cf-agent when run + "It's recommended that you always guard reports" + comment => "Remember by default output from cf-agent when run from cf-execd will be emailed"; DEBUG|DEBUG_main:: "Run with --define DEBUG or --define DEBUG_main to display this report"; methods: - "Actuate bundle that reports with a return value" - usebundle => bundle_with_return_value, - useresult => "return_array", - comment => "Reports can be used to return data into a parent bundle. + "Actuate bundle that reports with a return value" + usebundle => bundle_with_return_value, + useresult => "return_array", + comment => "Reports can be used to return data into a parent bundle. This is useful in some re-usable bundle patterns."; reports: - "I got '$(return_array[key])' returned from bundle_with_return_value"; + "I got '$(return_array[key])' returned from bundle_with_return_value"; - "Reports can be redirected and appended to files" - report_to_file => "$(sys.workdir)/report_output.txt", - comment => "It's important to note that this will suppress the report + "Reports can be redirected and appended to files" + report_to_file => "$(sys.workdir)/report_output.txt", + comment => "It's important to note that this will suppress the report from stdout."; - "Report content of a file:$(const.n)$(const.n)------------------------" - printfile => cat( $(this.promise_filename) ); + "Report content of a file:$(const.n)$(const.n)------------------------" + printfile => cat($(this.promise_filename)); } bundle agent bundle_with_return_value { reports: - "value from bundle_with_return_value" - bundle_return_value_index => "key"; + "value from bundle_with_return_value" bundle_return_value_index => "key"; } body printfile cat(file) { - file_to_print => "$(file)"; - number_of_lines => "inf"; + file_to_print => "$(file)"; + number_of_lines => "inf"; } @if minimum_version(3.8) body printfile head(file) { - inherit_from => "cat"; - # GNU head defaults to 10 - number_of_lines => "10"; + inherit_from => "cat"; + # GNU head defaults to 10 + number_of_lines => "10"; } @endif diff --git a/examples/reporttofile.cf b/examples/reporttofile.cf index 5c617ab3a4..5e11b65e11 100644 --- a/examples/reporttofile.cf +++ b/examples/reporttofile.cf @@ -1,36 +1,29 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - - body common control { - bundlesequence => { "example" }; + bundlesequence => { "example" }; } -# - bundle agent example { reports: - "$(sys.date),This is a report" - report_to_file => "/tmp/test_log"; + "$(sys.date),This is a report" report_to_file => "/tmp/test_log"; } diff --git a/examples/resolveconf.cf b/examples/resolveconf.cf index 11368c5065..225c0ac3f0 100644 --- a/examples/resolveconf.cf +++ b/examples/resolveconf.cf @@ -1,116 +1,80 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - ####################################################### # # Resolve conf # ####################################################### - -bundle common g # globals +bundle common g +# globals { vars: + "searchlist" slist => { "search iu.hio.no", "search cfengine.com" }; + "nameservers" slist => { "128.39.89.10", "128.39.74.16", "192.168.1.103" }; - "searchlist" slist => { - "search iu.hio.no", - "search cfengine.com" - }; - - "nameservers" slist => { - "128.39.89.10", - "128.39.74.16", - "192.168.1.103" - }; classes: - - "am_name_server" expression => reglist("@(nameservers)","$(sys.ipv4[eth1])"); + "am_name_server" + expression => reglist("@(nameservers)", "$(sys.ipv4[eth1])"); } - ####################################################### - body common control - { - any:: - - bundlesequence => { - "g", - resolver(@(g.searchlist),@(g.nameservers)) - }; - - domain => "iu.hio.no"; + any:: + bundlesequence => { "g", resolver(@(g.searchlist), @(g.nameservers)) }; + domain => "iu.hio.no"; } - ####################################################### - -bundle agent resolver(s,n) - +bundle agent resolver(s, n) { files: - - # When passing parameters down, we have to refer to - # a source context - - "$(sys.resolv)" # test on "/tmp/resolv.conf" # - - create => "true", - edit_line => doresolv("@(this.s)","@(this.n)"), + # When passing parameters down, we have to refer to + # a source context + "$(sys.resolv)" + # test on "/tmp/resolv.conf" # + create => "true", + edit_line => doresolv("@(this.s)", "@(this.n)"), edit_defaults => reconstruct; - # or edit_defaults => modify + # or edit_defaults => modify } - ####################################################### # For the library ####################################################### - -bundle edit_line doresolv(s,n) - +bundle edit_line doresolv(s, n) { vars: - - "line" slist => { @(s), @(n) }; + "line" slist => { @(s), @(n) }; insert_lines: - - "$(line)"; - + "$(line)"; } - ####################################################### - body edit_defaults reconstruct { - empty_file_before_editing => "true"; - edit_backup => "false"; - max_file_size => "100000"; + empty_file_before_editing => "true"; + edit_backup => "false"; + max_file_size => "100000"; } - ####################################################### - body edit_defaults modify { - empty_file_before_editing => "false"; - edit_backup => "false"; - max_file_size => "100000"; + empty_file_before_editing => "false"; + edit_backup => "false"; + max_file_size => "100000"; } - - diff --git a/examples/returnszero.cf b/examples/returnszero.cf index 2fc409c66b..369e877600 100644 --- a/examples/returnszero.cf +++ b/examples/returnszero.cf @@ -1,43 +1,37 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - #+begin_src cfengine3 body common control { - bundlesequence => { "example" }; + bundlesequence => { "example" }; } bundle agent example { classes: - - "my_result" expression => returnszero("/usr/local/bin/mycommand","noshell"); + "my_result" + expression => returnszero("/usr/local/bin/mycommand", "noshell"); reports: - !my_result:: - "Command failed"; - } #+end_src ############################################################################### diff --git a/examples/reverse.cf b/examples/reverse.cf index 019c9bd09f..494ef7e04e 100644 --- a/examples/reverse.cf +++ b/examples/reverse.cf @@ -1,46 +1,41 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - #+begin_src cfengine3 body common control { - bundlesequence => { "test" }; + bundlesequence => { "test" }; } bundle agent test { vars: - "test" slist => { - 1,2,3, - "one", "two", "three", - "long string", - "one", "two", "three", + "test" + slist => { + 1, 2, 3, "one", "two", "three", "long string", "one", "two", "three", }; - "reversed" slist => reverse("test"); + "reversed" slist => reverse("test"); reports: - "Original list is $(test)"; - "The reversed list is $(reversed)"; + "Original list is $(test)"; + "The reversed list is $(reversed)"; } #+end_src ############################################################################### diff --git a/examples/root_passwd.cf b/examples/root_passwd.cf index 5c963a05cb..874e65bbfb 100644 --- a/examples/root_passwd.cf +++ b/examples/root_passwd.cf @@ -1,136 +1,105 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - ###################################################################### # # Root password distribution # ###################################################################### - body common control - { - version => "1.2.3"; - bundlesequence => { "SetRootPassword" }; + version => "1.2.3"; + bundlesequence => { "SetRootPassword" }; } - ######################################################## - bundle common g { vars: - - "secret_keys_dir" string => "/tmp"; - + "secret_keys_dir" string => "/tmp"; } - ######################################################## - bundle agent SetRootPassword - { files: + "/var/cfengine/ppkeys/rootpw.txt" + copy_from => scp("$(fqhost)-root.txt", "master_host.example.org"); - "/var/cfengine/ppkeys/rootpw.txt" - - copy_from => scp("$(fqhost)-root.txt","master_host.example.org"); - - # or $(pw_class)-root.txt - - # Test this on a copy - - "/tmp/shadow" - - edit_line => SetPasswd("root"); - + # or $(pw_class)-root.txt + # Test this on a copy + "/tmp/shadow" edit_line => SetPasswd("root"); } - ######################################################## - bundle edit_line SetPasswd(user) { vars: - - # Assume this file contains a single string of the form :passwdhash: - # with : delimiters to avoid end of line/file problems - - "gotpw" int => readstringarray("pw","$(sys.workdir)/ppkeys/root-pw.txt","#[^\n]*",":","3","200"); + # Assume this file contains a single string of the form :passwdhash: + # with : delimiters to avoid end of line/file problems + "gotpw" + int => readstringarray( + "pw", "$(sys.workdir)/ppkeys/root-pw.txt", "#[^\n]*", ":", "3", "200" + ); field_edits: - - "$(user).*" - - # Set field of the file to parameter - # File has format root:HASH: or user:HASH: - - edit_field => col(":","2","$(pw[root][1])","set"); + "$(user).*" edit_field => col(":", "2", "$(pw[root][1])", "set"); } - ######################################################## - bundle server passwords { vars: + # Read a file of format + # + # classname: host1,host2,host4,IP-address,regex.*,etc + "pw_classes" + int => readstringarray( + "acl", + "$(g.secret_keys_dir)/classes.txt", + "#[^\n]*", + ":", + "100", + "4000" + ); + + "each_pw_class" slist => getindices("acl"); - # Read a file of format - # - # classname: host1,host2,host4,IP-address,regex.*,etc - # - - "pw_classes" int => readstringarray("acl","$(g.secret_keys_dir)/classes.txt","#[^\n]*",":","100","4000"); - "each_pw_class" slist => getindices("acl"); - access: - - "/secret/keys/$(each_pw_class)-root.txt" - - admit => splitstring("$(acl[$(each_pw_class)][1])" , ":" , "100"), + "/secret/keys/$(each_pw_class)-root.txt" + admit => splitstring("$(acl[$(each_pw_class)][1])", ":", "100"), ifencrypted => "true"; - } - ######################################## # Bodies ######################################## - -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)"; - field_operation => "$(method)"; - extend_fields => "true"; - allow_blank_fields => "true"; + field_separator => "$(split)"; + select_field => "$(col)"; + value_separator => ","; + field_value => "$(newval)"; + field_operation => "$(method)"; + extend_fields => "true"; + allow_blank_fields => "true"; } - ######################################## - -body copy_from scp(from,server) - +body copy_from scp(from, server) { - source => "$(from)"; - compare => "digest"; - encrypt => "true"; - verify => "true"; + source => "$(from)"; + compare => "digest"; + encrypt => "true"; + verify => "true"; } diff --git a/examples/rxdirs.cf b/examples/rxdirs.cf index 81eeb9acdc..a2e9207b71 100644 --- a/examples/rxdirs.cf +++ b/examples/rxdirs.cf @@ -4,48 +4,44 @@ bundle agent __main__ # @brief Illustrating the behavior of rxdirs in perms bodies. { vars: - "example_dirs" slist => { - "/tmp/rxdirs_example/rxdirs=default(false)-r", - "/tmp/rxdirs_example/rxdirs=default(false)-rx", - "/tmp/rxdirs_example/rxdirs=true-r", - "/tmp/rxdirs_example/rxdirs=true-rx", + "example_dirs" + slist => { + "/tmp/rxdirs_example/rxdirs=default(false)-r", + "/tmp/rxdirs_example/rxdirs=default(false)-rx", + "/tmp/rxdirs_example/rxdirs=true-r", + "/tmp/rxdirs_example/rxdirs=true-rx", }; files: - "$(example_dirs)/." - create => "true"; - - "/tmp/rxdirs_example/rxdirs=default(false)-r" - perms => example:m( 600 ); - - "/tmp/rxdirs_example/rxdirs=default(false)-rx" - perms => example:m( 700 ); - - "/tmp/rxdirs_example/rxdirs=true-r" - perms => example:m_rxdirs_on( 600 ); - - "/tmp/rxdirs_example/rxdirs=true-rx" - perms => example:m_rxdirs_on( 700 ); + "$(example_dirs)/." create => "true"; + "/tmp/rxdirs_example/rxdirs=default(false)-r" perms => example:m(600); + "/tmp/rxdirs_example/rxdirs=default(false)-rx" perms => example:m(700); + "/tmp/rxdirs_example/rxdirs=true-r" perms => example:m_rxdirs_on(600); + "/tmp/rxdirs_example/rxdirs=true-rx" perms => example:m_rxdirs_on(700); reports: - "$(example_dirs) modeoct='$(with)'" - with => filestat( $(example_dirs), modeoct ); + "$(example_dirs) modeoct='$(with)'" + with => filestat($(example_dirs), modeoct); } -body file control{ namespace => "example"; } +body file control +{ + namespace => "example"; +} body perms m(mode) # @brief Set the file mode # @param mode The new mode { - mode => "$(mode)"; + mode => "$(mode)"; } + body perms m_rxdirs_on(mode) # @brief Set the file mode and set +x on directory when +r is desired # @param mode The new mode { - inherit_from => m( $(mode) ); - rxdirs => "true"; + inherit_from => m($(mode)); + rxdirs => "true"; } #+end_src ############################################################################### diff --git a/examples/select_class.cf b/examples/select_class.cf index 9eb150637c..c2a45eee3b 100644 --- a/examples/select_class.cf +++ b/examples/select_class.cf @@ -1,53 +1,39 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - - body common control { - bundlesequence => { "g" }; - + bundlesequence => { "g" }; } - ################################# - bundle common g { classes: - - "selection" select_class => { "one", "two" }; + "selection" select_class => { "one", "two" }; reports: - one:: - "One was selected"; two:: - "Two was selected"; selection:: - "A selection was made"; - } - diff --git a/examples/select_mode.cf b/examples/select_mode.cf index d7e0313b46..566dcfaeec 100644 --- a/examples/select_mode.cf +++ b/examples/select_mode.cf @@ -1,66 +1,48 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - ####################################################### # # Searching for permissions # ####################################################### - body common control - { - bundlesequence => { "example" }; + bundlesequence => { "example" }; } - ############################################ - bundle agent example - { files: - - "/home/mark/tmp/test_from" - + "/home/mark/tmp/test_from" 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)"; } - diff --git a/examples/select_region.cf b/examples/select_region.cf index 217c0be843..92965f1932 100644 --- a/examples/select_region.cf +++ b/examples/select_region.cf @@ -1,25 +1,22 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - #+begin_src prep #@ ``` #@ echo "MATCHING before region" > /tmp/example_select_region.txt @@ -29,48 +26,39 @@ #@ echo "MATCHING after region" >> /tmp/example_select_region.txt #@ ``` #+end_src - #+begin_src cfengine3 bundle agent main # @brief Demonstrate how edit_line can operate within a region of a file { - vars: - "file" string => "/tmp/example_select_region.txt"; - files: + "file" string => "/tmp/example_select_region.txt"; - "$(file)" - comment => "We want to delete any lines that begin with the string + files: + "$(file)" + comment => "We want to delete any lines that begin with the string MATCHING inside the region described by regular expressions matching the beginning and end of the region.", - create => "true", - edit_line => delete_inside_region("^MATCHING.*", - "^BEGIN.*", - "^END.*"); + create => "true", + edit_line => delete_inside_region("^MATCHING.*", "^BEGIN.*", "^END.*"); reports: - "$(file)" printfile => cat( $(this.promiser) ); + "$(file)" printfile => cat($(this.promiser)); } - ######################################################## - bundle edit_line delete_inside_region(line_reg, begin_reg, end_reg) # @brief Delete lines matching `line_reg` when found within the expected region starting with `begin_reg` and `end_reg` { delete_lines: - - "$(line_reg)" - select_region => between( $(begin_reg), $(end_reg) ); - + "$(line_reg)" select_region => between($(begin_reg), $(end_reg)); } body select_region between(start, end) # @brief Select a region exclusively between regular expressions `start` and `end`. { - select_start => "$(start)"; - select_end => "$(end)"; + select_start => "$(start)"; + select_end => "$(end)"; @if minimum_version(3.10) - select_end_match_eof => "false"; + select_end_match_eof => "false"; @endif } @@ -78,11 +66,10 @@ body printfile cat(file) # @brief Report the contents of a file # @param file The full path of the file to report { - file_to_print => "$(file)"; - number_of_lines => "inf"; + file_to_print => "$(file)"; + number_of_lines => "inf"; } #+end_src - #+begin_src example_output #@ ``` #@ R: /tmp/example_select_region.txt diff --git a/examples/select_size.cf b/examples/select_size.cf index 19da8064b2..9ca96af298 100644 --- a/examples/select_size.cf +++ b/examples/select_size.cf @@ -1,57 +1,45 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - - body common control { - bundlesequence => { "example" }; + bundlesequence => { "example" }; } -# - bundle agent example { files: - - # Show files in range - - "/home/mark/tmp" - - file_select => name_and_sizes(".*cf","100","300"), + # Show files in range + "/home/mark/tmp" + file_select => name_and_sizes(".*cf", "100", "300"), depth_search => recurse("1"), transformer => "/bin/ls -l $(this.promiser)"; - } -# - -body file_select name_and_sizes(n,x,y) +body file_select name_and_sizes(n, x, y) { - leaf_name => { "$(n)" }; - search_size => irange("$(x)", "$(y)"); - file_result => "leaf_name&size"; + leaf_name => { "$(n)" }; + search_size => irange("$(x)", "$(y)"); + file_result => "leaf_name&size"; } body depth_search recurse(x) { - depth => "$(x)"; + depth => "$(x)"; } diff --git a/examples/selectservers.cf b/examples/selectservers.cf index 0afd360160..4b5a22a042 100644 --- a/examples/selectservers.cf +++ b/examples/selectservers.cf @@ -1,70 +1,54 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - # # Testing some variable/class definitions - note scope # # Use browser -f promise_output_agent.html to view -# - body common control - { - bundlesequence => { "test" }; + bundlesequence => { "test" }; } - ########################################################### - bundle agent example - -{ +{ 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" }; - - # selectservers(hostlist,port,sendstr,regex_on_reply,maxbytesread_reply,array_name - - "up_servers" int => selectservers("@(hosts)","80","","","100","alive_servers"); + # selectservers(hostlist,port,sendstr,regex_on_reply,maxbytesread_reply,array_name + "up_servers" + int => selectservers("@(hosts)", "80", "", "", "100", "alive_servers"); classes: - - "someone_alive" expression => isgreaterthan("$(up_servers)","0"); - - "i_am_a_server" expression => regarray("up_servers","$(host)|$(fqhost)"); + "someone_alive" expression => isgreaterthan("$(up_servers)", "0"); + "i_am_a_server" expression => regarray("up_servers", "$(host)|$(fqhost)"); reports: - someone_alive:: - "Number of active servers $(up_servers)" action => always; - "First server $(alive_servers[0]) fails over to $(alive_servers[1])"; - - } - ############################################################# - body action always { - ifelapsed => "0"; + ifelapsed => "0"; } diff --git a/examples/server_callback.cf b/examples/server_callback.cf index 3383fce61e..de65c8350b 100644 --- a/examples/server_callback.cf +++ b/examples/server_callback.cf @@ -1,30 +1,27 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - ######################################################## # # Simple test copy from server connection to cfServer # ######################################################## - # # run this as follows: # @@ -32,61 +29,47 @@ # cf-agent -f runtest_2.cf # # Notice that the same file configures all parts of cfengine - - ######################################################## - body common control { - bundlesequence => { "example" }; - version => "1.2.3"; + bundlesequence => { "example" }; + version => "1.2.3"; } - ######################################################## - bundle agent example { vars: } - ######################################################### # Server config ######################################################### - body server control - { - allowconnects => { "127.0.0.1" , "::1" }; - allowallconnects => { "127.0.0.1" , "::1" }; - trustkeysfrom => { "127.0.0.1" , "::1" }; - call_collect_interval => "5"; + allowconnects => { "127.0.0.1", "::1" }; + allowallconnects => { "127.0.0.1", "::1" }; + trustkeysfrom => { "127.0.0.1", "::1" }; + call_collect_interval => "5"; } - ######################################################### - bundle server access_rules() - { - access: - # On the policy hub am_policy_hub:: - "collect_calls" - comment => "Enable call-collect report collection for the specific client", - resource_type => "query", - admit => { "1.2.3.4" }; + comment => "Enable call-collect report collection for the specific client", + resource_type => "query", + admit => { "1.2.3.4" }; # On the isolated clients in the field any:: - "delta" - comment => "Grant access to cfengine hub to collect report deltas", - resource_type => "query", - admit => { "$(sys.policy_hub)" }; + comment => "Grant access to cfengine hub to collect report deltas", + resource_type => "query", + admit => { "$(sys.policy_hub)" }; + "full" - comment => "Grant access to cfengine hub to collect full report dump", - resource_type => "query", - admit => { "$(sys.policy_hub)" }; + comment => "Grant access to cfengine hub to collect full report dump", + resource_type => "query", + admit => { "$(sys.policy_hub)" }; } diff --git a/examples/server_copy_localhost.cf b/examples/server_copy_localhost.cf index 8c78bf92c5..a43be896be 100644 --- a/examples/server_copy_localhost.cf +++ b/examples/server_copy_localhost.cf @@ -1,30 +1,27 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - ######################################################## # # Simple test copy from server connection to cfServer # ######################################################## - # # run this as follows: # @@ -32,108 +29,77 @@ # cf-agent -f runtest_2.cf # # Notice that the same file configures all parts of cfengine - - ######################################################## - body common control { - bundlesequence => { "example" }; - version => "1.2.3"; - #fips_mode => "true"; + bundlesequence => { "example" }; + version => "1.2.3"; + #fips_mode => "true"; } - ######################################################## - bundle agent example { - files: - - "/tmp/testcopy" - comment => "test copy promise", - copy_from => mycopy("/tmp/test-src","127.0.0.1"), - perms => system, + files: + "/tmp/testcopy" + comment => "test copy promise", + copy_from => mycopy("/tmp/test-src", "127.0.0.1"), + perms => system, depth_search => recurse("inf"), - classes => satisfied("copy_ok"); + classes => satisfied("copy_ok"); - "/tmp/testcopy/single_file" - - comment => "test copy promise", - copy_from => mycopy("/tmp/test-src/README","127.0.0.1"), - perms => system; + "/tmp/testcopy/single_file" + comment => "test copy promise", + copy_from => mycopy("/tmp/test-src/README", "127.0.0.1"), + perms => system; reports: - copy_ok:: - "Files were copied.."; } - ######################################################### - body perms system - { - mode => "0644"; + mode => "0644"; } - ######################################################### - body depth_search recurse(d) - { - depth => "$(d)"; + depth => "$(d)"; } - ######################################################### - -body copy_from mycopy(from,server) - +body copy_from mycopy(from, server) { - source => "$(from)"; - servers => { "$(server)" }; - compare => "digest"; - encrypt => "true"; - verify => "true"; - copy_backup => "true"; #/false/timestamp - purge => "false"; - type_check => "true"; - force_ipv4 => "true"; - trustkey => "true"; + source => "$(from)"; + servers => { "$(server)" }; + compare => "digest"; + encrypt => "true"; + verify => "true"; + copy_backup => "true"; + #/false/timestamp + purge => "false"; + type_check => "true"; + force_ipv4 => "true"; + trustkey => "true"; } - ######################################################### - body classes satisfied(x) { - promise_repaired => { "$(x)" }; - persist_time => "0"; + promise_repaired => { "$(x)" }; + persist_time => "0"; } - ######################################################### # Server config ######################################################### - -body server control - +body server control { - allowconnects => { "127.0.0.1" , "::1" }; - allowallconnects => { "127.0.0.1" , "::1" }; - trustkeysfrom => { "127.0.0.1" , "::1" }; - # allowusers + allowconnects => { "127.0.0.1", "::1" }; + allowallconnects => { "127.0.0.1", "::1" }; + trustkeysfrom => { "127.0.0.1", "::1" }; + # allowusers } - ######################################################### - bundle server access_rules() - { - access: - - "/tmp/test-src" - - admit => { "127.0.0.1" }; + "/tmp/test-src" admit => { "127.0.0.1" }; } - - diff --git a/examples/server_copy_purge.cf b/examples/server_copy_purge.cf index 09a0056784..4e65e97f9a 100644 --- a/examples/server_copy_purge.cf +++ b/examples/server_copy_purge.cf @@ -1,31 +1,27 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - ######################################################## # # Simple test copy from server connection to cfServer # ######################################################## - # # run this as follows: # @@ -33,98 +29,69 @@ # cf-agent -f runtest_2.cf # # Notice that the same file configures all parts of cfengine - ######################################################## - body common control - { - bundlesequence => { "example" }; - version => "1.2.3"; + bundlesequence => { "example" }; + version => "1.2.3"; } - ######################################################## - bundle agent example - { files: - - "/home/mark/tmp/test_to" - - comment => "test copy promise", - copy_from => mycopy("/home/mark/tmp/test_from","127.0.0.1"), - perms => system, + "/home/mark/tmp/test_to" + comment => "test copy promise", + copy_from => mycopy("/home/mark/tmp/test_from", "127.0.0.1"), + perms => system, depth_search => recurse("inf"), - classes => satisfied("copy_ok"); + classes => satisfied("copy_ok"); reports: - copy_ok:: - "Files were copied.."; } - ######################################################### - body perms system - { - mode => "0644"; + mode => "0644"; } - ######################################################### - body depth_search recurse(d) - { - depth => "$(d)"; + depth => "$(d)"; } - ######################################################### - -body copy_from mycopy(from,server) - +body copy_from mycopy(from, server) { - source => "$(from)"; - servers => { "$(server)" }; - compare => "digest"; - verify => "true"; - copy_backup => "true"; #/false/timestamp - purge => "true"; - type_check => "true"; - force_ipv4 => "true"; - trustkey => "true"; + source => "$(from)"; + servers => { "$(server)" }; + compare => "digest"; + verify => "true"; + copy_backup => "true"; + #/false/timestamp + purge => "true"; + type_check => "true"; + force_ipv4 => "true"; + trustkey => "true"; } - ######################################################### - body classes satisfied(x) { - promise_repaired => { "$(x)" }; - persist_time => "0"; + promise_repaired => { "$(x)" }; + persist_time => "0"; } - ######################################################### # Server config ######################################################### - -body server control - +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 server access_rules() - { access: - - "/home/mark/tmp" - - admit => { "127.0.0.1" }; + "/home/mark/tmp" admit => { "127.0.0.1" }; } diff --git a/examples/server_copy_remote.cf b/examples/server_copy_remote.cf index fad85208a2..2dd22c9c96 100644 --- a/examples/server_copy_remote.cf +++ b/examples/server_copy_remote.cf @@ -1,32 +1,27 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - - ######################################################## # # Simple test copy from server connection to cfServer # ######################################################## - # # run this as follows: # @@ -35,97 +30,71 @@ # # Notice that the same file configures all parts of cfengine # even though different parts are read by different hosts and agents - ######################################################## - body common control - { - bundlesequence => { "example" }; + bundlesequence => { "example" }; } - ######################################################## - bundle agent example - { files: - - "/tmp/testcopy" - + "/tmp/testcopy" perms => system, - copy_from => mycopy("/src/document","remote-host.example.org"), + copy_from => mycopy("/src/document", "remote-host.example.org"), depth_search => recurse("inf"); - } - ######################################################## - body perms system - { - mode => "0444"; + mode => "0444"; } - ######################################################### - body depth_search recurse(d) - { - depth => "$(d)"; + depth => "$(d)"; } - ######################################################### - -body copy_from mycopy(from,server) - +body copy_from mycopy(from, server) { - source => "$(from)"; - #portnumber => "6789"; - servers => { "$(server)" , "failover1" }; - copy_backup => "true"; #/false/timestamp - stealth => "true"; #/on/false/off - preserve => "true"; - linkcopy_patterns => { ".*fish.*" }; - copylink_patterns => { "non-local.*"}; - compare => "mtime"; # ctime/mtime/checksum/sum/byte/binary/any - link_type => "absolute"; # /symbolic/relative/hard etc - type_check => "true"; - force_update => "false"; - force_ipv4 => "false"; - copy_size => irange("0","50000"); - trustkey => "true"; - encrypt => "true"; - verify => "true"; - purge => "false"; - findertype => "MacOSX"; + source => "$(from)"; + #portnumber => "6789"; + servers => { "$(server)", "failover1" }; + copy_backup => "true"; + #/false/timestamp + stealth => "true"; + #/on/false/off + preserve => "true"; + linkcopy_patterns => { ".*fish.*" }; + copylink_patterns => { "non-local.*" }; + compare => "mtime"; + # ctime/mtime/checksum/sum/byte/binary/any + link_type => "absolute"; + # /symbolic/relative/hard etc + type_check => "true"; + force_update => "false"; + force_ipv4 => "false"; + copy_size => irange("0", "50000"); + trustkey => "true"; + encrypt => "true"; + verify => "true"; + purge => "false"; + findertype => "MacOSX"; } - ######################################################### # Server config ######################################################### - -body server control - +body server control { - allowconnects => { "1.2.3.4" , "::1" }; - allowallconnects => { "1.2.3.4" , "::1" }; - trustkeysfrom => { "1.2.3.4" , "::1" }; - # allowusers + allowconnects => { "1.2.3.4", "::1" }; + allowallconnects => { "1.2.3.4", "::1" }; + trustkeysfrom => { "1.2.3.4", "::1" }; + # allowusers } - ######################################################### - bundle server access_rules() - { - access: - - # Grant access to the remote client to access the source docs - - "/src" admit => { "1.2.3.4" }; + # Grant access to the remote client to access the source docs + "/src" admit => { "1.2.3.4" }; } - - - diff --git a/examples/server_flatcopy_localhost.cf b/examples/server_flatcopy_localhost.cf index 5abd95241a..3fc85e590f 100644 --- a/examples/server_flatcopy_localhost.cf +++ b/examples/server_flatcopy_localhost.cf @@ -1,31 +1,27 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - ######################################################## # # Simple test copy from server connection to cfServer # ######################################################## - # # run this as follows: # @@ -33,106 +29,77 @@ # cf-agent -f runtest_2.cf # # Notice that the same file configures all parts of cfengine - ######################################################## - body common control - { - bundlesequence => { "example" }; - version => "1.2.3"; + bundlesequence => { "example" }; + version => "1.2.3"; } - ######################################################## - bundle agent example - { files: - - "/home/mark/tmp/testflatcopy" - - comment => "test copy promise", - copy_from => mycopy("/home/mark/LapTop/words","127.0.0.1"), - perms => system, + "/home/mark/tmp/testflatcopy" + comment => "test copy promise", + copy_from => mycopy("/home/mark/LapTop/words", "127.0.0.1"), + perms => system, depth_search => recurse("inf"), - classes => satisfied("copy_ok"); - + classes => satisfied("copy_ok"); - "/home/mark/tmp/testcopy/single_file" - - comment => "test copy promise", - copy_from => mycopy("/home/mark/LapTop/Cfengine3/trunk/README","127.0.0.1"), - perms => system; + "/home/mark/tmp/testcopy/single_file" + comment => "test copy promise", + copy_from => mycopy( + "/home/mark/LapTop/Cfengine3/trunk/README", "127.0.0.1" + ), + perms => system; reports: - copy_ok:: - "Files were copied.."; } - ######################################################### - body perms system - { - mode => "0644"; + mode => "0644"; } - ######################################################### - body depth_search recurse(d) - { - depth => "$(d)"; + depth => "$(d)"; } - ######################################################### - -body copy_from mycopy(from,server) - +body copy_from mycopy(from, server) { - source => "$(from)"; - servers => { "$(server)" }; - compare => "digest"; - verify => "true"; - copy_backup => "true"; #/false/timestamp - purge => "false"; - type_check => "true"; - force_ipv4 => "true"; - trustkey => "true"; - collapse_destination_dir => "true"; + source => "$(from)"; + servers => { "$(server)" }; + compare => "digest"; + verify => "true"; + copy_backup => "true"; + #/false/timestamp + purge => "false"; + type_check => "true"; + force_ipv4 => "true"; + trustkey => "true"; + collapse_destination_dir => "true"; } - ######################################################### - body classes satisfied(x) { - promise_repaired => { "$(x)" }; - persist_time => "0"; + promise_repaired => { "$(x)" }; + persist_time => "0"; } - ######################################################### # Server config ######################################################### - -body server control - +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 server access_rules() - { access: - - "/home/mark/LapTop" - - admit => { "127.0.0.1" }; + "/home/mark/LapTop" admit => { "127.0.0.1" }; } diff --git a/examples/service_catalogue.cf b/examples/service_catalogue.cf index b60e12eb8c..47e163647d 100644 --- a/examples/service_catalogue.cf +++ b/examples/service_catalogue.cf @@ -1,59 +1,44 @@ body common control { - bundlesequence => { "service_catalogue" }; + bundlesequence => { "service_catalogue" }; } - bundle agent service_catalogue { services: - "syslog" service_policy => "start"; - "www" service_policy => "stop"; + "syslog" service_policy => "start"; + "www" service_policy => "stop"; } - - bundle agent standard_services(service, state) { vars: - debian:: - - "startcommand[www]" string => "/etc/init.d/apache2 start"; - "stopcommand[www]" string => "/etc/init.d/apache2 stop"; - "processname[www]" string => "apache2"; - - "startcommand[syslog]" string => "/etc/init.d/rsyslog start"; - "stopcommand[syslog]" string => "/etc/init.d/rsyslog stop"; - "processname[syslog]" string => "rsyslogd"; - + "startcommand[www]" string => "/etc/init.d/apache2 start"; + "stopcommand[www]" string => "/etc/init.d/apache2 stop"; + "processname[www]" string => "apache2"; + "startcommand[syslog]" string => "/etc/init.d/rsyslog start"; + "stopcommand[syslog]" string => "/etc/init.d/rsyslog stop"; + "processname[syslog]" string => "rsyslogd"; classes: - - "start" expression => strcmp("start","$(state)"); - "stop" expression => strcmp("stop","$(state)"); + "start" expression => strcmp("start", "$(state)"); + "stop" expression => strcmp("stop", "$(state)"); processes: - start:: - ".*$(processname[$(service)]).*" - - comment => "Verify that the service appears in the process table", - restart_class => "restart_$(service)"; + comment => "Verify that the service appears in the process table", + restart_class => "restart_$(service)"; stop:: - ".*$(processname[$(service)]).*" - - comment => "Verify that the service does not appear in the process table", - process_stop => "$(stopcommand[$(service)])", - signals => { "term", "kill"}; + comment => "Verify that the service does not appear in the process table", + process_stop => "$(stopcommand[$(service)])", + signals => { "term", "kill" }; commands: - - "$(startcommand[$(service)])" - + "$(startcommand[$(service)])" comment => "Execute command to restart the $(service) service", if => "restart_$(service)"; } diff --git a/examples/service_catalogue_separate.cf b/examples/service_catalogue_separate.cf index 258c378447..983938c0af 100644 --- a/examples/service_catalogue_separate.cf +++ b/examples/service_catalogue_separate.cf @@ -1,33 +1,33 @@ body common control { - bundlesequence => { "service_catalogue_separate" }; + bundlesequence => { "service_catalogue_separate" }; } - bundle agent service_catalogue_separate { services: - "foo" service_policy => "start", + "foo" + service_policy => "start", service_method => service_bundle_separate; - "bar" service_policy => "stop", + "bar" + service_policy => "stop", service_method => service_bundle_separate; } body service_method service_bundle_separate { - service_bundle => $(this.promiser)("$(this.service_policy)"); + service_bundle => $(this.promiser)("$(this.service_policy)"); } - bundle agent foo(service_policy) { reports: - "we need to ensure $(service_policy) of foo"; + "we need to ensure $(service_policy) of foo"; } bundle agent bar(service_policy) { reports: - "we need to ensure $(service_policy) of bar"; + "we need to ensure $(service_policy) of bar"; } diff --git a/examples/service_disable.cf b/examples/service_disable.cf index 629fdae511..341e34bcaf 100644 --- a/examples/service_disable.cf +++ b/examples/service_disable.cf @@ -1,44 +1,31 @@ # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - body common control - { - bundlesequence => { "winservice" }; + bundlesequence => { "winservice" }; } - ########################################################### - bundle agent winservice - { vars: - - "bad_services" slist => { "Alerter", "ClipSrv" }; + "bad_services" slist => { "Alerter", "ClipSrv" }; services: - windows:: - "$(bad_services)" - - service_policy => "disable", - comment => "Disable services that create security issues"; + service_policy => "disable", + comment => "Disable services that create security issues"; } diff --git a/examples/service_start.cf b/examples/service_start.cf index a7544832ff..57b98aa012 100644 --- a/examples/service_start.cf +++ b/examples/service_start.cf @@ -1,26 +1,21 @@ -body common control -{ - bundlesequence => { "example" }; -} - +body common control +{ + bundlesequence => { "example" }; +} ############################################# - -bundle agent example -{ - services: - - "Themes" - service_policy => "start", - service_dependencies => { "Alerter" }, - service_method => exmethod; -} - +bundle agent example +{ + services: + "Themes" + service_policy => "start", + service_dependencies => { "Alerter" }, + service_method => exmethod; +} ############################################# - -body service_method exmethod -{ - service_type => "windows"; - service_args => "-f \"the file with spaces.cf\" --some-args"; - service_autostart_policy => "boot_time"; - service_dependence_chain => "start_parent_services"; -} +body service_method exmethod +{ + service_type => "windows"; + service_args => "-f \"the file with spaces.cf\" --some-args"; + service_autostart_policy => "boot_time"; + service_dependence_chain => "start_parent_services"; +} diff --git a/examples/services.cf b/examples/services.cf index edf58503f6..5ca211e861 100644 --- a/examples/services.cf +++ b/examples/services.cf @@ -8,22 +8,21 @@ bundle agent main # services { vars: - linux:: "enable[ssh]" - string => ifelse( "debian|ubuntu", "ssh", "sshd"), + string => ifelse("debian|ubuntu", "ssh", "sshd"), comment => "The name of the ssh service varies on different platforms. Here we set the name of the service based on existing classes and defaulting to `sshd`"; "disable[apache]" - string => ifelse( "debian|ubuntu", "apache2", "httpd" ), + string => ifelse("debian|ubuntu", "apache2", "httpd"), comment => "The name of the apache web service varies on different platforms. Here we set the name of the service based on existing classes and defaulting to `httpd`"; "enable[cron]" - string => ifelse( "debian|ubuntu", "cron", "crond" ), + string => ifelse("debian|ubuntu", "cron", "crond"), comment => "The name of the cron service varies on different platforms. Here we set the name of the service based on existing classes and defaulting to `crond`"; @@ -32,13 +31,11 @@ bundle agent main string => "cups", comment => "Printing services are not needed on most hosts."; - "enabled" slist => getvalues( enable ); - "disabled" slist => getvalues( disable ); + "enabled" slist => getvalues(enable); + "disabled" slist => getvalues(disable); services: - linux:: - "$(enabled)" -> { "SysOps" } service_policy => "start", comment => "These services should be running because x, y or z."; @@ -48,7 +45,6 @@ bundle agent main comment => "These services should not be running because x, y or z."; systemd:: - "sysstat" service_policy => "stop", comment => "Standard service handling for sysstat only works with diff --git a/examples/services_concept.cf b/examples/services_concept.cf index 9955b4fe06..ee12767bbd 100644 --- a/examples/services_concept.cf +++ b/examples/services_concept.cf @@ -1,126 +1,95 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - ##################################################################### # # Concept of standard services promises # ##################################################################### - body common control { - bundlesequence => { "example" }; + bundlesequence => { "example" }; } -# - bundle agent example { vars: - - "mail" slist => { "milter", "spamassassin", "postfix" }; - + "mail" slist => { "milter", "spamassassin", "postfix" }; services: - - "www" service_policy => "start", + "www" + service_policy => "start", service_method => service_test; - "$(mail)" service_policy => "stop", + "$(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 standard_services(service,state) +bundle agent standard_services(service, state) { - # DATA, - + # DATA, vars: - suse|redhat:: - - "startcommand[www]" string => "/etc/init.d/apache2 start"; - "stopcommand[www]" string => "/etc/init.d/apache2 stop"; + "startcommand[www]" string => "/etc/init.d/apache2 start"; + "stopcommand[www]" string => "/etc/init.d/apache2 stop"; debian|ubuntu:: - - "startcommand[www]" string => "/etc/init.d/httpd start"; - "stopcommand[www]" string => "/etc/init.d/httpd stop"; + "startcommand[www]" string => "/etc/init.d/httpd start"; + "stopcommand[www]" string => "/etc/init.d/httpd stop"; linux:: - "startcommand[postfix]" string => "/etc/init.d/postfix start"; - "stopcommand[postfix]" string => "/etc/init.d/postfix stop"; - - - # METHODS - + "stopcommand[postfix]" string => "/etc/init.d/postfix stop"; + # METHODS classes: - - "start" expression => strcmp("start","$(state)"); - "stop" expression => strcmp("stop","$(state)"); + "start" expression => strcmp("start", "$(state)"); + "stop" expression => strcmp("stop", "$(state)"); processes: - start:: - ".*$(service).*" - - comment => "Verify that the service appears in the process table", - restart_class => "restart_$(service)"; + comment => "Verify that the service appears in the process table", + restart_class => "restart_$(service)"; stop:: - ".*$(service).*" - - comment => "Verify that the service does not appear in the process", - process_stop => "$(stopcommand[$(service)])", - signals => { "term", "kill"}; + comment => "Verify that the service does not appear in the process", + process_stop => "$(stopcommand[$(service)])", + signals => { "term", "kill" }; commands: - - "$(startcommand[$(service)])" - + "$(startcommand[$(service)])" comment => "Execute command to restart the $(service) service", if => "restart_$(service)"; - } - ###################################################################### - -bundle agent non_standard_services(service,state) +bundle agent non_standard_services(service, state) { reports: - !done:: - "Test service promise for \"$(service)\" -> $(state)"; } diff --git a/examples/services_default_service_bundle.cf b/examples/services_default_service_bundle.cf index 2adeafc400..ffba70ef5e 100644 --- a/examples/services_default_service_bundle.cf +++ b/examples/services_default_service_bundle.cf @@ -2,26 +2,26 @@ bundle agent main # @brief Example showing how service_bundle is defaulted. { services: - "my-custom-service" + "my-custom-service" service_method => my_custom_service, service_policy => "stop"; } body service_method my_custom_service { - service_bundle => service_my_custom_service($(this.promiser), $(this.service_policy)); + service_bundle => service_my_custom_service( + $(this.promiser), $(this.service_policy) + ); } bundle agent service_my_custom_service(service, state) { reports: - "$(service) should have state $(state)"; + "$(service) should have state $(state)"; } - ############################################################################### #+begin_src example_output #@ ``` #@ R: my-custom-service should have state stop #@ ``` #+end_src - diff --git a/examples/services_win.cf b/examples/services_win.cf index 561e676979..0056bc3774 100644 --- a/examples/services_win.cf +++ b/examples/services_win.cf @@ -3,53 +3,34 @@ # win_services.cf - Windows Service Management # ######################################################################### - -body file control -{ - inputs => { "$(sys.libdir)/stdlib.cf" }; -} - -bundle agent win_services -{ - vars: - - # NOTE: Use "Service Name" (not "Display Name"); - # Administrative Tools -> Services -> Double Click on one to see its name - - "bad_services" slist => { - "RemoteRegistry" - }; - - - Windows_Server_2003_R2:: - - "autostart_services" slist => { - "Alerter", - "W32Time" # Windows Time - }; - - Windows_Server_2008:: - - "autostart_services" slist => { - "MpsSvc", # Windows Firewall - "W32Time" # Windows Time - }; - - - services: - - "$(bad_services)" - service_policy => "disable", - service_method => force_deps, - comment => "Disable services that create security issues"; - - - Windows_Server_2003_R2|Windows_Server_2008:: - - "$(autostart_services)" - service_policy => "start", - service_method => bootstart, - comment => "Make sure important services are running and set to start at boot time"; - -} - +body file control +{ + inputs => { "$(sys.libdir)/stdlib.cf" }; +} + +bundle agent win_services +{ + vars: + # NOTE: Use "Service Name" (not "Display Name"); + # Administrative Tools -> Services -> Double Click on one to see its name + "bad_services" slist => { "RemoteRegistry" }; + + Windows_Server_2003_R2:: + "autostart_services" slist => { "Alerter", "W32Time"# Windows Time }; + + Windows_Server_2008:: + "autostart_services" + slist => { "MpsSvc", # Windows Firewall "W32Time"# Windows Time }; + + services: + "$(bad_services)" + service_policy => "disable", + service_method => force_deps, + comment => "Disable services that create security issues"; + + Windows_Server_2003_R2|Windows_Server_2008:: + "$(autostart_services)" + service_policy => "start", + service_method => bootstart, + comment => "Make sure important services are running and set to start at boot time"; +} diff --git a/examples/setuidlog.cf b/examples/setuidlog.cf index 5f8c06873a..03075d9333 100644 --- a/examples/setuidlog.cf +++ b/examples/setuidlog.cf @@ -1,61 +1,43 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - - body common control - { - bundlesequence => { "example" }; + bundlesequence => { "example" }; } - ######################################################## - bundle agent example - { files: - - "/home/mark/tmp" -> "me" - - changes => tripwire, + "/home/mark/tmp" -> "me" + changes => tripwire, depth_search => recurse("1"); - } - - ######################################################### - body changes tripwire - { - hash => "md5"; - report_changes => "content"; - update_hashes => "true"; + hash => "md5"; + report_changes => "content"; + update_hashes => "true"; } - ######################################################### - body depth_search recurse(d) - { - depth => "$(d)"; + depth => "$(d)"; } diff --git a/examples/setvar.cf b/examples/setvar.cf index 84554960a1..61061b2951 100644 --- a/examples/setvar.cf +++ b/examples/setvar.cf @@ -1,56 +1,42 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - - body common control { - bundlesequence => { "setvars" }; - inputs => { "$(sys.libdir)/stdlib.cf" }; + bundlesequence => { "setvars" }; + inputs => { "$(sys.libdir)/stdlib.cf" }; } bundle agent setvars { vars: - - # want to set these values by the names of their array keys - - "rhs[lhs1]" string => " Mary had a little pig"; - "rhs[lhs2]" string => "Whose Fleece was white as snow"; - "rhs[lhs3]" string => "And everywhere that Mary went"; - - "rhs[net/ipv4/tcp_syncookies]" string => "1"; - "rhs[net/ipv4/icmp_echo_ignore_broadcasts]" string => "1"; - "rhs[net/ipv4/ip_forward]" string => "0"; - - # oops, now change pig -> lamb - + # want to set these values by the names of their array keys + "rhs[lhs1]" string => " Mary had a little pig"; + "rhs[lhs2]" string => "Whose Fleece was white as snow"; + "rhs[lhs3]" string => "And everywhere that Mary went"; + "rhs[net/ipv4/tcp_syncookies]" string => "1"; + "rhs[net/ipv4/icmp_echo_ignore_broadcasts]" string => "1"; + "rhs[net/ipv4/ip_forward]" string => "0"; + # oops, now change pig -> lamb files: - - - "/tmp/system" - + "/tmp/system" comment => "Create a file of variable assignments and manage this file", create => "true", edit_line => set_variable_values("setvars.rhs"); - } - diff --git a/examples/shuffle.cf b/examples/shuffle.cf index d8a96f91d7..6c341a561d 100644 --- a/examples/shuffle.cf +++ b/examples/shuffle.cf @@ -1,43 +1,38 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - #+begin_src cfengine3 body common control { - bundlesequence => { "test" }; + bundlesequence => { "test" }; } bundle agent test { vars: - "mylist" slist => { "b", "c", "a" }; - "seeds" slist => { "xx", "yy", "zz" }; - - "shuffled_$(seeds)" slist => shuffle(mylist, $(seeds)); - - "joined_$(seeds)" string => join(",", "shuffled_$(seeds)"); + "mylist" slist => { "b", "c", "a" }; + "seeds" slist => { "xx", "yy", "zz" }; + "shuffled_$(seeds)" slist => shuffle(mylist, $(seeds)); + "joined_$(seeds)" string => join(",", "shuffled_$(seeds)"); reports: - "shuffled RANDOMLY by $(seeds) = '$(joined_$(seeds))'"; + "shuffled RANDOMLY by $(seeds) = '$(joined_$(seeds))'"; } #+end_src ############################################################################### diff --git a/examples/simple_ssh_key_distribution.cf b/examples/simple_ssh_key_distribution.cf index 0ee199c906..bf928c949c 100644 --- a/examples/simple_ssh_key_distribution.cf +++ b/examples/simple_ssh_key_distribution.cf @@ -1,7 +1,7 @@ body common control { - bundlesequence => { "autorun_ssh_key_distribution" }; - inputs => { "$(sys.libdir)/stdlib.cf" }; + bundlesequence => { "autorun_ssh_key_distribution" }; + inputs => { "$(sys.libdir)/stdlib.cf" }; } bundle common ssh_key_info @@ -33,8 +33,8 @@ bundle agent autorun_ssh_key_distribution methods: "Distribute SSH Keys" - usebundle => ssh_key_distribution( $(users) ), - if => userexists( $(users) ), + usebundle => ssh_key_distribution($(users)), + if => userexists($(users)), comment => "It's important that we make sure each of these users ssh_authorized_keys file has the correct content and permissions so that they can successfully log in, if @@ -47,27 +47,28 @@ bundle agent ssh_key_distribution(users) "description" string => "Ensure that specified users are able to log in using their ssh keys"; + vars: # We get the users UID so that we can set permission appropriately - "uid[$(users)]" int => getuid( $(users) ); + "uid[$(users)]" int => getuid($(users)); files: "/home/$(users)/.ssh/." create => "true", - perms => mo( 700, "$(uid[$(users)])"), + perms => mo(700, "$(uid[$(users)])"), comment => "It is important to set the proper restrictive permissions and ownership so that the ssh authorized_keys feature works correctly."; "/home/$(users)/.ssh/authorized_keys" - perms => mo( 600, "$(uid[$(users)])" ), - copy_from => remote_dcp( "$(ssh_key_info.repo_path)/$(users)", - $(ssh_key_info.key_server) ), + perms => mo(600, "$(uid[$(users)])"), + copy_from => remote_dcp( + "$(ssh_key_info.repo_path)/$(users)", $(ssh_key_info.key_server) + ), comment => "We centrally manage and users authorized keys. We source each users complete authorized_keys file from the central server."; } - bundle server ssh_key_access_rules { meta: diff --git a/examples/software_dist.cf b/examples/software_dist.cf index 3c059ffde3..ca882f0444 100644 --- a/examples/software_dist.cf +++ b/examples/software_dist.cf @@ -1,23 +1,18 @@ # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - ######################################################################### # # software_local.cf - Application Deployment From Directory Repository @@ -45,131 +40,121 @@ # "cfengine-nova-1.1.2-i686.msi". # ######################################################################### - -body common control -{ - inputs => { "$(sys.libdir)/stdlib.cf" }; - bundlesequence => { "check_software" }; -} - -bundle agent check_software -{ - vars: - - # software to install if not installed - "include_software" slist => { - "7-zip-4.50-$(sys.arch).msi" - }; - - # this software gets updated if it is installed - "autoupdate_software" slist => { - "7-zip" - }; - - # software to uninstall if it is installed - "exclude_software" slist => { - "7-zip-4.65-$(sys.arch).msi" - }; - - methods: +body common control +{ + inputs => { "$(sys.libdir)/stdlib.cf" }; + bundlesequence => { "check_software" }; +} + +bundle agent check_software +{ + vars: + # software to install if not installed + "include_software" slist => { "7-zip-4.50-$(sys.arch).msi" }; + + # this software gets updated if it is installed + "autoupdate_software" slist => { "7-zip" }; + + # software to uninstall if it is installed + "exclude_software" slist => { "7-zip-4.65-$(sys.arch).msi" }; + + methods: # TODO: Fix the following bundles, msi_implicit is giving errors: - # "any" usebundle => add_software( "@(check_software.include_software)", "$(sys.policy_hub)" ); - # "any" usebundle => update_software( "@(check_software.autoupdate_software)", "$(sys.policy_hub)" ); - # "any" usebundle => remove_software( "@(check_software.exclude_software)", "$(sys.policy_hub)" ); -} - + # "any" usebundle => add_software( "@(check_software.include_software)", "$(sys.policy_hub)" ); + # "any" usebundle => update_software( "@(check_software.autoupdate_software)", "$(sys.policy_hub)" ); + # "any" usebundle => remove_software( "@(check_software.exclude_software)", "$(sys.policy_hub)" ); +} ######################################################################### - -bundle agent add_software(pkg_name, srv) -{ - vars: - # dir to install from locally - can also check multiple directories - "local_software_dir" string => "C:\Program Files\Cfengine\software\add"; - - files: - - "$(local_software_dir)" - copy_from => remote_cp("/var/cfengine/master_software_updates/$(sys.flavour)_$(sys.arch)/add", "$(srv)"), - depth_search => recurse("1"), - classes => if_repaired("got_newpkg"), - comment => "Copy software from remote repository"; - - - packages: - - # When to check if the package is installed ? - got_newpkg|any:: - "$(pkg_name)" - package_policy => "add", - package_method => msi_implicit( "$(local_software_dir)" ), - classes => if_else("add_success", "add_fail" ), - comment => "Install new software, if not already present"; - - reports: - add_fail:: - "Failed to install one or more packages"; -} - +bundle agent add_software(pkg_name, srv) +{ + vars: + # dir to install from locally - can also check multiple directories + "local_software_dir" string => "C:\Program Files\Cfengine\software\add"; + + files: + "$(local_software_dir)" + copy_from => remote_cp( + "/var/cfengine/master_software_updates/$(sys.flavour)_$(sys.arch)/add", + "$(srv)" + ), + depth_search => recurse("1"), + classes => if_repaired("got_newpkg"), + comment => "Copy software from remote repository"; + + packages: + # When to check if the package is installed ? + got_newpkg|any:: + "$(pkg_name)" + package_policy => "add", + package_method => msi_implicit("$(local_software_dir)"), + classes => if_else("add_success", "add_fail"), + comment => "Install new software, if not already present"; + + reports: + add_fail:: + "Failed to install one or more packages"; +} ######################################################################### - -bundle agent update_software(sw_names, srv) -{ - vars: - # dir to install from locally - can also check multiple directories - "local_software_dir" string => "C:\Program Files\Cfengine\software\update"; - - files: - - "$(local_software_dir)" - copy_from => remote_cp("/var/cfengine/master_software_updates/$(sys.flavour)_$(sys.arch)/update", "$(srv)"), - depth_search => recurse("1"), - classes => if_repaired("got_newpkg"), - comment => "Copy software updates from remote repository"; - - - packages: - - # When to check if the package is updated ? - got_newpkg|any:: - "$(sw_names)" - package_policy => "update", - package_select => ">=", # picks the newest update available - package_architectures => { "$(sys.arch)" }, # install 32 or 64 bit package ? - package_version => "1.0", # at least version 1.0 - package_method => msi_explicit( "$(local_software_dir)" ), - classes => if_else("update_success", "update_fail"); - - - reports: - update_fail:: - "Failed to update one or more packages"; -} - +bundle agent update_software(sw_names, srv) +{ + vars: + # dir to install from locally - can also check multiple directories + "local_software_dir" string => "C:\Program Files\Cfengine\software\update"; + + files: + "$(local_software_dir)" + copy_from => remote_cp( + "/var/cfengine/master_software_updates/$(sys.flavour)_$(sys.arch)/update", + "$(srv)" + ), + depth_search => recurse("1"), + classes => if_repaired("got_newpkg"), + comment => "Copy software updates from remote repository"; + + packages: + # When to check if the package is updated ? + got_newpkg|any:: + "$(sw_names)" + package_policy => "update", + package_select => ">=", + # picks the newest update available + package_architectures => { "$(sys.arch)" }, + # install 32 or 64 bit package ? + package_version => "1.0", + # at least version 1.0 + package_method => msi_explicit("$(local_software_dir)"), + classes => if_else("update_success", "update_fail"); + + reports: + update_fail:: + "Failed to update one or more packages"; +} ######################################################################### - -bundle agent remove_software(pkg_name, srv) -{ - vars: - # dir to install from locally - can also check multiple directories - "local_software_dir" string => "C:\Program Files\Cfengine\software\remove"; - - files: - - "$(local_software_dir)" - copy_from => remote_cp("/var/cfengine/master_software_updates/$(sys.flavour)_$(sys.arch)/remove", "$(srv)"), - depth_search => recurse("1"), - classes => if_repaired("got_newpkg"), - comment => "Copy removable software from remote repository"; - - packages: - got_newpkg:: - "$(pkg_name)" - package_policy => "delete", - package_method => msi_implicit( "$(local_software_dir)" ), - classes => if_else("remove_success", "remove_fail" ), - comment => "Remove software, if present"; - - reports: - remove_fail:: - "Failed to remove one or more packages"; -} +bundle agent remove_software(pkg_name, srv) +{ + vars: + # dir to install from locally - can also check multiple directories + "local_software_dir" string => "C:\Program Files\Cfengine\software\remove"; + + files: + "$(local_software_dir)" + copy_from => remote_cp( + "/var/cfengine/master_software_updates/$(sys.flavour)_$(sys.arch)/remove", + "$(srv)" + ), + depth_search => recurse("1"), + classes => if_repaired("got_newpkg"), + comment => "Copy removable software from remote repository"; + + packages: + got_newpkg:: + "$(pkg_name)" + package_policy => "delete", + package_method => msi_implicit("$(local_software_dir)"), + classes => if_else("remove_success", "remove_fail"), + comment => "Remove software, if present"; + + reports: + remove_fail:: + "Failed to remove one or more packages"; +} diff --git a/examples/software_update_version_yum.cf b/examples/software_update_version_yum.cf index 3df34b742e..710ef62946 100644 --- a/examples/software_update_version_yum.cf +++ b/examples/software_update_version_yum.cf @@ -1,55 +1,45 @@ -# # Schedule software update for yum-based distributions (e.g. RedHat, CentOS) # Will only update to the given package_version assumed to be found in the yum repository. # If installed version is the same as package_version or newer, no action is taken. -# - body common control { - bundlesequence => { "system_software" }; + bundlesequence => { "system_software" }; } - bundle agent system_software { classes: - "update_hosts" expression => "host1|host2"; - "update_schedule" expression => "Day27.Hr02.Min00_05"; + "update_hosts" expression => "host1|host2"; + "update_schedule" expression => "Day27.Hr02.Min00_05"; packages: update_hosts.update_schedule:: "bash" - comment => "Make sure bash package is updated to right version", - handle => "package_bash_update", - package_version => "3.2-32.el5", - package_architectures => { "x86_64" }, - package_policy => "addupdate", - package_select => ">=", - package_method => yum_version; - + comment => "Make sure bash package is updated to right version", + handle => "package_bash_update", + package_version => "3.2-32.el5", + package_architectures => { "x86_64" }, + package_policy => "addupdate", + package_select => ">=", + package_method => yum_version; } - body package_method yum_version { - package_changes => "bulk"; - package_list_command => "/bin/rpm -qa --qf '%{name} %{version}-%{release} %{arch}\n'"; - package_patch_list_command => "/usr/bin/yum check-update"; - - package_list_name_regex => "^(\S+?)\s\S+?\s\S+$"; - package_list_version_regex => "^\S+?\s(\S+?)\s\S+$"; - package_list_arch_regex => "^\S+?\s\S+?\s(\S+)$"; - - package_installed_regex => ".*"; - package_name_convention => "$(name)-$(version).$(arch)"; - - package_patch_installed_regex => "^\s.*"; - package_patch_name_regex => "([^.]+).*"; - package_patch_version_regex => "[^\s]\s+([^\s]+).*"; - package_patch_arch_regex => "[^.]+\.([^\s]+).*"; - - package_add_command => "/usr/bin/yum -y install"; - package_update_command => "/usr/bin/yum -y update"; - package_delete_command => "/bin/rpm -e --nodeps --allmatches"; - package_verify_command => "/bin/rpm -V"; + package_changes => "bulk"; + package_list_command => "/bin/rpm -qa --qf '%{name} %{version}-%{release} %{arch}\n'"; + package_patch_list_command => "/usr/bin/yum check-update"; + package_list_name_regex => "^(\S+?)\s\S+?\s\S+$"; + package_list_version_regex => "^\S+?\s(\S+?)\s\S+$"; + package_list_arch_regex => "^\S+?\s\S+?\s(\S+)$"; + package_installed_regex => ".*"; + package_name_convention => "$(name)-$(version).$(arch)"; + package_patch_installed_regex => "^\s.*"; + package_patch_name_regex => "([^.]+).*"; + package_patch_version_regex => "[^\s]\s+([^\s]+).*"; + package_patch_arch_regex => "[^.]+\.([^\s]+).*"; + package_add_command => "/usr/bin/yum -y install"; + package_update_command => "/usr/bin/yum -y update"; + package_delete_command => "/bin/rpm -e --nodeps --allmatches"; + package_verify_command => "/bin/rpm -V"; } diff --git a/examples/some.cf b/examples/some.cf index bbcfa210d6..6364dd12cc 100644 --- a/examples/some.cf +++ b/examples/some.cf @@ -1,95 +1,107 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - #+begin_src cfengine3 body common control { - bundlesequence => { "test" }; + bundlesequence => { "test" }; } bundle agent test { classes: - - # This is an easy way to check if a list is empty, better than - # expression => strcmp(length(x), "0") - - # Note that if you use length() or none() or every() they will - # go through all the elements!!! some() returns as soon as any - # element matches. - "empty_x" not => some(".*", x); - "empty_y" not => some(".*", y); - - "some11" expression => some("long string", test1); - "some12" expression => some("none", test1); - "some21" expression => some("long string", test2); - "some22" expression => some("none", test2); + # This is an easy way to check if a list is empty, better than + # expression => strcmp(length(x), "0") + # Note that if you use length() or none() or every() they will + # go through all the elements!!! some() returns as soon as any + # element matches. + "empty_x" not => some(".*", x); + "empty_y" not => some(".*", y); + "some11" expression => some("long string", test1); + "some12" expression => some("none", test1); + "some21" expression => some("long string", test2); + "some22" expression => some("none", test2); vars: - "x" slist => { "a", "b" }; - "y" slist => { }; - - "test1" slist => { - 1,2,3, - "one", "two", "three", - "long string", - "four", "fix", "six", - "one", "two", "three", + "x" slist => { "a", "b" }; + "y" slist => {}; + + "test1" + slist => { + 1, + 2, + 3, + "one", + "two", + "three", + "long string", + "four", + "fix", + "six", + "one", + "two", + "three", }; - - "test2" data => parsejson('[1,2,3, + "test2" + data => parsejson( + '[1,2,3, "one", "two", "three", "long string", "four", "fix", "six", - "one", "two", "three",]'); + "one", "two", "three",]' + ); reports: empty_x:: "x has no elements"; + empty_y:: "y has no elements"; any:: "The test1 list is $(test1)"; + some11:: "some() test1 1 passed"; + !some11:: "some() test1 1 failed"; + some12:: "some() test1 2 failed"; + !some12:: "some() test1 2 passed"; - "The test2 list is $(test2)"; + some21:: "some() test2 1 passed"; + !some21:: "some() test2 1 failed"; + some22:: "some() test2 2 failed"; + !some22:: "some() test2 2 passed"; - } #+end_src ############################################################################### diff --git a/examples/sort.cf b/examples/sort.cf index 4ed79f00f9..66ab8e82a3 100644 --- a/examples/sort.cf +++ b/examples/sort.cf @@ -1,100 +1,119 @@ #+begin_src cfengine3 body common control { - bundlesequence => { test }; + bundlesequence => { test }; } bundle agent test { vars: - "a" slist => { "b", "c", "a" }; - "b" slist => { "100", "9", "10", "8.23" }; - "c" slist => { }; - "d" slist => { "", "a", "", "b" }; - "e" slist => { "a", "1", "b" }; + "a" slist => { "b", "c", "a" }; + "b" slist => { "100", "9", "10", "8.23" }; + "c" slist => {}; + "d" slist => { "", "a", "", "b" }; + "e" slist => { "a", "1", "b" }; - "ips" slist => { "100.200.100.0", "1.2.3.4", "9.7.5.1", "9", "9.7", "9.7.5", "", "-1", "where are the IP addresses?" }; - "ipv6" slist => { "FE80:0000:0000:0000:0202:B3FF:FE1E:8329", - "FE80::0202:B3FF:FE1E:8329", - "::1", - # the following should all be parsed as the same address and sorted together - "2001:db8:0:0:1:0:0:1", - "2001:0db8:0:0:1:0:0:1", - "2001:db8::1:0:0:1", - "2001:db8::0:1:0:0:1", - "2001:0db8::1:0:0:1", - "2001:db8:0:0:1::1", - "2001:db8:0000:0:1::1", - "2001:DB8:0:0:1::1", # note uppercase IPv6 addresses are invalid - # examples from https://www.ripe.net/lir-services/new-lir/ipv6_reference_card.pdf - "8000:63bf:3fff:fdd2", - "::ffff:192.0.2.47", - "fdf8:f53b:82e4::53", - "fe80::200:5aee:feaa:20a2", - "2001:0000:4136:e378:", - "8000:63bf:3fff:fdd2", - "2001:0002:6c::430", - "2001:10:240:ab::a", - "2002:cb0a:3cdd:1::1", - "2001:db8:8:4::2", - "ff01:0:0:0:0:0:0:2", - "-1", "where are the IP addresses?" }; + "ips" + slist => { + "100.200.100.0", + "1.2.3.4", + "9.7.5.1", + "9", + "9.7", + "9.7.5", + "", + "-1", + "where are the IP addresses?", + }; - "macs" slist => { "00:14:BF:F7:23:1D", "0:14:BF:F7:23:1D", ":14:BF:F7:23:1D", "00:014:BF:0F7:23:01D", - "00:14:BF:F7:23:1D", "0:14:BF:F7:23:1D", ":14:BF:F7:23:1D", "00:014:BF:0F7:23:01D", - "01:14:BF:F7:23:1D", "1:14:BF:F7:23:1D", - "01:14:BF:F7:23:2D", "1:14:BF:F7:23:2D", - "-1", "where are the MAC addresses?" }; + "ipv6" + slist => { + "FE80:0000:0000:0000:0202:B3FF:FE1E:8329", + "FE80::0202:B3FF:FE1E:8329", + "::1", + # the following should all be parsed as the same address and sorted together + "2001:db8:0:0:1:0:0:1", + "2001:0db8:0:0:1:0:0:1", + "2001:db8::1:0:0:1", + "2001:db8::0:1:0:0:1", + "2001:0db8::1:0:0:1", + "2001:db8:0:0:1::1", + "2001:db8:0000:0:1::1", + "2001:DB8:0:0:1::1", + # note uppercase IPv6 addresses are invalid + # examples from https://www.ripe.net/lir-services/new-lir/ipv6_reference_card.pdf + "8000:63bf:3fff:fdd2", + "::ffff:192.0.2.47", + "fdf8:f53b:82e4::53", + "fe80::200:5aee:feaa:20a2", + "2001:0000:4136:e378:", + "8000:63bf:3fff:fdd2", + "2001:0002:6c::430", + "2001:10:240:ab::a", + "2002:cb0a:3cdd:1::1", + "2001:db8:8:4::2", + "ff01:0:0:0:0:0:0:2", + "-1", + "where are the IP addresses?", + }; - "ja" string => join(",", "a"); - "jb" string => join(",", "b"); - "jc" string => join(",", "c"); - "jd" string => join(",", "d"); - "je" string => join(",", "e"); + "macs" + slist => { + "00:14:BF:F7:23:1D", + "0:14:BF:F7:23:1D", + ":14:BF:F7:23:1D", + "00:014:BF:0F7:23:01D", + "00:14:BF:F7:23:1D", + "0:14:BF:F7:23:1D", + ":14:BF:F7:23:1D", + "00:014:BF:0F7:23:01D", + "01:14:BF:F7:23:1D", + "1:14:BF:F7:23:1D", + "01:14:BF:F7:23:2D", + "1:14:BF:F7:23:2D", + "-1", + "where are the MAC addresses?", + }; - "jips" string => join(",", "ips"); - "jipv6" string => join(",", "ipv6"); - "jmacs" string => join(",", "macs"); - - "sa" slist => sort("a", "lex"); - "sb" slist => sort("b", "lex"); - "sc" slist => sort("c", "lex"); - "sd" slist => sort("d", "lex"); - "se" slist => sort("e", "lex"); - - "sb_int" slist => sort("b", "int"); - "sb_real" slist => sort("b", "real"); - - "sips" slist => sort("ips", "ip"); - "sipv6" slist => sort("ipv6", "ip"); - "smacs" slist => sort("macs", "mac"); - - - "jsa" string => join(",", "sa"); - "jsb" string => join(",", "sb"); - "jsc" string => join(",", "sc"); - "jsd" string => join(",", "sd"); - "jse" string => join(",", "se"); - - "jsb_int" string => join(",", "sb_int"); - "jsb_real" string => join(",", "sb_real"); - - "jsips" string => join(",", "sips"); - "jsipv6" string => join(",", "sipv6"); - "jsmacs" string => join(",", "smacs"); + "ja" string => join(",", "a"); + "jb" string => join(",", "b"); + "jc" string => join(",", "c"); + "jd" string => join(",", "d"); + "je" string => join(",", "e"); + "jips" string => join(",", "ips"); + "jipv6" string => join(",", "ipv6"); + "jmacs" string => join(",", "macs"); + "sa" slist => sort("a", "lex"); + "sb" slist => sort("b", "lex"); + "sc" slist => sort("c", "lex"); + "sd" slist => sort("d", "lex"); + "se" slist => sort("e", "lex"); + "sb_int" slist => sort("b", "int"); + "sb_real" slist => sort("b", "real"); + "sips" slist => sort("ips", "ip"); + "sipv6" slist => sort("ipv6", "ip"); + "smacs" slist => sort("macs", "mac"); + "jsa" string => join(",", "sa"); + "jsb" string => join(",", "sb"); + "jsc" string => join(",", "sc"); + "jsd" string => join(",", "sd"); + "jse" string => join(",", "se"); + "jsb_int" string => join(",", "sb_int"); + "jsb_real" string => join(",", "sb_real"); + "jsips" string => join(",", "sips"); + "jsipv6" string => join(",", "sipv6"); + "jsmacs" string => join(",", "smacs"); reports: - "sorted lexicographically '$(ja)' => '$(jsa)'"; - "sorted lexicographically '$(jb)' => '$(jsb)'"; - "sorted lexicographically '$(jc)' => '$(jsc)'"; - "sorted lexicographically '$(jd)' => '$(jsd)'"; - "sorted lexicographically '$(je)' => '$(jse)'"; - - "sorted integers '$(jb)' => '$(jsb_int)'"; - "sorted reals '$(jb)' => '$(jsb_real)'"; - - "sorted IPs '$(jips)' => '$(jsips)'"; - "sorted IPv6s '$(jipv6)' => '$(jsipv6)'"; - "sorted MACs '$(jmacs)' => '$(jsmacs)'"; + "sorted lexicographically '$(ja)' => '$(jsa)'"; + "sorted lexicographically '$(jb)' => '$(jsb)'"; + "sorted lexicographically '$(jc)' => '$(jsc)'"; + "sorted lexicographically '$(jd)' => '$(jsd)'"; + "sorted lexicographically '$(je)' => '$(jse)'"; + "sorted integers '$(jb)' => '$(jsb_int)'"; + "sorted reals '$(jb)' => '$(jsb_real)'"; + "sorted IPs '$(jips)' => '$(jsips)'"; + "sorted IPv6s '$(jipv6)' => '$(jsipv6)'"; + "sorted MACs '$(jmacs)' => '$(jsmacs)'"; } #+end_src diff --git a/examples/splitstring.cf b/examples/splitstring.cf index c32f4ea088..0af30dfd04 100644 --- a/examples/splitstring.cf +++ b/examples/splitstring.cf @@ -1,45 +1,44 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - #+begin_src cfengine3 body common control { - bundlesequence => { "test" }; + bundlesequence => { "test" }; } bundle agent test { vars: - - "split1" slist => splitstring("one:two:three",":","10"); - "split2" slist => splitstring("one:two:three",":","1"); - "split3" slist => splitstring("alpha:xyz:beta","xyz","10"); + "split1" slist => splitstring("one:two:three", ":", "10"); + "split2" slist => splitstring("one:two:three", ":", "1"); + "split3" slist => splitstring("alpha:xyz:beta", "xyz", "10"); reports: + "split1: $(split1)"; - "split1: $(split1)"; # will list "one", "two", and "three" - "split2: $(split2)"; # will list "one", "two:three" will be thrown away. - "split3: $(split3)"; # will list "alpha:" and ":beta" + # will list "one", "two", and "three" + "split2: $(split2)"; + # will list "one", "two:three" will be thrown away. + "split3: $(split3)"; + # will list "alpha:" and ":beta" } #+end_src ############################################################################### diff --git a/examples/sql_table_structure.cf b/examples/sql_table_structure.cf index d1c3816daf..287ec196ee 100644 --- a/examples/sql_table_structure.cf +++ b/examples/sql_table_structure.cf @@ -1,47 +1,35 @@ -# # Database promises are introduced in CFEngine Community edition 3.3.0 -# - body common control { - bundlesequence => { "databases" }; + bundlesequence => { "databases" }; } - bundle agent databases - { databases: - - "cfengine_db/users" - + "cfengine_db/users" database_operation => "create", database_type => "sql", - database_columns => { - "username,varchar,50", - "password,varchar,80", - "email,varchar,20", + database_columns => { + "username,varchar,50", "password,varchar,80", "email,varchar,20", }, database_server => local_mysql("root", ""); } - -body database_server local_mysql(username, password) +body database_server local_mysql(username, password) { - db_server_owner => "$(username)"; - db_server_password => "$(password)"; - db_server_host => "localhost"; - db_server_type => "mysql"; - db_server_connection_db => "mysql"; + db_server_owner => "$(username)"; + db_server_password => "$(password)"; + db_server_host => "localhost"; + db_server_type => "mysql"; + db_server_connection_db => "mysql"; } - body database_server local_postgresql(username, password) { - db_server_owner => "$(username)"; - db_server_password => "$(password)"; - db_server_host => "localhost"; - db_server_type => "postgres"; - db_server_connection_db => "postgres"; + db_server_owner => "$(username)"; + db_server_password => "$(password)"; + db_server_host => "localhost"; + db_server_type => "postgres"; + db_server_connection_db => "postgres"; } - diff --git a/examples/storage-cifs.cf b/examples/storage-cifs.cf index 3568f69c15..57013406a5 100644 --- a/examples/storage-cifs.cf +++ b/examples/storage-cifs.cf @@ -7,7 +7,7 @@ bundle agent main packages: redhat|centos:: - "cifs-utils" policy => "present"; + "cifs-utils" policy => "present"; "samba-client" policy => "present"; files: @@ -16,15 +16,14 @@ bundle agent main storage: redhat|centos:: - "/mnt/CIFS" - mount => cifs_guest( $(cifs[server]) , $(cifs[path]) ); + "/mnt/CIFS" mount => cifs_guest($(cifs[server]), $(cifs[path])); } -body mount cifs_guest(server,source) +body mount cifs_guest(server, source) { - mount_type => "cifs"; - mount_source => "$(source)"; - mount_server => "$(server)"; - mount_options => { "guest" }; - edit_fstab => "false"; + mount_type => "cifs"; + mount_source => "$(source)"; + mount_server => "$(server)"; + mount_options => { "guest" }; + edit_fstab => "false"; } diff --git a/examples/storage.cf b/examples/storage.cf index 7cecbe531d..ec1d69c863 100644 --- a/examples/storage.cf +++ b/examples/storage.cf @@ -1,57 +1,43 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - - # # cfengine 3 # # cf-agent -f ./cftest.cf -K -# - body common control - { - bundlesequence => { "storage" }; + bundlesequence => { "storage" }; } -# - bundle agent storage - { storage: - - "/usr" volume => mycheck("11G"); - "/" volume => mycheck("60%"); - + "/usr" volume => mycheck("11G"); + "/" volume => mycheck("60%"); } - ###################################################################### - -body volume mycheck(free) # reusable template - +body volume mycheck(free) +# reusable template { - check_foreign => "false"; - freespace => "$(free)"; - sensible_size => "10000"; - sensible_count => "2"; + check_foreign => "false"; + freespace => "$(free)"; + sensible_size => "10000"; + sensible_count => "2"; } diff --git a/examples/storejson.cf b/examples/storejson.cf index 851f47d6d0..88d49c81d9 100644 --- a/examples/storejson.cf +++ b/examples/storejson.cf @@ -2,46 +2,46 @@ bundle common globals { vars: - "example_data" data => '{ "msg": "Hello from $(this.bundle)" }'; + "example_data" data => '{ "msg": "Hello from $(this.bundle)" }'; } + bundle agent example_storejson # @brief Example showing storejson { vars: - "example_data" data => '{ "msg": "Hello from $(this.bundle)" }'; - - # Using storejson with data from remote bundle - - # "json_string_zero" -> { "CFEngine 3.16.0"} - # string => storejson( globals.example_data ) - # comment => "Unquoted with . (dot) present will cause the parser to error"; + "example_data" data => '{ "msg": "Hello from $(this.bundle)" }'; - "json_string_one" string => storejson( @(globals.example_data) ); - "json_string_two" string => storejson( "globals.example_data" ); + # Using storejson with data from remote bundle + # "json_string_zero" -> { "CFEngine 3.16.0"} + # string => storejson( globals.example_data ) + # comment => "Unquoted with . (dot) present will cause the parser to error"; + "json_string_one" string => storejson(@(globals.example_data)); + "json_string_two" string => storejson("globals.example_data"); - # Using storejson with data from this bundle - "json_string_three" string => storejson( @(example_storejson.example_data) ); - "json_string_four" string => storejson( "example_storejson.example_data"); - "json_string_five" string => storejson( example_data ); - "json_string_six" string => storejson( "$(this.bundle).example_data"); - "json_string_seven" string => storejson( @(example_data) ); + # Using storejson with data from this bundle + "json_string_three" string => storejson(@(example_storejson.example_data)); + "json_string_four" string => storejson("example_storejson.example_data"); + "json_string_five" string => storejson(example_data); + "json_string_six" string => storejson("$(this.bundle).example_data"); + "json_string_seven" string => storejson(@(example_data)); reports: - "json_string_one and json_string_two are identical:$(const.n)$(json_string_one)" - if => strcmp( $(json_string_one), $(json_string_two) ); + "json_string_one and json_string_two are identical:$(const.n)$(json_string_one)" + if => strcmp($(json_string_one), $(json_string_two)); - "json_string_{one,two,three,four,five,six,seven} are identical:$(const.n)$(json_string_three)" - if => and( - strcmp( $(json_string_three), $(json_string_four) ), - strcmp( $(json_string_four), $(json_string_five) ), - strcmp( $(json_string_five), $(json_string_six) ), - strcmp( $(json_string_six), $(json_string_seven) ) - ); + "json_string_{one,two,three,four,five,six,seven} are identical:$(const.n)$(json_string_three)" + if => and( + strcmp($(json_string_three), $(json_string_four)), + strcmp($(json_string_four), $(json_string_five)), + strcmp($(json_string_five), $(json_string_six)), + strcmp($(json_string_six), $(json_string_seven)) + ); } bundle agent __main__ { - methods: "example_storejson"; + methods: + "example_storejson"; } ############################################################################### #+end_src diff --git a/examples/strcmp.cf b/examples/strcmp.cf index 016dafed4c..9436921c47 100644 --- a/examples/strcmp.cf +++ b/examples/strcmp.cf @@ -1,45 +1,38 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - #+begin_src cfengine3 body common control { - bundlesequence => { "example" }; + bundlesequence => { "example" }; } bundle agent example { classes: - - "same" expression => strcmp("test","test"); + "same" expression => strcmp("test", "test"); reports: - same:: - "Strings are equal"; !same:: - "Strings are not equal"; } #+end_src diff --git a/examples/strftime.cf b/examples/strftime.cf index ead82f8d45..96d4828c3f 100644 --- a/examples/strftime.cf +++ b/examples/strftime.cf @@ -1,87 +1,162 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - #+begin_src cfengine3 #@ The templates used here are from the documentation of the standard strftime #@ implementation in the [glibc manual](http://www.gnu.org/software/libc/manual/html_node/Formatting-Calendar-Time.html#Formatting-Calendar-Time). body agent control { - environment => { "LC_ALL=en_US.UTF-8", "TZ=GMT" }; + environment => { "LC_ALL=en_US.UTF-8", "TZ=GMT" }; } + bundle agent main { vars: - "time" int => "1234567890"; - - "template[%a]" string => "The abbreviated weekday name according to the current locale."; - "template[%A]" string => "The full weekday name according to the current locale."; - "template[%b]" string => "The abbreviated month name according to the current locale."; - "template[%B]" string => "The full month name according to the current locale."; - "template[%c]" string => "The preferred calendar time representation for the current locale."; - "template[%C]" string => "The century of the year. This is equivalent to the greatest integer not greater than the year divided by 100."; - "template[%d]" string => "The day of the month as a decimal number (range 01 through 31)."; - "template[%D]" string => "The date using the format %m/$d/%y."; - "template[%e]" string => "The day of the month like with %d, but padded with blank (range 1 through 31)."; - "template[%F]" string => "The date using the format %Y-%m-%d. This is the form specified in the ISO 8601 standard and is the preferred form for all uses."; - "template[%g]" string => "The year corresponding to the ISO week number, but without the century (range 00 through 99). This has the same format and value as %y, except that if the ISO week number (see %V) belongs to the previous or next year, that year is used instead."; - "template[%G]" string => "The year corresponding to the ISO week number. This has the same format and value as %Y, except that if the ISO week number (see %V) belongs to the previous or next year, that year is used instead."; - "template[%h]" string => "The abbreviated month name according to the current locale. The action is the same as for %b."; - "template[%H]" string => "The hour as a decimal number, using a 24-hour clock (range 00 through 23)."; - "template[%I]" string => "The hour as a decimal number, using a 12-hour clock (range 01 through 12)."; - "template[%j]" string => "The day of the year as a decimal number (range 001 through 366)."; - "template[%k]" string => "The hour as a decimal number, using a 24-hour clock like %H, but padded with blank (range 0 through 23)."; - "template[%l]" string => "The hour as a decimal number, using a 12-hour clock like %I, but padded with blank (range 1 through 12)."; - "template[%m]" string => "The month as a decimal number (range 01 through 12)."; - "template[%M]" string => "The minute as a decimal number (range 00 through 59)."; - "template[%n]" string => "A single \n (newline) character."; - "template[%p]" string => "Either AM or PM, according to the given time value; or the corresponding strings for the current locale. Noon is treated as PM and midnight as AM. In most locales AM/PM format is not supported, in such cases %p yields an empty string."; - "template[%P]" string => "Either am or pm, according to the given time value; or the corresponding strings for the current locale, printed in lowercase characters. Noon is treated as pm and midnight as am. In most locales AM/PM format is not supported, in such cases %P yields an empty string."; - "template[%r]" string => "The complete calendar time using the AM/PM format of the current locale."; - "template[%R]" string => "The hour and minute in decimal numbers using the format %H:%M."; - "template[%S]" string => "The seconds as a decimal number (range 00 through 60)."; - "template[%t]" string => "A single \t (tabulator) character."; - "template[%T]" string => "The time of day using decimal numbers using the format %H:%M:%S."; - "template[%u]" string => "The day of the week as a decimal number (range 1 through 7), Monday being 1."; - "template[%U]" string => "The week number of the current year as a decimal number (range 00 through 53), starting with the first Sunday as the first day of the first week. Days preceding the first Sunday in the year are considered to be in week 00."; - "template[%V]" string => "The *ISO 8601:1988* week number as a decimal number (range 01 through 53). ISO weeks start with Monday and end with Sunday. Week 01 of a year is the first week which has the majority of its days in that year; this is equivalent to the week containing the year's first Thursday, and it is also equivalent to the week containing January 4. Week 01 of a year can contain days from the previous year. The week before week 01 of a year is the last week (52 or 53) of the previous year even if it contains days from the new year."; - "template[%w]" string => "The day of the week as a decimal number (range 0 through 6), Sunday being 0."; - "template[%w]" string => "The day of the week as a decimal number (range 0 through 6), Sunday being 0."; - "template[%x]" string => "The preferred date representation for the current locale."; - "template[%X]" string => "The preferred time of day representation for the current locale."; - "template[%y]" string => "The year without a century as a decimal number (range 00 through 99). This is equivalent to the year modulo 100."; - "template[%Y]" string => "The year as a decimal number, using the Gregorian calendar. Years before the year 1 are numbered 0, -1, and so on."; - "template[%z]" string => "*RFC 822*/*ISO 8601:1988* style numeric time zone (e.g., -0600 or +0100), or nothing if no time zone is determinable."; - "template[%Z]" string => "The time zone abbreviation (empty if the time zone can't be determined)."; - "template[%%]" string => "A literal % character."; - - # Since %s is ever changing resulting in unstable output, causing a test failure in CI - # it's not used unless show_seconds_since_epoch is defined - "template[%s]" string => "The number of seconds since the epoch, i.e., since 1970-01-01 00:00:00 UTC. Leap seconds are not counted unless leap second support is available.", if => "show_seconds_since_epoch"; - - "_i" slist => sort(getindices(template), lex); + "time" int => "1234567890"; + + "template[%a]" + string => "The abbreviated weekday name according to the current locale."; + + "template[%A]" + string => "The full weekday name according to the current locale."; + + "template[%b]" + string => "The abbreviated month name according to the current locale."; + + "template[%B]" + string => "The full month name according to the current locale."; + + "template[%c]" + string => "The preferred calendar time representation for the current locale."; + + "template[%C]" + string => "The century of the year. This is equivalent to the greatest integer not greater than the year divided by 100."; + + "template[%d]" + string => "The day of the month as a decimal number (range 01 through 31)."; + + "template[%D]" string => "The date using the format %m/$d/%y."; + + "template[%e]" + string => "The day of the month like with %d, but padded with blank (range 1 through 31)."; + + "template[%F]" + string => "The date using the format %Y-%m-%d. This is the form specified in the ISO 8601 standard and is the preferred form for all uses."; + + "template[%g]" + string => "The year corresponding to the ISO week number, but without the century (range 00 through 99). This has the same format and value as %y, except that if the ISO week number (see %V) belongs to the previous or next year, that year is used instead."; + + "template[%G]" + string => "The year corresponding to the ISO week number. This has the same format and value as %Y, except that if the ISO week number (see %V) belongs to the previous or next year, that year is used instead."; + + "template[%h]" + string => "The abbreviated month name according to the current locale. The action is the same as for %b."; + + "template[%H]" + string => "The hour as a decimal number, using a 24-hour clock (range 00 through 23)."; + + "template[%I]" + string => "The hour as a decimal number, using a 12-hour clock (range 01 through 12)."; + + "template[%j]" + string => "The day of the year as a decimal number (range 001 through 366)."; + + "template[%k]" + string => "The hour as a decimal number, using a 24-hour clock like %H, but padded with blank (range 0 through 23)."; + + "template[%l]" + string => "The hour as a decimal number, using a 12-hour clock like %I, but padded with blank (range 1 through 12)."; + + "template[%m]" + string => "The month as a decimal number (range 01 through 12)."; + + "template[%M]" + string => "The minute as a decimal number (range 00 through 59)."; + + "template[%n]" string => "A single \n (newline) character."; + + "template[%p]" + string => "Either AM or PM, according to the given time value; or the corresponding strings for the current locale. Noon is treated as PM and midnight as AM. In most locales AM/PM format is not supported, in such cases %p yields an empty string."; + + "template[%P]" + string => "Either am or pm, according to the given time value; or the corresponding strings for the current locale, printed in lowercase characters. Noon is treated as pm and midnight as am. In most locales AM/PM format is not supported, in such cases %P yields an empty string."; + + "template[%r]" + string => "The complete calendar time using the AM/PM format of the current locale."; + + "template[%R]" + string => "The hour and minute in decimal numbers using the format %H:%M."; + + "template[%S]" + string => "The seconds as a decimal number (range 00 through 60)."; + + "template[%t]" string => "A single \t (tabulator) character."; + + "template[%T]" + string => "The time of day using decimal numbers using the format %H:%M:%S."; + + "template[%u]" + string => "The day of the week as a decimal number (range 1 through 7), Monday being 1."; + + "template[%U]" + string => "The week number of the current year as a decimal number (range 00 through 53), starting with the first Sunday as the first day of the first week. Days preceding the first Sunday in the year are considered to be in week 00."; + + "template[%V]" + string => "The *ISO 8601:1988* week number as a decimal number (range 01 through 53). ISO weeks start with Monday and end with Sunday. Week 01 of a year is the first week which has the majority of its days in that year; this is equivalent to the week containing the year's first Thursday, and it is also equivalent to the week containing January 4. Week 01 of a year can contain days from the previous year. The week before week 01 of a year is the last week (52 or 53) of the previous year even if it contains days from the new year."; + + "template[%w]" + string => "The day of the week as a decimal number (range 0 through 6), Sunday being 0."; + + "template[%w]" + string => "The day of the week as a decimal number (range 0 through 6), Sunday being 0."; + + "template[%x]" + string => "The preferred date representation for the current locale."; + + "template[%X]" + string => "The preferred time of day representation for the current locale."; + + "template[%y]" + string => "The year without a century as a decimal number (range 00 through 99). This is equivalent to the year modulo 100."; + + "template[%Y]" + string => "The year as a decimal number, using the Gregorian calendar. Years before the year 1 are numbered 0, -1, and so on."; + + "template[%z]" + string => "*RFC 822*/*ISO 8601:1988* style numeric time zone (e.g., -0600 or +0100), or nothing if no time zone is determinable."; + + "template[%Z]" + string => "The time zone abbreviation (empty if the time zone can't be determined)."; + + "template[%%]" string => "A literal % character."; + + # Since %s is ever changing resulting in unstable output, causing a test failure in CI + # it's not used unless show_seconds_since_epoch is defined + "template[%s]" + string => "The number of seconds since the epoch, i.e., since 1970-01-01 00:00:00 UTC. Leap seconds are not counted unless leap second support is available.", + if => "show_seconds_since_epoch"; + + "_i" slist => sort(getindices(template), lex); reports: - "$(_i) :: $(template[$(_i)])$(const.n)$(const.t)For example: '$(with)'" - with => strftime(gmtime, $(_i), $(time)); + "$(_i) :: $(template[$(_i)])$(const.n)$(const.t)For example: '$(with)'" + with => strftime(gmtime, $(_i), $(time)); } #+end_src ############################################################################### diff --git a/examples/string.cf b/examples/string.cf index 9953b0d2f9..72d0ba9b70 100644 --- a/examples/string.cf +++ b/examples/string.cf @@ -2,20 +2,22 @@ bundle agent main { classes: - "classA"; - "classB"; + "classA"; + "classB"; vars: - "some_string" string => "cba"; - "class_expressions" slist => {"classA.classB", - string(and("classA", strcmp("$(some_string)", "abc"))) + "some_string" string => "cba"; + + "class_expressions" + slist => { + "classA.classB", + string(and("classA", strcmp("$(some_string)", "abc"))), }; reports: - "$(class_expressions)"; + "$(class_expressions)"; } #+end_src - #+begin_src example_output #@ ``` #@ R: classA.classB diff --git a/examples/string_downcase.cf b/examples/string_downcase.cf index d9d0eb2a7d..ab59b14759 100644 --- a/examples/string_downcase.cf +++ b/examples/string_downcase.cf @@ -1,37 +1,35 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - #+begin_src cfengine3 body common control { - bundlesequence => { "example" }; + bundlesequence => { "example" }; } bundle agent example { vars: - "downcase" string => string_downcase("ABC"); # will contain "abc" + "downcase" string => string_downcase("ABC"); + # will contain "abc" reports: - "downcased ABC = $(downcase)"; + "downcased ABC = $(downcase)"; } #+end_src ############################################################################### diff --git a/examples/string_head.cf b/examples/string_head.cf index da7d51febe..67b126067e 100644 --- a/examples/string_head.cf +++ b/examples/string_head.cf @@ -1,38 +1,35 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - #+begin_src cfengine3 body common control { - bundlesequence => { "example" }; + bundlesequence => { "example" }; } bundle agent example { vars: - "start" string => string_head("abc", "1"); # will contain "a" + "start" string => string_head("abc", "1"); + # will contain "a" reports: - "start of abc = $(start)"; - + "start of abc = $(start)"; } #+end_src ############################################################################### diff --git a/examples/string_length.cf b/examples/string_length.cf index daebc9bc8a..5cf217f364 100644 --- a/examples/string_length.cf +++ b/examples/string_length.cf @@ -1,37 +1,35 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - #+begin_src cfengine3 body common control { - bundlesequence => { "example" }; + bundlesequence => { "example" }; } bundle agent example { vars: - "length" int => string_length("abc"); # will contain "3" + "length" int => string_length("abc"); + # will contain "3" reports: - "length of string abc = $(length)"; + "length of string abc = $(length)"; } #+end_src ############################################################################### diff --git a/examples/string_mustache.cf b/examples/string_mustache.cf index 4e646df464..7b998d2178 100644 --- a/examples/string_mustache.cf +++ b/examples/string_mustache.cf @@ -1,56 +1,61 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - #+begin_src cfengine3 body common control { - bundlesequence => { "config", "example" }; + bundlesequence => { "config", "example" }; } bundle agent config { vars: - "deserts" data => parsejson('{ "deserts": { + "deserts" + data => parsejson( + '{ "deserts": { "Africa": "Sahara", "Asia": "Gobi" -} }'); +} }' + ); } - bundle agent example { vars: - # {{@}} is the current key during an iteration in 3.7 with Mustache - "with_data_container" string => string_mustache("from container: deserts = {{%deserts}} -from container: {{#deserts}}The desert {{.}} is in {{@}}. {{/deserts}}", "config.deserts"); - - # you can dump an entire data structure with {{%myvar}} in 3.7 with Mustache - "with_system_state" string => string_mustache("from datastate(): deserts = {{%vars.config.deserts.deserts}} -from datastate(): {{#vars.config.deserts.deserts}}The desert {{.}} is in {{@}}. {{/vars.config.deserts.deserts}}"); # will use datastate() + # {{@}} is the current key during an iteration in 3.7 with Mustache + "with_data_container" + string => string_mustache( + "from container: deserts = {{%deserts}} +from container: {{#deserts}}The desert {{.}} is in {{@}}. {{/deserts}}", + "config.deserts" + ); + # you can dump an entire data structure with {{%myvar}} in 3.7 with Mustache + "with_system_state" + string => string_mustache( + "from datastate(): deserts = {{%vars.config.deserts.deserts}} +from datastate(): {{#vars.config.deserts.deserts}}The desert {{.}} is in {{@}}. {{/vars.config.deserts.deserts}}" + ); + # will use datastate() reports: - "With an explicit data container: $(with_data_container)"; - - "With the system datastate(): $(with_system_state)"; + "With an explicit data container: $(with_data_container)"; + "With the system datastate(): $(with_system_state)"; } #+end_src ############################################################################### diff --git a/examples/string_replace.cf b/examples/string_replace.cf index 1e4e84940b..69db6b46e2 100644 --- a/examples/string_replace.cf +++ b/examples/string_replace.cf @@ -1,44 +1,45 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - #+begin_src cfengine3 bundle agent main { vars: - # replace one occurence - "replace_once" string => string_replace("This is a string", "string", "thing"); - # replace several occurences - "replace_several" string => string_replace("This is a string", "i", "o"); - # replace nothing - "replace_none" string => string_replace("This is a string", "boat", "no"); - # replace ambiguous order - "replace_ambiguous" string => string_replace("aaaaa", "aaa", "b"); + # replace one occurence + "replace_once" + string => string_replace("This is a string", "string", "thing"); + + # replace several occurences + "replace_several" string => string_replace("This is a string", "i", "o"); + + # replace nothing + "replace_none" string => string_replace("This is a string", "boat", "no"); + + # replace ambiguous order + "replace_ambiguous" string => string_replace("aaaaa", "aaa", "b"); reports: - # in order, the above... - "replace_once = '$(replace_once)'"; - "replace_several = '$(replace_several)'"; - "replace_none = '$(replace_none)'"; - "replace_ambiguous = '$(replace_ambiguous)'"; + # in order, the above... + "replace_once = '$(replace_once)'"; + "replace_several = '$(replace_several)'"; + "replace_none = '$(replace_none)'"; + "replace_ambiguous = '$(replace_ambiguous)'"; } #+end_src ############################################################################### diff --git a/examples/string_reverse.cf b/examples/string_reverse.cf index 402030d2ca..1a084b4a2e 100644 --- a/examples/string_reverse.cf +++ b/examples/string_reverse.cf @@ -1,38 +1,35 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - #+begin_src cfengine3 body common control { - bundlesequence => { "example" }; + bundlesequence => { "example" }; } bundle agent example { vars: - "reversed" - string => string_reverse("abc"); # will contain "cba" + "reversed" string => string_reverse("abc"); + # will contain "cba" reports: - "reversed abs = $(reversed)"; + "reversed abs = $(reversed)"; } #+end_src ############################################################################### diff --git a/examples/string_split.cf b/examples/string_split.cf index 7e1cf4a4bc..b9e5201bc2 100644 --- a/examples/string_split.cf +++ b/examples/string_split.cf @@ -1,45 +1,44 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - #+begin_src cfengine3 body common control { - bundlesequence => { "test" }; + bundlesequence => { "test" }; } bundle agent test { vars: - - "split1" slist => string_split("one:two:three", ":", "10"); - "split2" slist => string_split("one:two:three", ":", "1"); - "split3" slist => string_split("alpha:xyz:beta", "xyz", "10"); + "split1" slist => string_split("one:two:three", ":", "10"); + "split2" slist => string_split("one:two:three", ":", "1"); + "split3" slist => string_split("alpha:xyz:beta", "xyz", "10"); reports: + "split1: $(split1)"; - "split1: $(split1)"; # will list "one", "two", and "three" - "split2: $(split2)"; # will list "one:two:three" - "split3: $(split3)"; # will list "alpha:" and ":beta" + # will list "one", "two", and "three" + "split2: $(split2)"; + # will list "one:two:three" + "split3: $(split3)"; + # will list "alpha:" and ":beta" } #+end_src ############################################################################### diff --git a/examples/string_tail.cf b/examples/string_tail.cf index 441af12280..ddef3f3776 100644 --- a/examples/string_tail.cf +++ b/examples/string_tail.cf @@ -1,38 +1,35 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - #+begin_src cfengine3 body common control { - bundlesequence => { "example" }; + bundlesequence => { "example" }; } bundle agent example { vars: - "end" string => string_tail("abc", "1"); # will contain "c" + "end" string => string_tail("abc", "1"); + # will contain "c" reports: - "end of abc = $(end)"; - + "end of abc = $(end)"; } #+end_src ############################################################################### diff --git a/examples/string_trim.cf b/examples/string_trim.cf index 466c3a0125..00be6f30a3 100644 --- a/examples/string_trim.cf +++ b/examples/string_trim.cf @@ -3,20 +3,23 @@ bundle agent example_trim # @brief Example showing string_trim { vars: - "my_string_one" string => string_trim( " Trim spaces please "); - "my_string_two" string => string_trim( " + "my_string_one" string => string_trim(" Trim spaces please "); + + "my_string_two" + string => string_trim(" Trim newlines also please "); reports: - "my_string_one: '$(my_string_one)'"; - "my_string_two: '$(my_string_two)'"; + "my_string_one: '$(my_string_one)'"; + "my_string_two: '$(my_string_two)'"; } bundle agent __main__ { - methods: "example_trim"; + methods: + "example_trim"; } ############################################################################### #+end_src diff --git a/examples/string_upcase.cf b/examples/string_upcase.cf index 85edc87a88..781bbab6bc 100644 --- a/examples/string_upcase.cf +++ b/examples/string_upcase.cf @@ -1,37 +1,35 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - #+begin_src cfengine3 body common control { - bundlesequence => { "example" }; + bundlesequence => { "example" }; } bundle agent example { vars: - "upcase" string => string_upcase("abc"); # will contain "ABC" + "upcase" string => string_upcase("abc"); + # will contain "ABC" reports: - "upcased abc: $(upcase)"; + "upcased abc: $(upcase)"; } #+end_src ############################################################################### diff --git a/examples/stringarray.cf b/examples/stringarray.cf index 147d9b22be..c93ba87733 100644 --- a/examples/stringarray.cf +++ b/examples/stringarray.cf @@ -1,47 +1,37 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - - body common control - { - bundlesequence => { "example" }; + bundlesequence => { "example" }; } - ########################################################### - bundle agent example - -{ +{ vars: + "dim_array" + int => readstringarray( + "array_name", "/etc/passwd", "#[^\n]*", ":", 10, 4000 + ); - "dim_array" - - int => readstringarray("array_name","/etc/passwd","#[^\n]*",":",10,4000); - - "idx" slist => getindices("array_name"); + "idx" slist => getindices("array_name"); reports: - - "Index $(idx): [1]=$(array_name[$(idx)][1]),[2]=$(array_name[$(idx)][2])...[7]=$(array_name[$(idx)][6])"; + "Index $(idx): [1]=$(array_name[$(idx)][1]),[2]=$(array_name[$(idx)][2])...[7]=$(array_name[$(idx)][6])"; } - diff --git a/examples/style_PascaleCase.cf b/examples/style_PascaleCase.cf index 739bc5ca1f..a04c2a785f 100644 --- a/examples/style_PascaleCase.cf +++ b/examples/style_PascaleCase.cf @@ -1,29 +1,28 @@ bundle agent __main__ { methods: - "Ssh"; + "Ssh"; } + bundle agent Ssh { vars: - "ServiceName" string => "ssh"; - "ConfigFile" string => "/etc/ssh/sshd_config"; - "Conf[Port]" string => "22"; + "ServiceName" string => "ssh"; + "ConfigFile" string => "/etc/ssh/sshd_config"; + "Conf[Port]" string => "22"; files: - "$(ConfigFile)" - edit_line => default:set_line_based("$(this.bundle).Conf", - " ", - "\s+", - ".*", - "\s*#\s*"), - classes => default:results( "bundle", "$(ConfigFile)"); + "$(ConfigFile)" + edit_line => default:set_line_based( + "$(this.bundle).Conf", " ", "\s+", ".*", "\s*#\s*" + ), + classes => default:results("bundle", "$(ConfigFile)"); services: _etc_ssh_sshd_config_repaired:: "$(ServiceName)" service_policy => "restart", - classes => default:results( "bundle", "$(ServiceName)_restart"); + classes => default:results("bundle", "$(ServiceName)_restart"); reports: ssh_restart_repaired._etc_ssh_sshd_config_repaired:: diff --git a/examples/style_camelCase.cf b/examples/style_camelCase.cf index 87fb29d4d7..221ec571c0 100644 --- a/examples/style_camelCase.cf +++ b/examples/style_camelCase.cf @@ -1,29 +1,28 @@ bundle agent __main__ { methods: - "Ssh"; + "Ssh"; } + bundle agent ssh { vars: - "serviceName" string => "ssh"; - "configFile" string => "/etc/ssh/sshd_config"; - "conf[Port]" string => "22"; + "serviceName" string => "ssh"; + "configFile" string => "/etc/ssh/sshd_config"; + "conf[Port]" string => "22"; files: - "$(configFile)" - edit_line => default:set_line_based("$(this.bundle).conf", - " ", - "\s+", - ".*", - "\s*#\s*"), - classes => default:results( "bundle", "$(configFile)"); + "$(configFile)" + edit_line => default:set_line_based( + "$(this.bundle).conf", " ", "\s+", ".*", "\s*#\s*" + ), + classes => default:results("bundle", "$(configFile)"); services: _etc_ssh_sshd_config_repaired:: "$(serviceName)" service_policy => "restart", - classes => default:results( "bundle", "$(serviceName)_restart"); + classes => default:results("bundle", "$(serviceName)_restart"); reports: ssh_restart_repaired._etc_ssh_sshd_config_repaired:: diff --git a/examples/style_hungarian.cf b/examples/style_hungarian.cf index 49d1ddf76d..f6382723e3 100644 --- a/examples/style_hungarian.cf +++ b/examples/style_hungarian.cf @@ -2,43 +2,40 @@ bundle agent __main__ { vars: - "s_one" string => "one"; - "ITwo" int => "2"; - "rThree" real => "3.0"; - - "lMyList" slist => { "$(s_one)", "$(ITwo)", "$(rThree)" }; + "s_one" string => "one"; + "ITwo" int => "2"; + "rThree" real => "3.0"; + "lMyList" slist => { "$(s_one)", "$(ITwo)", "$(rThree)" }; methods: - "Iteration inside (bundle called once)" - usebundle => dollar_vs_at( @(lMyList) ); + "Iteration inside (bundle called once)" + usebundle => dollar_vs_at(@(lMyList)); - "Iteration outside (bundle called length(lMyList) times)" - usebundle => dollar_vs_at( $(lMyList) ); + "Iteration outside (bundle called length(lMyList) times)" + usebundle => dollar_vs_at($(lMyList)); } -bundle agent dollar_vs_at( myParam ) +bundle agent dollar_vs_at(myParam) { vars: - "myParamType" string => type( myParam ); + "myParamType" string => type(myParam); - classes: - "myParamType_slist" expression => strcmp( $(myParamType), "slist" ); - "myParamType_string" expression => strcmp( $(myParamType), "string" ); + classes: + "myParamType_slist" expression => strcmp($(myParamType), "slist"); + "myParamType_string" expression => strcmp($(myParamType), "string"); reports: - "Bundle promised by '$(with)'" - with => nth( reverse( callstack_promisers() ), 0 ); + "Bundle promised by '$(with)'" + with => nth(reverse(callstack_promisers()), 0); myParamType_slist:: "myParam is of type '$(myParamType)' with value $(with)" - with => join( ", ", @(myParam) ); + with => join(", ", @(myParam)); myParamType_string:: "myParam is of type '$(myParamType)' with value $(myParam)"; - } #+end_src cfengine3 - #+begin_src example_output #@ ``` #@ R: Bundle promised by 'Iteration inside (bundle called once)' @@ -49,4 +46,3 @@ bundle agent dollar_vs_at( myParam ) #@ R: myParam is of type 'string' with value 3.000000 #@ ``` #+end_src - diff --git a/examples/style_snake_case.cf b/examples/style_snake_case.cf index 3d83833bdd..05efc120ed 100644 --- a/examples/style_snake_case.cf +++ b/examples/style_snake_case.cf @@ -1,29 +1,28 @@ bundle agent __main__ { methods: - "ssh"; + "ssh"; } + bundle agent ssh { vars: - "service_name" string => "ssh"; - "config_file" string => "/etc/ssh/sshd_config"; - "conf[Port]" string => "22"; + "service_name" string => "ssh"; + "config_file" string => "/etc/ssh/sshd_config"; + "conf[Port]" string => "22"; files: - "$(config_file)" - edit_line => default:set_line_based("$(this.bundle).conf", - " ", - "\s+", - ".*", - "\s*#\s*"), - classes => default:results( "bundle", "$(config_file)"); + "$(config_file)" + edit_line => default:set_line_based( + "$(this.bundle).conf", " ", "\s+", ".*", "\s*#\s*" + ), + classes => default:results("bundle", "$(config_file)"); services: _etc_ssh_sshd_config_repaired:: "$(service_name)" service_policy => "restart", - classes => default:results( "bundle", "$(service_name)_restart"); + classes => default:results("bundle", "$(service_name)_restart"); reports: ssh_restart_repaired._etc_ssh_sshd_config_repaired:: diff --git a/examples/sublist.cf b/examples/sublist.cf index d2104f8309..45ee4403b9 100644 --- a/examples/sublist.cf +++ b/examples/sublist.cf @@ -1,61 +1,55 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - #+begin_src cfengine3 body common control { - bundlesequence => { "test" }; + bundlesequence => { "test" }; } bundle agent test { vars: - "test" slist => { - 1,2,3, - "one", "two", "three", - "long string", - "four", "fix", "six", + "test" + slist => { + 1, 2, 3, "one", "two", "three", "long string", "four", "fix", "six", }; - "test_head9999" slist => sublist("test", "head", 9999); - "test_head1" slist => sublist("test", "head", 1); - "test_head0" slist => sublist("test", "head", 0); - - "test_tail9999" slist => sublist("test", "tail", 9999); - "test_tail10" slist => sublist("test", "tail", 10); - "test_tail2" slist => sublist("test", "tail", 2); - "test_tail1" slist => sublist("test", "tail", 1); - "test_tail0" slist => sublist("test", "tail", 0); + "test_head9999" slist => sublist("test", "head", 9999); + "test_head1" slist => sublist("test", "head", 1); + "test_head0" slist => sublist("test", "head", 0); + "test_tail9999" slist => sublist("test", "tail", 9999); + "test_tail10" slist => sublist("test", "tail", 10); + "test_tail2" slist => sublist("test", "tail", 2); + "test_tail1" slist => sublist("test", "tail", 1); + "test_tail0" slist => sublist("test", "tail", 0); reports: - "The test list is $(test)"; - "This line should not appear: $(test_head0)"; - "The head(1) of the test list is $(test_head1)"; - "The head(9999) of the test list is $(test_head9999)"; - "This line should not appear: $(test_tail0)"; - "The tail(1) of the test list is $(test_tail1)"; - "The tail(10) of the test list is $(test_tail10)"; - "The tail(2) of the test list is $(test_tail2)"; - "The tail(9999) of the test list is $(test_tail9999)"; + "The test list is $(test)"; + "This line should not appear: $(test_head0)"; + "The head(1) of the test list is $(test_head1)"; + "The head(9999) of the test list is $(test_head9999)"; + "This line should not appear: $(test_tail0)"; + "The tail(1) of the test list is $(test_tail1)"; + "The tail(10) of the test list is $(test_tail10)"; + "The tail(2) of the test list is $(test_tail2)"; + "The tail(9999) of the test list is $(test_tail9999)"; } #+end_src ############################################################################### diff --git a/examples/sum.cf b/examples/sum.cf index 5aa0fe157a..19b1209876 100644 --- a/examples/sum.cf +++ b/examples/sum.cf @@ -1,41 +1,38 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - #+begin_src cfengine3 body common control { - bundlesequence => { "test" }; + bundlesequence => { "test" }; } bundle agent test { vars: - "adds_to_six" ilist => { "1", "2", "3" }; - "six" real => sum("adds_to_six"); - "adds_to_zero" rlist => { "1.0", "2", "-3e0" }; - "zero" real => sum("adds_to_zero"); + "adds_to_six" ilist => { "1", "2", "3" }; + "six" real => sum("adds_to_six"); + "adds_to_zero" rlist => { "1.0", "2", "-3e0" }; + "zero" real => sum("adds_to_zero"); reports: - "six is $(six), zero is $(zero)"; + "six is $(six), zero is $(zero)"; } #+end_src ############################################################################### diff --git a/examples/switchcase.cf b/examples/switchcase.cf index 7865a8448c..301d2d1c1d 100644 --- a/examples/switchcase.cf +++ b/examples/switchcase.cf @@ -1,73 +1,50 @@ - body common control { - bundlesequence => { "test1", "test2" }; + bundlesequence => { "test1", "test2" }; } - ################################################## - bundle agent test1 { classes: - - "default" expression => "any"; + "default" expression => "any"; reports: - linux:: - - "This is a linux box" - classes => exclusive; + "This is a linux box" classes => exclusive; solaris:: - - - "This is a solaris box" - classes => exclusive; + "This is a solaris box" classes => exclusive; default:: - "This is something not worth mentioning specifically" - classes => reset_default; + classes => reset_default; } - ################################################## - bundle agent test2 { classes: - - "default" expression => "any"; + "default" expression => "any"; reports: - linux:: - - "This is another linux box" - classes => exclusive; + "This is another linux box" classes => exclusive; solaris:: - - "This is another solaris box" - classes => exclusive; + "This is another solaris box" classes => exclusive; default:: - "This is something else not worth mentioning specifically" - classes => reset_default; - + classes => reset_default; } - ########################################################## - body classes exclusive { - cancel_kept => { "default" }; - cancel_notkept => { "default" }; - cancel_repaired => { "default" }; + cancel_kept => { "default" }; + cancel_notkept => { "default" }; + cancel_repaired => { "default" }; } body classes reset_default { - promise_kept => { "default" }; + promise_kept => { "default" }; } diff --git a/examples/symlink.cf b/examples/symlink.cf index f89e51f1ca..6cf1399031 100644 --- a/examples/symlink.cf +++ b/examples/symlink.cf @@ -1,41 +1,38 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. ######################################################## - body file control { - inputs => { "$(sys.libdir)/stdlib.cf" }; + inputs => { "$(sys.libdir)/stdlib.cf" }; } bundle agent main { files: - - # We use move_obstructions because we want the symlink to replace a - # regular file if necessary. - "/etc/apache2/sites-enabled/www.cfengine.com" -> { "webmaster@cfengine.com" } - link_from => ln_s( "/etc/apache2/sites-available/www.cfengine.com" ), - move_obstructions => "true", - comment => "We always want our website to be enabled."; + # We use move_obstructions because we want the symlink to replace a + # regular file if necessary. + "/etc/apache2/sites-enabled/www.cfengine.com" -> { + "webmaster@cfengine.com" + } + link_from => ln_s("/etc/apache2/sites-available/www.cfengine.com"), + move_obstructions => "true", + comment => "We always want our website to be enabled."; } - ######################################################### diff --git a/examples/symlink_children.cf b/examples/symlink_children.cf index 338fa1e4fd..3314c76368 100644 --- a/examples/symlink_children.cf +++ b/examples/symlink_children.cf @@ -1,26 +1,23 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. ######################################################## - #+begin_src cfengine3 body file control { @@ -30,14 +27,13 @@ body file control bundle agent main { files: - - # This will make symlinks to each file in /var/cfengine/bin - # for example: - # '/usr/local/bin/cf-agent' -> '/var/cfengine/bin/cf-agent' - # '/usr/local/bin/cf-serverd' -> '/var/cfengine/bin/cf-serverd' - "/usr/local/bin" - link_from => linkchildren("/var/cfengine/bin"), - comment => "We like for cfengine binaries to be available inside of the + # This will make symlinks to each file in /var/cfengine/bin + # for example: + # '/usr/local/bin/cf-agent' -> '/var/cfengine/bin/cf-agent' + # '/usr/local/bin/cf-serverd' -> '/var/cfengine/bin/cf-serverd' + "/usr/local/bin" + link_from => linkchildren("/var/cfengine/bin"), + comment => "We like for cfengine binaries to be available inside of the common $PATH"; } #+end_src diff --git a/examples/sys_interfaces_ip_addresses_ipv4.cf b/examples/sys_interfaces_ip_addresses_ipv4.cf index 39c93e1c91..40bf8a74b3 100644 --- a/examples/sys_interfaces_ip_addresses_ipv4.cf +++ b/examples/sys_interfaces_ip_addresses_ipv4.cf @@ -1,38 +1,36 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - #+begin_src cfengine3 bundle agent example_sys_interfaces # @brief Illustrate iterating over interfaces and addresses { reports: - "Address: $(sys.ip_addresses)"; - "Interface: $(sys.interfaces)"; - "Address of '$(sys.interfaces)' is '$(sys.ipv4[$(sys.interfaces)])'"; + "Address: $(sys.ip_addresses)"; + "Interface: $(sys.interfaces)"; + "Address of '$(sys.interfaces)' is '$(sys.ipv4[$(sys.interfaces)])'"; } + bundle agent __main__ { methods: - "example_sys_interfaces"; + "example_sys_interfaces"; } #+end_src ############################################################################### @@ -59,4 +57,3 @@ bundle agent __main__ #@ R: Address of 'vboxnet13' is '192.168.69.1' #@ ``` #+end_src - diff --git a/examples/syslog.cf b/examples/syslog.cf index 574cf6c91f..4f56c18ebc 100644 --- a/examples/syslog.cf +++ b/examples/syslog.cf @@ -1,47 +1,36 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - - body common control { - bundlesequence => { "one" }; + bundlesequence => { "one" }; } - - bundle agent one { files: - - "/tmp/xyz" - + "/tmp/xyz" create => "true", action => log; - } body action log { - log_level => "inform"; + log_level => "inform"; } - - diff --git a/examples/syslog2.cf b/examples/syslog2.cf index 0cf62746fd..837a44d8e4 100644 --- a/examples/syslog2.cf +++ b/examples/syslog2.cf @@ -1,34 +1,23 @@ -# # With Nova, log directly to a central server -- careful of scalability (UDP) -# - body common control { - bundlesequence => { "example" }; - syslog_host => "loghost.example.org"; + bundlesequence => { "example" }; + syslog_host => "loghost.example.org"; } -# - bundle agent example { vars: - - "software" slist => { "/root/xyz", "/tmp/xyz" }; + "software" slist => { "/root/xyz", "/tmp/xyz" }; files: - - "$(software)" - + "$(software)" create => "true", action => logme("$(software)"); - } -# - body action logme(x) { - log_repaired => "udp_syslog"; - log_string => "cfengine repaired promise $(this.handle) - $(x)"; + log_repaired => "udp_syslog"; + log_string => "cfengine repaired promise $(this.handle) - $(x)"; } diff --git a/examples/template.cf b/examples/template.cf index bf7b45e775..f4fe454ed3 100644 --- a/examples/template.cf +++ b/examples/template.cf @@ -1,65 +1,47 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - ######################################################## # # Simple test editfile - template expansion # ######################################################## - body common control - { - bundlesequence => { "example" }; + bundlesequence => { "example" }; } - ######################################################## - bundle agent example - { files: - - "/home/mark/tmp/file_based_on_template" - - create => "true", + "/home/mark/tmp/file_based_on_template" + create => "true", edit_line => ExpandMeFrom("/tmp/source_template"); - - } - ######################################################## - bundle edit_line ExpandMeFrom(template) { vars: - - "myvar" string => "[sub string]"; + "myvar" string => "[sub string]"; insert_lines: - - "$(template)" - + "$(template)" insert_type => "file", expand_scalars => "true"; } - diff --git a/examples/template2.cf b/examples/template2.cf index 8e506caeb3..6f5db5bc48 100644 --- a/examples/template2.cf +++ b/examples/template2.cf @@ -1,47 +1,37 @@ - body common control { - bundlesequence => { "example" }; - - inputs => { "$(sys.libdir)/stdlib.cf" }; + bundlesequence => { "example" }; + inputs => { "$(sys.libdir)/stdlib.cf" }; } bundle agent example { methods: - - "any" usebundle => get_template("/tmp/sudoers","400"); - "any" usebundle => get_template("/tmp/hosts","644"); - + "any" usebundle => get_template("/tmp/sudoers", "400"); + "any" usebundle => get_template("/tmp/hosts", "644"); } - ############################################################# - -bundle agent get_template(final_destination,mode) +bundle agent get_template(final_destination, mode) { vars: - - # This needs to ne preconfigured to your site - - "masterfiles" string => "/home/mark/tmp"; - "this_template" string => lastnode("$(final_destination)","/"); + # This needs to ne preconfigured to your site + "masterfiles" string => "/home/mark/tmp"; + "this_template" string => lastnode("$(final_destination)", "/"); files: - - "$(final_destination).staging" - + "$(final_destination).staging" comment => "Get template and expand variables for this host", - perms => mo("400","root"), - copy_from => remote_cp("$(masterfiles)/templates/$(this_template)","$(policy_server)"), + perms => mo("400", "root"), + copy_from => remote_cp( + "$(masterfiles)/templates/$(this_template)", "$(policy_server)" + ), action => if_elapsed("60"); - "$(final_destination)" - + "$(final_destination)" comment => "Expand the template", create => "true", edit_line => expand_template("$(final_destination).staging"), edit_defaults => empty, - perms => mo("$(mode)","root"), + perms => mo("$(mode)", "root"), action => if_elapsed("60"); - } diff --git a/examples/template_method-inline_mustache.cf b/examples/template_method-inline_mustache.cf index b78550f6c1..906e46ad67 100644 --- a/examples/template_method-inline_mustache.cf +++ b/examples/template_method-inline_mustache.cf @@ -1,66 +1,58 @@ # Copyright 2021 Northern.tech AS - -# This file is part of Cfengine 3 - written and maintained by Northern.tech AS. - +# +# This file is part of CFEngine 3 - written and maintained by Northern.tech AS. # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - ############################################################################### #+begin_src cfengine3 bundle agent example_using_template_method_inline_mustache { vars: + # Here we construct a data container that will be passed to the mustache + # templating engine + "d" data => '{ "host": "docs.cfengine.com" }'; - # Here we construct a data container that will be passed to the mustache - # templating engine - - "d" - data => '{ "host": "docs.cfengine.com" }'; - - # Here we specify a string that will be used as an inline mustache template - "mustache_template_string" - string => "Welcome to host '{{{host}}}'"; + # Here we specify a string that will be used as an inline mustache template + "mustache_template_string" string => "Welcome to host '{{{host}}}'"; files: - # Here we render the file using the data container and inline template specification - - "/tmp/example.txt" - create => "true", - template_method => "inline_mustache", - edit_template_string => "$(mustache_template_string)", - template_data => @(d); + # Here we render the file using the data container and inline template specification + "/tmp/example.txt" + create => "true", + template_method => "inline_mustache", + edit_template_string => "$(mustache_template_string)", + template_data => @(d); reports: - "/tmp/example.txt" - printfile => cat( $(this.promiser) ); + "/tmp/example.txt" printfile => cat($(this.promiser)); } - # Copied from stdlib, lib/reports.cf body printfile cat(file) # @brief Report the contents of a file # @param file The full path of the file to report { - file_to_print => "$(file)"; - number_of_lines => "inf"; + file_to_print => "$(file)"; + number_of_lines => "inf"; } + bundle agent __main__ { - methods: "example_using_template_method_inline_mustache"; + methods: + "example_using_template_method_inline_mustache"; } #+end_src ############################################################################### diff --git a/examples/test_environment.cf b/examples/test_environment.cf index 54f2be9e9a..5896fd1890 100644 --- a/examples/test_environment.cf +++ b/examples/test_environment.cf @@ -1,103 +1,80 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - ####################################################### # # Guest environments # ####################################################### - body common control - { - bundlesequence => { "my_vm_cloud" }; + bundlesequence => { "my_vm_cloud" }; } - ####################################################### - bundle agent my_vm_cloud - { guest_environments: - - scope||any:: # These should probably be in class "any" to ensure uniqueness - + scope||any:: + # These should probably be in class "any" to ensure uniqueness "test2" - - environment_resources => my_environment, - environment_interface => vnet("eth0,192.168.1.100/24"), - environment_type => "test", - environment_state => "create", - environment_host => "atlas"; - + environment_resources => my_environment, + environment_interface => vnet("eth0,192.168.1.100/24"), + environment_type => "test", + environment_state => "create", + environment_host => "atlas"; "test2" - - environment_resources => my_environment, - environment_interface => vnet("eth0,192.168.1.101/24"), - environment_type => "test", - environment_state => "delete", - environment_host => "atlas"; - + environment_resources => my_environment, + environment_interface => vnet("eth0,192.168.1.101/24"), + environment_type => "test", + environment_state => "delete", + environment_host => "atlas"; "test4" - - environment_resources => my_environment, - environment_interface => vnet("eth0,192.168.1.102/24"), - environment_type => "test", - environment_state => "create", - environment_host => "atlas"; + environment_resources => my_environment, + environment_interface => vnet("eth0,192.168.1.102/24"), + environment_type => "test", + environment_state => "create", + environment_host => "atlas"; "network1" - environment_type => "test_net", - environment_state => "create", - environment_host => "atlas"; - - - # default environment_state => "create" on host, and "suspended elsewhere" + environment_type => "test_net", + environment_state => "create", + environment_host => "atlas"; + # default environment_state => "create" on host, and "suspended elsewhere" } - ####################################################### - 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 } - ####################################################### - body environment_interface vnet(primary) { - env_name => "$(this.promiser)"; - env_addresses => { "$(primary)" }; - - host1:: - - env_network => "default_vnet1"; - - host2:: - - env_network => "default_vnet2"; - + env_name => "$(this.promiser)"; + env_addresses => { "$(primary)" }; + host1:: + env_network => "default_vnet1"; + host2:: + env_network => "default_vnet2"; } diff --git a/examples/tidy_all_files.cf b/examples/tidy_all_files.cf index 413b8e38d7..8a4b07a0c2 100644 --- a/examples/tidy_all_files.cf +++ b/examples/tidy_all_files.cf @@ -1,87 +1,62 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - ####################################################### # # Deleting files, like cf2 tidy age=0 r=inf # ####################################################### - body common control - { - any:: - - bundlesequence => { "example" }; + any:: + bundlesequence => { "example" }; } - ############################################ - bundle agent example - { files: - - "/home/mark/tmp/test_to" - + "/home/mark/tmp/test_to" delete => tidyfiles, file_select => zero_age, depth_search => recurse("inf"); - # Now delete the parent. - - "/home/mark/tmp/testcopy" - delete => tidyfiles; + # Now delete the parent. + "/home/mark/tmp/testcopy" delete => tidyfiles; } - ######################################################### - body depth_search recurse(d) - { - #include_basedir => "true"; - depth => "$(d)"; + #include_basedir => "true"; + depth => "$(d)"; } - ######################################################### - body delete tidyfiles - { - dirlinks => "delete"; - rmdirs => "true"; + dirlinks => "delete"; + rmdirs => "true"; } - ######################################################### - body file_select zero_age - -# # we can build old "include", "exclude", and "ignore" # from these as standard patterns - these bodies can # form a library of standard patterns -# - { - 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"; } diff --git a/examples/translatepath.cf b/examples/translatepath.cf index 8271a24f93..5d85ad7768 100644 --- a/examples/translatepath.cf +++ b/examples/translatepath.cf @@ -1,38 +1,34 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - #+begin_src cfengine3 body common control { - bundlesequence => { "test" }; + bundlesequence => { "test" }; } bundle agent test { vars: - "inputs_dir" string => translatepath("/a/b/c/inputs"); + "inputs_dir" string => translatepath("/a/b/c/inputs"); reports: - windows:: "The path has backslashes: $(inputs_dir)"; diff --git a/examples/type.cf b/examples/type.cf index 07ab7a2032..18be46d61e 100644 --- a/examples/type.cf +++ b/examples/type.cf @@ -1,35 +1,30 @@ #+begin_src cfengine3 body common control { - bundlesequence => { "example" }; + bundlesequence => { "example" }; } bundle agent example { vars: - "foo" - data => '{ "bar": true, "baz": [1, 2, 3] }'; - - "_foo" string => type("foo", "true"); - "_foobar" string => type("foo[bar]", "false"); - "_foobaz" string => type("foo[baz]", "true"); - - "a" string => "hello"; - "b" int => "123"; - "c" rlist => { "1.1", "2.2", "3.3" }; - - "_a" string => type("a"); - "_b" string => type("b", "true"); - "_c" string => type("c", "false"); + "foo" data => '{ "bar": true, "baz": [1, 2, 3] }'; + "_foo" string => type("foo", "true"); + "_foobar" string => type("foo[bar]", "false"); + "_foobaz" string => type("foo[baz]", "true"); + "a" string => "hello"; + "b" int => "123"; + "c" rlist => { "1.1", "2.2", "3.3" }; + "_a" string => type("a"); + "_b" string => type("b", "true"); + "_c" string => type("c", "false"); reports: - "'foo' is of type '$(_foo)' (detail)"; - "'foo[bar]' is of type '$(_foobar)' (no detail)"; - "'foo[baz]' is of type '$(_foobaz)' (detail)"; - - "'a' is of type '$(_a)' (no detail)"; - "'b' is of type '$(_b)' (detail)"; - "'c' is of type '$(_c)' (no detail)"; + "'foo' is of type '$(_foo)' (detail)"; + "'foo[bar]' is of type '$(_foobar)' (no detail)"; + "'foo[baz]' is of type '$(_foobaz)' (detail)"; + "'a' is of type '$(_a)' (no detail)"; + "'b' is of type '$(_b)' (detail)"; + "'c' is of type '$(_c)' (no detail)"; } #+end_src ############################################################################# diff --git a/examples/unique.cf b/examples/unique.cf index 028f4b7673..41b68e2312 100644 --- a/examples/unique.cf +++ b/examples/unique.cf @@ -1,49 +1,55 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - #+begin_src cfengine3 body common control { - bundlesequence => { "test" }; + bundlesequence => { "test" }; } bundle agent test { vars: - "test" slist => { - 1,2,3, - "one", "two", "three", - "long string", - "four", "fix", "six", - "one", "two", "three", + "test" + slist => { + 1, + 2, + 3, + "one", + "two", + "three", + "long string", + "four", + "fix", + "six", + "one", + "two", + "three", }; - "test_str" string => join(",", "test"); - "test_unique" slist => unique("test"); - "unique_str" string => join(",", "test_unique"); + "test_str" string => join(",", "test"); + "test_unique" slist => unique("test"); + "unique_str" string => join(",", "test_unique"); reports: - "The test list is $(test_str)"; - "The unique elements of the test list: $(unique_str)"; + "The test list is $(test_str)"; + "The unique elements of the test list: $(unique_str)"; } #+end_src ############################################################################### diff --git a/examples/unpack_method_calls.cf b/examples/unpack_method_calls.cf index 7f0a8dae58..1b2343b75d 100644 --- a/examples/unpack_method_calls.cf +++ b/examples/unpack_method_calls.cf @@ -1,39 +1,39 @@ #+begin_src cfengine3 body common control { - bundlesequence => { run }; + bundlesequence => { run }; } bundle agent run { vars: - "todo" slist => { "call_1,a,b", "call_2,x,y", "call_2,p,q" }; + "todo" slist => { "call_1,a,b", "call_2,x,y", "call_2,p,q" }; methods: - "call" usebundle => unpack($(todo)); + "call" usebundle => unpack($(todo)); } bundle agent unpack(list) { vars: - "split" slist => splitstring($(list), ",", "100"); - "method" string => nth("split", "0"); - "param1" string => nth("split", "1"); - "param2" string => nth("split", "2"); + "split" slist => splitstring($(list), ",", "100"); + "method" string => nth("split", "0"); + "param1" string => nth("split", "1"); + "param2" string => nth("split", "2"); methods: - "relay" usebundle => $(method)($(param1), $(param2)); + "relay" usebundle => $(method)($(param1), $(param2)); } bundle agent call_1(p1, p2) { reports: - "$(this.bundle): called with parameters $(p1) and $(p2)"; + "$(this.bundle): called with parameters $(p1) and $(p2)"; } bundle agent call_2(p1, p2) { reports: - "$(this.bundle): called with parameters $(p1) and $(p2)"; + "$(this.bundle): called with parameters $(p1) and $(p2)"; } #+end_src diff --git a/examples/update.cf b/examples/update.cf index 0c1a93656d..1bcc92d318 100644 --- a/examples/update.cf +++ b/examples/update.cf @@ -1,67 +1,58 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - #cop update,example #cop What should a failsafe and update file contain?,example - # Minimum failsafe - body common control { - bundlesequence => { "update" }; + bundlesequence => { "update" }; } bundle agent update { vars: + "master_location" string => "$(sys.workdir)/masterfiles"; - "master_location" string => "$(sys.workdir)/masterfiles"; - - "policy_server" string => readfile("$(sys.workdir)/policy_server.dat",40), + "policy_server" + string => readfile("$(sys.workdir)/policy_server.dat", 40), comment => "IP address to locate your policy host."; classes: - - "policy_host" or => { - classmatch(canonify("ipv4_$(policy_server)")), - classmatch(canonify("$(policy_server)")) + "policy_host" + or => { + classmatch(canonify("ipv4_$(policy_server)")), + classmatch(canonify("$(policy_server)")), }, - comment => "Define the ip identity of the policy source host"; - "have_ppkeys" expression => fileexists("$(sys.workdir)/ppkeys/localhost.pub"); + "have_ppkeys" + expression => fileexists("$(sys.workdir)/ppkeys/localhost.pub"); - "nofile" expression => fileexists("$(sys.workdir)/policy_server.dat"); + "nofile" expression => fileexists("$(sys.workdir)/policy_server.dat"); commands: - !have_ppkeys:: - "/var/cfengine/bin/cf-key"; files: - - "/var/cfengine/inputs" - + "/var/cfengine/inputs" handle => "update_policy", perms => u_p("600"), copy_from => u_scp("$(master_location)"), @@ -69,74 +60,50 @@ bundle agent update action => immediate; processes: - any:: - "cf-execd" restart_class => "start_exec"; policy_host:: - "cf-serverd" restart_class => "start_server"; commands: - start_exec:: - "$(sys.workdir)/bin/cf-execd" - action => logme("executor"); + "$(sys.workdir)/bin/cf-execd" action => logme("executor"); start_server:: - "$(sys.workdir)/bin/cf-serverd" - action => logme("server"); + "$(sys.workdir)/bin/cf-serverd" action => logme("server"); reports: - bootstrap_mode.policy_host:: - "I am the policy host - i.e. with ipv4 address $(policy_server)"; - } - ############################################ - body action logme(x) { - log_repaired => "stdout"; - log_string => " -> Started the $(x) (success)"; + log_repaired => "stdout"; + log_string => " -> Started the $(x) (success)"; } - ############################################ - body perms u_p(p) - { - mode => "$(p)"; + mode => "$(p)"; } - ############################################# - body copy_from u_scp(from) - { - source => "$(from)"; - compare => "digest"; - trustkey => "true"; - - !policy_host:: - - servers => { "$(policy_server)" }; + source => "$(from)"; + compare => "digest"; + trustkey => "true"; + !policy_host:: + servers => { "$(policy_server)" }; } - ######################################################### - body action immediate { - ifelapsed => "1"; + ifelapsed => "1"; } - ############################################ - body depth_search u_recurse(d) - { - depth => "$(d)"; + depth => "$(d)"; } diff --git a/examples/user_edit.cf b/examples/user_edit.cf index 1a19d20ee9..ded5940ec8 100644 --- a/examples/user_edit.cf +++ b/examples/user_edit.cf @@ -1,69 +1,60 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - - -# - body common control { - bundlesequence => { "users" }; + bundlesequence => { "users" }; } body agent control { - abortbundleclasses => { "ldap_fail" }; + abortbundleclasses => { "ldap_fail" }; } - ################################################################################ - bundle agent users { vars: - - "users" slist => { "mark", "nakarin", "jonhenrik" }; + "users" slist => { "mark", "nakarin", "jonhenrik" }; files: - - "/tmp/passwd2" - + "/tmp/passwd2" create => "true", edit_line => fix_passwd("$(users)"); reports: - !ldap_fail:: - "Editing user $(users)"; } - ################################################################################################### - bundle edit_line fix_passwd(x) { classes: - - "ldap_fail" not => ldaparray("dat","ldap://eternity.iu.hio.no","dc=cfengine,dc=com","(uid=$(x))","subtree","none"); + "ldap_fail" + not => ldaparray( + "dat", + "ldap://eternity.iu.hio.no", + "dc=cfengine,dc=com", + "(uid=$(x))", + "subtree", + "none" + ); insert_lines: - - "Hello $(x),$(dat[uid]),$(dat[gecos])"; + "Hello $(x),$(dat[uid]),$(dat[gecos])"; } diff --git a/examples/user_edit_method.cf b/examples/user_edit_method.cf index fc1a354925..48fca9959a 100644 --- a/examples/user_edit_method.cf +++ b/examples/user_edit_method.cf @@ -1,81 +1,66 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - - -# - body common control { - bundlesequence => { "users" }; + bundlesequence => { "users" }; } body agent control { - abortbundleclasses => { "ldap_fail" }; + abortbundleclasses => { "ldap_fail" }; } - #################################################################################### - bundle agent users { vars: - - "users" slist => { "mark", "nakarin", "three" }; + "users" slist => { "mark", "nakarin", "three" }; methods: - - "all" usebundle => fix_user("$(users)"); - + "all" usebundle => fix_user("$(users)"); } - ################################################################################### - bundle agent fix_user(x) - { classes: - - "ldap_fail" not => ldaparray("dat","ldap://eternity.iu.hio.no","dc=cfengine,dc=com","(uid=$(x))","subtree","none"); + "ldap_fail" + not => ldaparray( + "dat", + "ldap://eternity.iu.hio.no", + "dc=cfengine,dc=com", + "(uid=$(x))", + "subtree", + "none" + ); files: - - "/tmp/passwd" - + "/tmp/passwd" create => "true", edit_line => fix_passwd("$(x)"); reports: - !ldap_fail:: - "Editing user $(x)"; } - #################################################################################### - bundle edit_line fix_passwd(x) - { insert_lines: - - "Hello $(x),$(fix_user.dat[uid]),$(fix_user.dat[gecos])"; + "Hello $(x),$(fix_user.dat[uid]),$(fix_user.dat[gecos])"; } diff --git a/examples/userexists.cf b/examples/userexists.cf index 979a8f4f97..6a1941c9be 100644 --- a/examples/userexists.cf +++ b/examples/userexists.cf @@ -1,45 +1,38 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - #+begin_src cfengine3 body common control { - bundlesequence => { "example" }; + bundlesequence => { "example" }; } bundle agent example { classes: - - "ok" expression => userexists("root"); + "ok" expression => userexists("root"); reports: - ok:: - "Root exists"; !ok:: - "Root does not exist"; } #+end_src diff --git a/examples/useringroup.cf b/examples/useringroup.cf index 0c594ed0bf..bb9c542978 100644 --- a/examples/useringroup.cf +++ b/examples/useringroup.cf @@ -1,5 +1,5 @@ #+begin_src cfengine3 -body common control +body common control { bundlesequence => { "example" }; } @@ -7,12 +7,12 @@ body common control bundle agent example { classes: - "root_in_root" - expression => useringroup("root", "root"); + "root_in_root" expression => useringroup("root", "root"); reports: root_in_root:: "root is indeed in the root group"; + !root_in_root:: "something went wrong"; } diff --git a/examples/users_type.cf b/examples/users_type.cf index aebf87cfa2..619ad5e5fc 100644 --- a/examples/users_type.cf +++ b/examples/users_type.cf @@ -2,13 +2,12 @@ body file control { inputs => { "$(sys.libdir)/stdlib.cf" }; } - ### Users main BEGIN ### bundle agent main { vars: - "users" slist => { "jack", "john" }; - "skel" string => "/etc/skel"; + "users" slist => { "jack", "john" }; + "skel" string => "/etc/skel"; users: !windows:: @@ -18,7 +17,6 @@ bundle agent main home_bundle => home_skel($(users), $(skel)); } ### Users main END ### - ### Home Bundle BEGIN ### bundle agent home_skel(user, skel) # @brief Initialize a user's home directory with the contents of skel @@ -32,16 +30,14 @@ bundle agent home_skel(user, skel) depth_search => recurse("inf"); } ### Home Bundle END ### - ### Locked User BEGIN ### bundle agent service_accounts { vars: - "users" slist => { "apache", "libuuid" }; + "users" slist => { "apache", "libuuid" }; users: !windows:: - "$(users)" - policy => "locked"; + "$(users)" policy => "locked"; } ### Locked User END ### diff --git a/examples/validdata.cf b/examples/validdata.cf index f9bb636964..c672651e39 100644 --- a/examples/validdata.cf +++ b/examples/validdata.cf @@ -4,15 +4,16 @@ bundle agent main vars: "json_string" string => '{"test": [1, 2, 3]}'; "primitive" string => "\"hello\""; - + reports: - "This JSON string is valid!" - if => validdata("$(json_string)", "JSON"); + "This JSON string is valid!" if => validdata("$(json_string)", "JSON"); + "This JSON string is not valid." unless => validdata("$(json_string)", "JSON"); "This JSON string is valid! (strict)" if => validdata("$(primitive)", "JSON", "true"); + "This JSON string is not valid. (strict)" unless => validdata("$(primitive)", "JSON", "true"); } diff --git a/examples/validjson.cf b/examples/validjson.cf index c11eca8b3b..81ee483023 100644 --- a/examples/validjson.cf +++ b/examples/validjson.cf @@ -6,17 +6,15 @@ bundle agent main "primitive" string => "\"hello\""; reports: - "This JSON string is valid!" - if => validjson("$(json_string)"); - "This JSON string is not valid." - unless => validjson("$(json_string)"); + "This JSON string is valid!" if => validjson("$(json_string)"); + "This JSON string is not valid." unless => validjson("$(json_string)"); "This JSON string is valid! (strict)" if => validjson("$(primitive)", "true"); + "This JSON string is not valid. (strict)" unless => validjson("$(primitive)", "true"); } - #+end_src ############################################################################### #+begin_src example_output diff --git a/examples/varclass.cf b/examples/varclass.cf index 8eacead6ad..125cc7161e 100644 --- a/examples/varclass.cf +++ b/examples/varclass.cf @@ -1,48 +1,30 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - - - body common control - { - bundlesequence => { "example" }; + bundlesequence => { "example" }; } - ########################################################### - bundle agent example - -{ +{ commands: - - "/bin/echo This is linux" - - if => "linux"; - - - "/bin/echo This is solaris" - - if => "solaris"; - + "/bin/echo This is linux" if => "linux"; + "/bin/echo This is solaris" if => "solaris"; } - diff --git a/examples/varexpansion.cf b/examples/varexpansion.cf index 6f30ee2818..26e6c457a7 100644 --- a/examples/varexpansion.cf +++ b/examples/varexpansion.cf @@ -1,54 +1,38 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - - - body common control - { - bundlesequence => { "example" }; + bundlesequence => { "example" }; } - ########################################################### - bundle agent example - -{ +{ vars: - - "scalar1" string => "SCALAR 1"; - "list1" slist => { "LIST1_1", "LIST1_2" } ; - - "array[1]" string => "ARRAY 1"; - "array[2]" string => "ARRAY 2"; - - "i" slist => getindices("array"); + "scalar1" string => "SCALAR 1"; + "list1" slist => { "LIST1_1", "LIST1_2" }; + "array[1]" string => "ARRAY 1"; + "array[2]" string => "ARRAY 2"; + "i" slist => getindices("array"); reports: - "Scalar $(scalar1)"; - - "LIst $(list1)"; - - "Array $(array[$(i)])"; - + "Scalar $(scalar1)"; + "LIst $(list1)"; + "Array $(array[$(i)])"; } - diff --git a/examples/variablesmatching.cf b/examples/variablesmatching.cf index 647b598a9e..68725847bb 100644 --- a/examples/variablesmatching.cf +++ b/examples/variablesmatching.cf @@ -1,41 +1,38 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - #+begin_src cfengine3 body common control { - bundlesequence => { run }; + bundlesequence => { run }; } bundle agent run { vars: - "all" slist => variablesmatching(".*"); - "v" slist => variablesmatching("default:sys.cf_version.*"); - "v_sorted" slist => sort(v, lex); + "all" slist => variablesmatching(".*"); + "v" slist => variablesmatching("default:sys.cf_version.*"); + "v_sorted" slist => sort(v, lex); + reports: - "Variables matching 'default:sys.cf_version.*' = $(v_sorted)"; + "Variables matching 'default:sys.cf_version.*' = $(v_sorted)"; } - #+end_src ############################################################################### #+begin_src example_output diff --git a/examples/variablesmatching_as_data.cf b/examples/variablesmatching_as_data.cf index 19bc026792..bac8a51012 100644 --- a/examples/variablesmatching_as_data.cf +++ b/examples/variablesmatching_as_data.cf @@ -1,41 +1,40 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - #+begin_src cfengine3 body common control { - bundlesequence => { run }; + bundlesequence => { run }; } bundle agent run { vars: - "all" data => variablesmatching_as_data(".*"); # this is huge - "v" data => variablesmatching_as_data("default:sys.cf_version_major.*"); - "v_dump" string => format("%S", v); + "all" data => variablesmatching_as_data(".*"); + + # this is huge + "v" data => variablesmatching_as_data("default:sys.cf_version_major.*"); + "v_dump" string => format("%S", v); + reports: - "Variables matching 'default:sys.cf_version.*' = $(v_dump)"; + "Variables matching 'default:sys.cf_version.*' = $(v_dump)"; } - #+end_src ############################################################################### #+begin_src example_output diff --git a/examples/varnet.cf b/examples/varnet.cf index d104643ff1..8e80bcd60e 100644 --- a/examples/varnet.cf +++ b/examples/varnet.cf @@ -1,14 +1,11 @@ - -body common control -{ - bundlesequence => { "example" }; -} - - - -bundle agent example -{ - reports: - "My default interface and ip4 address is $(sys.interface) and $(sys.ipv4)"; - "Can also extract $(sys.ipv4[Local_Area_Connection_3]), $(sys.ipv4_2[Wireless_Network_Connection])"; -} +body common control +{ + bundlesequence => { "example" }; +} + +bundle agent example +{ + reports: + "My default interface and ip4 address is $(sys.interface) and $(sys.ipv4)"; + "Can also extract $(sys.ipv4[Local_Area_Connection_3]), $(sys.ipv4_2[Wireless_Network_Connection])"; +} diff --git a/examples/vars.cf b/examples/vars.cf index 92b0b6c719..a818981d1b 100644 --- a/examples/vars.cf +++ b/examples/vars.cf @@ -1,39 +1,34 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - body common control { - bundlesequence => {"yes"}; + bundlesequence => { "yes" }; } - bundle agent yes { vars: - - "var" string => "/one/two/last1", + "var" + string => "/one/two/last1", comment => "This is a comment"; - - reports: - "Test = $(var)"; + reports: + "Test = $(var)"; } diff --git a/examples/version_compare.cf b/examples/version_compare.cf index e9859f67e1..0bdb95feb0 100644 --- a/examples/version_compare.cf +++ b/examples/version_compare.cf @@ -4,6 +4,7 @@ bundle agent __main__ reports: "This will be skipped because the version comparison is false" if => version_compare("3.21.0", "<", "3.20.99"); + "This will be printed because the version comparison is true" if => version_compare("3.24.1", ">=", "3.24.1"); } diff --git a/examples/warnifline.cf b/examples/warnifline.cf index f86e560ce3..6caddd7438 100644 --- a/examples/warnifline.cf +++ b/examples/warnifline.cf @@ -1,63 +1,47 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - ######################################################## # # Warn if line matched # ######################################################## - body common control - { - bundlesequence => { "example" }; + bundlesequence => { "example" }; } - ######################################################## - bundle agent example - { files: - - "/var/cfengine/inputs/.*" - + "/var/cfengine/inputs/.*" edit_line => DeleteLinesMatching(".*cfenvd.*"), action => WarnOnly; } - ######################################################## - bundle edit_line DeleteLinesMatching(regex) { delete_lines: - - "$(regex)" action => WarnOnly; - + "$(regex)" action => WarnOnly; } - ######################################################## - body action WarnOnly { - action_policy => "warn"; + action_policy => "warn"; } diff --git a/examples/webserver.cf b/examples/webserver.cf index d6458a5bc6..6c99aaa80c 100644 --- a/examples/webserver.cf +++ b/examples/webserver.cf @@ -1,121 +1,73 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - ####################################################### # # Apache 2 reconfig - modelled on SuSE # ####################################################### - body common control - { - any:: - - bundlesequence => { - apache - }; + any:: + bundlesequence => { apache }; } - ####################################################### - bundle agent apache - { files: - - "/home/mark/tmp/apache2" # "/etc/sysconfig/apache2" - - edit_line => fixapache; + "/home/mark/tmp/apache2" edit_line => fixapache; } - ####################################################### # For the library ####################################################### - bundle edit_line fixapache - -{ # Values have the form NAME = "quoted space separated list" - +{ + # Values have the form NAME = "quoted space separated list" vars: - - "add_modules" slist => { - "dav", - "dav_fs", - "ssl", - "php5", - "dav_svn", - "xyz", - "superduper" + "add_modules" + slist => { + "dav", "dav_fs", "ssl", "php5", "dav_svn", "xyz", "superduper" }; - "del_modules" slist => { - "php3", - "jk", - "userdir", - "imagemap", - "alias" - }; + "del_modules" slist => { "php3", "jk", "userdir", "imagemap", "alias" }; insert_lines: - - "APACHE_CONF_INCLUDE_FILES=\"/site/masterfiles/local-http.conf\""; + "APACHE_CONF_INCLUDE_FILES=\"/site/masterfiles/local-http.conf\""; field_edits: - - ##################################################################### - # APACHE_MODULES="authz_host actions alias auth_basic dav dav_fs imagemap ssl php5 dav_svn authz_default jk" - ##################################################################### - - "APACHE_MODULES=.*" - - # Insert module "columns" between the quoted RHS - # using space separators - - edit_field => quotedvar("$(add_modules)","append"); - - "APACHE_MODULES=.*" - - # Delte module "columns" between the quoted RHS - # using space separators - - edit_field => quotedvar("$(del_modules)","delete"); - - # if this line already exists, edit it + ##################################################################### + # APACHE_MODULES="authz_host actions alias auth_basic dav dav_fs imagemap ssl php5 dav_svn authz_default jk" + ##################################################################### + "APACHE_MODULES=.*" edit_field => quotedvar("$(add_modules)", "append"); + "APACHE_MODULES=.*" edit_field => quotedvar("$(del_modules)", "delete"); + # if this line already exists, edit it } - ######################################## # Bodies ######################################## - -body edit_field quotedvar(newval,method) - +body edit_field quotedvar(newval, method) { - field_separator => "\""; - select_field => "2"; - value_separator => " "; - field_value => "$(newval)"; - field_operation => "$(method)"; - extend_fields => "false"; - allow_blank_fields => "true"; + field_separator => "\""; + select_field => "2"; + value_separator => " "; + field_value => "$(newval)"; + field_operation => "$(method)"; + extend_fields => "false"; + allow_blank_fields => "true"; } - diff --git a/examples/win_dns_client.cf b/examples/win_dns_client.cf index eb4d066952..c48d968076 100644 --- a/examples/win_dns_client.cf +++ b/examples/win_dns_client.cf @@ -1,27 +1,29 @@ # Ensures correct DNS settings for Windows DNS clients # Tested on: Windows Server 2003 32-bit, Windows Server 2008 R2 64-bit - - -body common control -{ - bundlesequence => { "windows_dns" }; -} - -bundle agent windows_dns -{ - vars: - "dns_servers" string => "192.168.1.3 192.168.1.4"; - - "keys" string => execresult("$(sys.winsysdir)\reg.exe query HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces", "noshell"); - "key_list" slist => splitstring("$(keys)", "\r\n", 50); - - - databases: - "$(key_list)" - comment => "Ensure DNS client configuration is correct", - handle => canonify("windows_dns_$(dns_servers)"), - database_operation => "create", - database_rows => { "NameServer,REG_SZ,$(dns_servers)" }, - database_type => "ms_registry", - if => not( strcmp("$(key_list)", "" )); -} +body common control +{ + bundlesequence => { "windows_dns" }; +} + +bundle agent windows_dns +{ + vars: + "dns_servers" string => "192.168.1.3 192.168.1.4"; + + "keys" + string => execresult( + "$(sys.winsysdir)\reg.exe query HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces", + "noshell" + ); + + "key_list" slist => splitstring("$(keys)", "\r\n", 50); + + databases: + "$(key_list)" + comment => "Ensure DNS client configuration is correct", + handle => canonify("windows_dns_$(dns_servers)"), + database_operation => "create", + database_rows => { "NameServer,REG_SZ,$(dns_servers)" }, + database_type => "ms_registry", + if => not(strcmp("$(key_list)", "")); +} diff --git a/examples/win_emergency.cf b/examples/win_emergency.cf index e4279ef885..5e33dbc9f2 100644 --- a/examples/win_emergency.cf +++ b/examples/win_emergency.cf @@ -8,66 +8,44 @@ # by the server control policy). # ######################################################################### - -body common control -{ - bundlesequence => { "win_emergency" }; - inputs => { "$(sys.libdir)/stdlib.cf" }; -} - -bundle agent win_emergency -{ - vars: - "disable_services" slist => { - "RemoteRegistry" # Windows Remote Management - }; - - "secure_files" slist => { - "C:\Secret", - "$(sys.workdir)\secret.txt" - }; - - "close_ports" slist => { - "6510", - "9300" - }; - - - commands: - - emergency:: - - "\"$(sys.winsysdir)\netsh.exe\"" - args => "firewall add portopening ALL $(close_ports) \"Port $(close_ports)\" DISABLE", - comment => "Close firewall ports on emergency"; - - - databases: - - emergency:: - - "HKEY_LOCAL_MACHINE\SOFTWARE\Northern.tech AS\Cfengine" - database_operation => "create", - database_rows => { "emergency,REG_SZ,This is an emergency!" } , - database_type => "ms_registry", - comment => "Create emergency policy registry settings"; - - - files: - - emergency:: - - "$(secure_files)" - acl => strict, - comment => "Secure important file access on emergency"; - - - services: - - emergency:: - - "$(disable_services)" - service_policy => "disable", - comment => "Disable security-relevant services on emergency"; - -} +body common control +{ + bundlesequence => { "win_emergency" }; + inputs => { "$(sys.libdir)/stdlib.cf" }; +} + +bundle agent win_emergency +{ + vars: + "disable_services" + slist => { "RemoteRegistry"# Windows Remote Management }; + + "secure_files" slist => { "C:\Secret", "$(sys.workdir)\secret.txt" }; + "close_ports" slist => { "6510", "9300" }; + + commands: + emergency:: + "\"$(sys.winsysdir)\netsh.exe\"" + args => "firewall add portopening ALL $(close_ports) \"Port $(close_ports)\" DISABLE", + comment => "Close firewall ports on emergency"; + + databases: + emergency:: + "HKEY_LOCAL_MACHINE\SOFTWARE\Northern.tech AS\Cfengine" + database_operation => "create", + database_rows => { "emergency,REG_SZ,This is an emergency!" }, + database_type => "ms_registry", + comment => "Create emergency policy registry settings"; + + files: + emergency:: + "$(secure_files)" + acl => strict, + comment => "Secure important file access on emergency"; + + services: + emergency:: + "$(disable_services)" + service_policy => "disable", + comment => "Disable security-relevant services on emergency"; +} diff --git a/examples/win_registry.cf b/examples/win_registry.cf index 0b66b91e9e..5a0bf2d703 100644 --- a/examples/win_registry.cf +++ b/examples/win_registry.cf @@ -3,92 +3,66 @@ # win_registry.cf - Windows Registry Management # ######################################################################### - -bundle agent win_registry -{ - vars: - - "cache_keys" slist => { - "HKEY_LOCAL_MACHINE\SOFTWARE\Northern.tech AS" - }; - - "reg_create" slist => - { - "value1,REG_SZ,this is the first value...", - "value2,REG_SZ,...and this is the second!" - }; - - "reg_delete" slist => - { - "value1" - }; - - - methods: - - # 1) Cfengine can cache and restore any part of the registry - - # "any" usebundle => registry_cache("@(win_registry.cache_keys)"); - # "any" usebundle => registry_restore("@(win_registry.cache_keys)"); - - # 2) Registry settings may also be explicitly defined/deleted in policy - - # "any" usebundle => registry_define("HKEY_LOCAL_MACHINE\SOFTWARE\Northern.tech AS\Cfengine", "@(win_registry.reg_create)"); - # "any" usebundle => registry_delete("HKEY_LOCAL_MACHINE\SOFTWARE\Northern.tech AS\Cfengine", "@(win_registry.reg_delete)"); -} - +bundle agent win_registry +{ + vars: + "cache_keys" slist => { "HKEY_LOCAL_MACHINE\SOFTWARE\Northern.tech AS" }; + + "reg_create" + slist => { + "value1,REG_SZ,this is the first value...", + "value2,REG_SZ,...and this is the second!", + }; + + "reg_delete" slist => { "value1" }; + + methods: + # 1) Cfengine can cache and restore any part of the registry + # "any" usebundle => registry_cache("@(win_registry.cache_keys)"); + # "any" usebundle => registry_restore("@(win_registry.cache_keys)"); + # 2) Registry settings may also be explicitly defined/deleted in policy + # "any" usebundle => registry_define("HKEY_LOCAL_MACHINE\SOFTWARE\Northern.tech AS\Cfengine", "@(win_registry.reg_create)"); + # "any" usebundle => registry_delete("HKEY_LOCAL_MACHINE\SOFTWARE\Northern.tech AS\Cfengine", "@(win_registry.reg_delete)"); +} ######################################################################### - -bundle agent registry_cache(keys) -{ - databases: - windows:: - - "$(keys)" - database_operation => "cache", - database_type => "ms_registry", - comment => "Save correct registry settings"; -} - +bundle agent registry_cache(keys) +{ + databases: + windows:: + "$(keys)" + database_operation => "cache", + database_type => "ms_registry", + comment => "Save correct registry settings"; +} ######################################################################### - -bundle agent registry_restore(keys) -{ - databases: - windows:: - - "$(keys)" - database_operation => "restore", - database_type => "ms_registry", - comment => "Make sure correct registry settings are set, according to cached version"; -} - +bundle agent registry_restore(keys) +{ + databases: + windows:: + "$(keys)" + database_operation => "restore", + database_type => "ms_registry", + comment => "Make sure correct registry settings are set, according to cached version"; +} ######################################################################### - -bundle agent registry_define(key, contents) -{ - databases: - windows:: - - "$(key)" - - database_operation => "create", - database_rows => { "$(contents)" } , - database_type => "ms_registry", - comment => "Explicitly define important registry settings"; -} - +bundle agent registry_define(key, contents) +{ + databases: + windows:: + "$(key)" + database_operation => "create", + database_rows => { "$(contents)" }, + database_type => "ms_registry", + comment => "Explicitly define important registry settings"; +} ######################################################################### - -bundle agent registry_delete(key, values) -{ - databases: - windows:: - - "$(key)" - - database_operation => "delete", - database_columns => { "@(values)" } , - database_type => "ms_registry", - comment => "Remove unwanted registry values"; -} +bundle agent registry_delete(key, values) +{ + databases: + windows:: + "$(key)" + database_operation => "delete", + database_columns => { "@(values)" }, + database_type => "ms_registry", + comment => "Remove unwanted registry values"; +} diff --git a/examples/win_schedule.cf b/examples/win_schedule.cf index 29d46b340f..af294113d2 100644 --- a/examples/win_schedule.cf +++ b/examples/win_schedule.cf @@ -9,57 +9,52 @@ # security and performance. # ######################################################################### - -body common control -{ - bundlesequence => { "system_scheduling" }; - inputs => { "$(sys.libdir)/stdlib.cf" }; -} - -bundle agent system_scheduling -{ - vars: - - # Command definitions are given in cmd[index]. - # The dependencies of the commands are dep_cmd[index], as boolean class expressions. - # Comments are given as comment_cmd[index] - - "cmd[1]" string => "$(sys.cf_key)"; - "dep_cmd[1]" string => "cmd2_success"; - "comment_cmd[1]" string => "Check that a Cfengine key is generated if command 2 has run (dummy)"; - - - windows:: - "cmd[2]" string => "\"$(sys.winsysdir)\shutdown.exe\" /r /c \"Cfengine automatic restart\" /t 120"; - "dep_cmd[2]" string => "Monday.Hr05.Min00_05"; - "comment_cmd[2]" string => "Restart windows every week"; - - "cmd[3]" string => "$(sys.winsysdir)\cscript.exe \"$(sys.workdir)\script1.vbs\" //Nologo > \"$(sys.workdir)\script1_out.txt\""; - "dep_cmd[3]" string => "Hr05.Min05_10"; - "comment_cmd[3]" string => "Run a script and save its output for later reference (needs to be run in shell)"; - - - !windows:: - - "cmd[2]" string => "/bin/echo Hello World!"; - "dep_cmd[2]" string => "Hr12.Min00_05"; - "comment_cmd[2]" string => "Print a message (dummy)"; - - - any:: - - "cmd_index" slist => getindices("cmd"); - - - commands: - - # Runs a command if its dependencies are satisfied - - "$(cmd[$(cmd_index)])" - classes => if_repaired("cmd$(cmd_index)_success"), - if => "$(dep_cmd[$(cmd_index)])", - contain => in_shell, - comment => "$(comment_cmd[$(cmd_index)])"; - -} - +body common control +{ + bundlesequence => { "system_scheduling" }; + inputs => { "$(sys.libdir)/stdlib.cf" }; +} + +bundle agent system_scheduling +{ + vars: + # Command definitions are given in cmd[index]. + # The dependencies of the commands are dep_cmd[index], as boolean class expressions. + # Comments are given as comment_cmd[index] + "cmd[1]" string => "$(sys.cf_key)"; + "dep_cmd[1]" string => "cmd2_success"; + + "comment_cmd[1]" + string => "Check that a Cfengine key is generated if command 2 has run (dummy)"; + + windows:: + "cmd[2]" + string => "\"$(sys.winsysdir)\shutdown.exe\" /r /c \"Cfengine automatic restart\" /t 120"; + + "dep_cmd[2]" string => "Monday.Hr05.Min00_05"; + "comment_cmd[2]" string => "Restart windows every week"; + + "cmd[3]" + string => "$(sys.winsysdir)\cscript.exe \"$(sys.workdir)\script1.vbs\" //Nologo > \"$(sys.workdir)\script1_out.txt\""; + + "dep_cmd[3]" string => "Hr05.Min05_10"; + + "comment_cmd[3]" + string => "Run a script and save its output for later reference (needs to be run in shell)"; + + !windows:: + "cmd[2]" string => "/bin/echo Hello World!"; + "dep_cmd[2]" string => "Hr12.Min00_05"; + "comment_cmd[2]" string => "Print a message (dummy)"; + + any:: + "cmd_index" slist => getindices("cmd"); + + commands: + # Runs a command if its dependencies are satisfied + "$(cmd[$(cmd_index)])" + classes => if_repaired("cmd$(cmd_index)_success"), + if => "$(dep_cmd[$(cmd_index)])", + contain => in_shell, + comment => "$(comment_cmd[$(cmd_index)])"; +} diff --git a/examples/with.cf b/examples/with.cf index 9a9ce649d9..2eacc57a0e 100644 --- a/examples/with.cf +++ b/examples/with.cf @@ -1,35 +1,35 @@ # Copyright 2021 Northern.tech AS - +# # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. - # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; version 3. - +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - # To the extent this program is licensed as part of the Enterprise # versions of Cfengine, the applicable Commercial Open Source License # (COSL) may apply to this file if you as a licensee so wish it. See # included file COSL.txt. - #+begin_src cfengine3 bundle agent main { vars: - "todo" slist => { "a 1", "b 2", "c 3" }; - # Here, `with` is the canonified version of $(todo), letting us avoid an - # intermediate canonification array. - "$(with)" string => "$(todo)", with => canonify($(todo)); + "todo" slist => { "a 1", "b 2", "c 3" }; - "complex" data => ' + # Here, `with` is the canonified version of $(todo), letting us avoid an + # intermediate canonification array. + "$(with)" + string => "$(todo)", + with => canonify($(todo)); + + "complex" data => ' { "x": 200, "y": [ 1, 2, null, true, false ] @@ -37,16 +37,15 @@ bundle agent main '; reports: - "For iterable '$(todo)' we created variable '$(with)' and its value is '$(todo)'" - with => canonify($(todo)); + "For iterable '$(todo)' we created variable '$(with)' and its value is '$(todo)'" + with => canonify($(todo)); - "We can print a data container compactly without creating a temporary variable: $(with)" - with => format("%S", complex); + "We can print a data container compactly without creating a temporary variable: $(with)" + with => format("%S", complex); - "We can print a data container fully without creating a temporary variable: $(with)" - with => storejson(complex); + "We can print a data container fully without creating a temporary variable: $(with)" + with => storejson(complex); } - #+end_src ############################################################################### #+begin_src example_output diff --git a/examples/zenoss.cf b/examples/zenoss.cf index 45736fc610..5e2b0a8d3d 100644 --- a/examples/zenoss.cf +++ b/examples/zenoss.cf @@ -1,88 +1,70 @@ - ###################################################################### # # Zenoss integration template example # ###################################################################### - body common control { - bundlesequence => { "zenoss_host", "zenoss_client" }; - syslog_host => "zenoss_syslog.example.org"; - syslog_port => "514"; - inputs => { "$(sys.libdir)/stdlib.cf" }; + bundlesequence => { "zenoss_host", "zenoss_client" }; + syslog_host => "zenoss_syslog.example.org"; + syslog_port => "514"; + inputs => { "$(sys.libdir)/stdlib.cf" }; } - ######################################################## - bundle agent zenoss_host { vars: + "cf_server_hosts" string => "cfengine_policy.example.org"; + "cf_doc_root" string => "/srv/www/html"; + "zCfengineComplianceFile" string => "/home/zenoss/compliance.zen"; - "cf_server_hosts" string => "cfengine_policy.example.org"; - "cf_doc_root" string => "/srv/www/html"; - "zCfengineComplianceFile" string => "/home/zenoss/compliance.zen"; - - files: - - # Assume Cfengine is running on the zenoss server to collect data - + files: + # Assume Cfengine is running on the zenoss server to collect data zenoss_syslog_example_org:: - "$(zCfengineComplianceFile)" - - comment => "Collect data from the Cfengine policy server", - perms => mo("644","zenoss"), - copy_from => secure_cp("$(cf_doc_root)/reports/summary.z","$(cf_server_host)"); - + comment => "Collect data from the Cfengine policy server", + perms => mo("644", "zenoss"), + copy_from => secure_cp( + "$(cf_doc_root)/reports/summary.z", "$(cf_server_host)" + ); } - ######################################################## - bundle agent zenoss_client { processes: - - # On clients, we just pass any messages to the zenoss server - # for logging... - - "bad_process" - + # On clients, we just pass any messages to the zenoss server + # for logging... + "bad_process" comment => "Make sure that process X is not running, tell zenoss if it was", signals => { "term", "kill" }, action => tell_zenoss_repaired("bad_process was killed"); files: - - "/etc/passwd" - + "/etc/passwd" comment => "Check passwd security, tell zenoss if permissions were wrong", - perms => mog("644","root","root"), + perms => mog("644", "root", "root"), action => tell_zenoss_repaired("passwd file had incorrect permissions"); commands: - - "/my/important/script -xyz" - + "/my/important/script -xyz" comment => "Run my mission critical batch process", - action => tell_zenoss_failed("myscript failed to execute or returned error"); - + action => tell_zenoss_failed( + "myscript failed to execute or returned error" + ); } - -# # Library stuff -# - body action tell_zenoss_repaired(x) { - log_repaired => "udp_syslog"; - log_string => "zenoss_cfengine_integration $(x) promise repaired"; - ifelapsed => "10"; # Every 10 mins + log_repaired => "udp_syslog"; + log_string => "zenoss_cfengine_integration $(x) promise repaired"; + ifelapsed => "10"; + # Every 10 mins } body action tell_zenoss_failed(x) { - log_failed => "udp_syslog"; - log_string => "zenoss_cfengine_integration $(x) persistent problem"; - ifelapsed => "10"; # Every 10 mins + log_failed => "udp_syslog"; + log_string => "zenoss_cfengine_integration $(x) persistent problem"; + ifelapsed => "10"; + # Every 10 mins } diff --git a/tests/acceptance/00_basics/04_bundles/wrong-bundle-type.cf b/tests/acceptance/00_basics/04_bundles/wrong-bundle-type.cf index 34f8381459..891fec99e5 100644 --- a/tests/acceptance/00_basics/04_bundles/wrong-bundle-type.cf +++ b/tests/acceptance/00_basics/04_bundles/wrong-bundle-type.cf @@ -16,7 +16,7 @@ bundle agent init bundle agent test { vars: - "subout" string => execresult("${sys.cf_agent} -Kf ${this.promise_filename}.sub", "noshell"); + "subout" string => execresult("${sys.cf_agent} -Kf $(this.promise_dirname)/wrong-bundle-type.sub.x.cf", "noshell"); } bundle agent check diff --git a/tests/acceptance/00_basics/04_bundles/wrong-bundle-type.cf.sub b/tests/acceptance/00_basics/04_bundles/wrong-bundle-type.sub.x.cf similarity index 100% rename from tests/acceptance/00_basics/04_bundles/wrong-bundle-type.cf.sub rename to tests/acceptance/00_basics/04_bundles/wrong-bundle-type.sub.x.cf diff --git a/tests/acceptance/01_vars/02_functions/classfilterdata_collecting.cf b/tests/acceptance/01_vars/02_functions/classfilterdata_collecting.cf index dba9671cdf..d40d5a4aa8 100644 --- a/tests/acceptance/01_vars/02_functions/classfilterdata_collecting.cf +++ b/tests/acceptance/01_vars/02_functions/classfilterdata_collecting.cf @@ -14,21 +14,21 @@ bundle agent init "mode": "755", "owner": "root", "group": "root", - "ifvarclass": "role_1" + "if": "role_1" }, { "file": "/tmp/bar", "mode": "600", "owner": "root", "group": "root", - "ifvarclass": "role_2" + "if": "role_2" }, { "file": "/tmp/baz", "mode": "644", "owner": "root", "group": "root", - "ifvarclass": "(role_1|role_2)" + "if": "(role_1|role_2)" } ]'; } @@ -44,7 +44,7 @@ bundle agent test vars: "filtered" - data => classfilterdata(readjson("$(G.testfile).json"), "auto", "ifvarclass"); + data => classfilterdata(readjson("$(G.testfile).json"), "auto", "if"); } bundle agent check @@ -57,14 +57,14 @@ bundle agent check "mode": "600", "owner": "root", "group": "root", - "ifvarclass": "role_2" + "if": "role_2" }, { "file": "/tmp/baz", "mode": "644", "owner": "root", "group": "root", - "ifvarclass": "(role_1|role_2)" + "if": "(role_1|role_2)" } ]'); "actual" diff --git a/tests/acceptance/02_classes/01_basic/if_resolving_classexpression_from_datacontainer.cf b/tests/acceptance/02_classes/01_basic/if_resolving_classexpression_from_datacontainer.cf index bdaf17203e..ba14969dd7 100644 --- a/tests/acceptance/02_classes/01_basic/if_resolving_classexpression_from_datacontainer.cf +++ b/tests/acceptance/02_classes/01_basic/if_resolving_classexpression_from_datacontainer.cf @@ -11,7 +11,7 @@ bundle agent test { meta: "description" -> { "CFE-3319" } - string => "Test that if/ifvarclass can check class expressions from within a data container"; + string => "Test that if can check class expressions from within a data container"; vars: diff --git a/tests/acceptance/dcs.sub.cf b/tests/acceptance/dcs.sub.cf index 15bba3cd3d..757943343b 100644 --- a/tests/acceptance/dcs.sub.cf +++ b/tests/acceptance/dcs.sub.cf @@ -116,16 +116,16 @@ bundle common G vars: # General commands. "$(cmds)" string => "$(paths[$(paths_indices)])$(const.dirsep)$(cmds)$(exeext)", - ifvarclass => canonify("$(paths_indices)_$(cmds)$(exeext)"); + if => canonify("$(paths_indices)_$(cmds)$(exeext)"); # Special cases. "$(sbin_cmds)" string => "$(paths[$(paths_indices)])$(const.dirsep)$(sbin_cmds)$(exeext)", - ifvarclass => canonify("$(paths_indices)_$(sbin_cmds)$(exeext)"); + if => canonify("$(paths_indices)_$(sbin_cmds)$(exeext)"); # gmake has higher priority, so should come last. "make" string => "$(paths[$(paths_indices)])$(const.dirsep)make$(exeext)", - ifvarclass => canonify("$(paths_indices)_make$(exeext)"); + if => canonify("$(paths_indices)_make$(exeext)"); "make" string => "$(paths[$(paths_indices)])$(const.dirsep)gmake$(exeext)", - ifvarclass => canonify("$(paths_indices)_gmake$(exeext)"); + if => canonify("$(paths_indices)_gmake$(exeext)"); # on solaris, gsed works more like GNU sed, such as having `-i` option solaris:: @@ -247,7 +247,7 @@ bundle agent test_run(filename) AUTO:: "any" usebundle => "$(default.tests)", - ifvarclass => canonify("have_test_run_$(default.tests)"); + if => canonify("have_test_run_$(default.tests)"); reports: !AUTO:: @@ -460,15 +460,15 @@ bundle agent dcs_report_generic_classes(x) reports: DEBUG:: - "class '$(x)_$(choices)' was defined" ifvarclass => '$(x)_$(choices)'; - "class '$(x)_$(choices)' was NOT defined" ifvarclass => '!$(x)_$(choices)'; + "class '$(x)_$(choices)' was defined" if => '$(x)_$(choices)'; + "class '$(x)_$(choices)' was NOT defined" if => '!$(x)_$(choices)'; } bundle agent dcs_generic_classes_to_string(x) { vars: "choices" slist => { "repaired", "failed", "denied", "timeout", "kept" }; - "s[$(choices)]" string => "$(x)_$(choices)", ifvarclass => '$(x)_$(choices)'; + "s[$(choices)]" string => "$(x)_$(choices)", if => '$(x)_$(choices)'; "found_unsorted" slist => getvalues(s); "found" slist => sort(found_unsorted, "lex"); "found_str" string => format("%S", found); @@ -792,13 +792,13 @@ reports: bundle agent dcs_passif(classname, test) { reports: - "$(test) Pass" ifvarclass => $(classname); - "$(test) FAIL" ifvarclass => not($(classname)); + "$(test) Pass" if => $(classname); + "$(test) FAIL" if => not($(classname)); EXTRA:: - "$(this.bundle): passing based on class '$(classname)'" ifvarclass => $(classname); + "$(this.bundle): passing based on class '$(classname)'" if => $(classname); DEBUG:: - "$(this.bundle): failing based on class '$(classname)'" ifvarclass => not($(classname)); + "$(this.bundle): failing based on class '$(classname)'" if => not($(classname)); } bundle agent dcs_pass(test) @@ -872,17 +872,17 @@ bundle agent dcs_passif_expected(expected, not_expected, test) reports: DEBUG:: "$(this.bundle): bad: $(ex) was NOT defined" - ifvarclass => "!$(ex)"; + if => "!$(ex)"; "$(this.bundle): bad: $(notex) WAS defined" - ifvarclass => "$(notex)"; + if => "$(notex)"; EXTRA:: "$(this.bundle): good: $(ex) WAS defined" - ifvarclass => "$(ex)"; + if => "$(ex)"; "$(this.bundle): good: $(notex) was NOT defined" - ifvarclass => "!$(notex)"; + if => "!$(notex)"; } ####################################################### @@ -906,17 +906,17 @@ bundle agent dcs_passif_output(wanted, unwanted, command, test) reports: DEBUG:: "$(this.bundle): bad: '$(wanted)' was NOT found in the output of '$(command)'" - ifvarclass => "!__passif_output_wanted"; + if => "!__passif_output_wanted"; "$(this.bundle): bad: '$(unwanted)' WAS found in the output of '$(command)'" - ifvarclass => "__passif_output_unwanted"; + if => "__passif_output_unwanted"; EXTRA:: "$(this.bundle): good: '$(wanted)' WAS found in the output of '$(command)'" - ifvarclass => "__passif_output_wanted"; + if => "__passif_output_wanted"; "$(this.bundle): good: '$(unwanted)' was NOT found in the output of '$(command)'" - ifvarclass => "!__passif_output_unwanted"; + if => "!__passif_output_unwanted"; DEBUG:: "$(this.bundle): the output of command '$(command)' was: '$(subout)'"; diff --git a/tests/unit/data/body_executor_control_empty.cf b/tests/unit/data/body_executor_control_empty.cf index 8b13789179..314b71f668 100644 --- a/tests/unit/data/body_executor_control_empty.cf +++ b/tests/unit/data/body_executor_control_empty.cf @@ -1 +1 @@ - +# No configuration for cf-execd here diff --git a/tests/unit/data/constraint_lval_invalid.cf b/tests/unit/data/constraint_lval_invalid.cf deleted file mode 100644 index 588f84ec38..0000000000 --- a/tests/unit/data/constraint_lval_invalid.cf +++ /dev/null @@ -1,7 +0,0 @@ -bundle agent test -{ - files: - "$(G.testdir)/shouldnotexist" - create => "true", - nonexistent_attribute => "abc"; -} diff --git a/tests/unit/data/vars_multiple_types.cf b/tests/unit/data/vars_multiple_types.x.cf similarity index 100% rename from tests/unit/data/vars_multiple_types.cf rename to tests/unit/data/vars_multiple_types.x.cf diff --git a/tests/unit/policy_test.c b/tests/unit/policy_test.c index 11311d0c2c..26ffea99ce 100644 --- a/tests/unit/policy_test.c +++ b/tests/unit/policy_test.c @@ -138,7 +138,7 @@ static void test_body_control_no_arguments(void) static void test_vars_multiple_types(void) { - Seq *errs = LoadAndCheck("vars_multiple_types.cf"); + Seq *errs = LoadAndCheck("vars_multiple_types.x.cf"); assert_int_equal(1, errs->length); SeqDestroy(errs);