Switch branches/tags
Find file History
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
..
Failed to load latest commit information.
Makefile.am
README.org
abort.cf
accessed_before.cf
accessedbefore.cf
accumulated_time.cf
acl.cf
acl_generic.cf
acl_ntfs.cf
acl_secret.cf
active_directory.cf
activedirectory_listusers.cf
activedirectory_showuser.cf
ago.cf
app_baseline.cf
appgroups.cf
arrays.cf
augment.cf
backreferences_files.cf
badpromise.cf
badtype.cf
bsdflags.cf
bundle_return_values.cf
bundlesequence.cf
bundlesmatching.cf
bundlestate.cf
canonify.cf
cf2_integration.cf
change_detect.cf
changedbefore.cf
chdir.cf
class-automatic-canonificiation.cf
classes_global.cf
classesmatching.cf
classmatch.cf
classvar_convergence.cf
commands.cf
compare.cf
container_iteration.cf
container_key_iteration.cf
control_expand.cf
controlclasses.cf
copy.cf
copy_classes.cf
copy_copbl.cf
copy_edit.cf
copydir_copbl.cf
copylinks.cf
countclassesmatching.cf
countlinesmatching.cf
create_filedir.cf
createdb.cf
customize_by_named_list.cf
data_expand.cf
data_readstringarray.cf
data_regextract.cf
datastate.cf
def.json
defaults.cf
defaults2.cf
defaults3.cf
definitions.cf
deletelines.cf
depends_on.cf
depends_on2.cf
difference.cf
dirname.cf
disable.cf
disable_and_rotate_files.cf
diskfree.cf
dollar.cf
edit_column_files.cf
edit_comment_lines.cf
edit_deletenotmatch.cf
edit_insert_fuzzylines.cf
edit_insert_lines.cf
edit_insert_lines_silly.cf
edit_passwd_file.cf
edit_passwd_file_basic.cf
edit_replace_string.cf
edit_sectioned_file.cf
edit_setvar.cf
edit_template.cf
edit_triggerclass.cf
edit_xml.cf
ensure_line_present_prepend_append.cf
env.cf
epimenides.cf
escape.cf
eval.cf
every.cf
exec_args.cf
exec_in_sequence.cf
execd.cf
execresult.cf
expand.cf
failedcommand.cf
failsafe.cf
file_change_detection.cf
file_hash.cf
file_owner_list_template.cf
fileexists.cf
filenames.cf
fileperms.cf
filesexist.cf
filesexist2.cf
filesize.cf
filestat.cf
filter.cf
findfiles.cf
fix_names.cf
format.cf
getclassmetatags.cf
getenv.cf
getfields.cf
getgid.cf
getindices.cf
getindices_and_values.cf
getmacaddress.cf
getregistry.cf
getuid.cf
getuserinfo.cf
getusers.cf
getvalues.cf
getvariablemetatags.cf
global_list_expansion.cf
global_list_expansion_2.cf
grep.cf
groupexists.cf
guest_environment_kvm.cf
hash.cf
hash_to_int.cf
hashcomment.cf
hashmatch.cf
hashuncomment.cf
helloworld.cf
host2ip.cf
hostrange.cf
hostsseen.cf
hostswithclass.cf
hub.cf
id.cf
inherit.cf
insert_users.cf
intarray.cf
intersection.cf
inventory_cpu.cf
ip2host.cf
iprange.cf
irange.cf
isdir.cf
isexecutable.cf
isgreaterthan.cf
isipinsubnet.cf
islessthan.cf
islink.cf
isnewerthan.cf
isplain.cf
isvariable.cf
iteration.cf
join.cf
kill_process_running_wrong_user.cf
knowledge_driver.cf
knowledge_txt.cf
lastnode.cf
ldap.cf
length.cf
linking.cf
literal_server.cf
local_group_present.cf
local_user_password.cf
local_user_secondary_group_member.cf
local_users_absent.cf
local_users_locked.cf
local_users_present.cf
locate_files_and_compress.cf
log_private.cf
loops.cf
lsdir.cf
main.cf
main_entry_point.cf
main_library.cf
maparray.cf
mapdata.cf
mapdata_jsonpipe.cf
maplist.cf
max-min-mean-variance.cf
measure_log.cf
measurements.cf
menu.cf
mergedata.cf
meta.cf
method.cf
method_polymorph.cf
method_validate.cf
method_var.cf
method_var2.cf
missing_ok.cf
module_exec.cf
module_exec_2.cf
monitord.cf
mount_fs.cf
multipassvars.cf
multiple_outcomes.cf
mustache_classes.cf
mustache_comments.cf
mustache_extension_compact_json.cf
mustache_extension_expand_key.cf
mustache_extension_multiline_json.cf
mustache_extension_top.cf
mustache_sections_empty_list.cf
mustache_sections_inverted.cf
mustache_sections_non_empty_list.cf
mustache_sections_non_false_value.cf
mustache_set_delimiters.cf
mustache_template_motd.cf
mustache_template_motd.cf.mustache
mustache_variables.cf
namespace.cf
namespace1.cf
namespace2.cf
namespace3.cf
namespace_class1.cf
namespace_classes.cf
namespace_var_meta.cf
namespace_var_meta2.cf
neighbourhood_watch.cf
none.cf
nth.cf
null_config.cf
occurrences.cf
orchestrate_chain1.cf
orchestrate_chain2.cf
orchestrate_delay_trigger.cf
orchestrate_dominoes1.cf
orchestrate_dominoes2.cf
orchestrate_dragon.cf
orchestrate_dragon_load_balancer.cf
orchestrate_n_of_m.cf
orchestration_hostlist.cf
ordering.cf
package_apt.cf
package_bundles.cf
package_freebsd.cf
package_latest.cf
package_msi_file.cf
package_msi_version.cf
package_rpm.cf
package_solaris.cf
package_windows_feature.cf
package_yum.cf
package_zypper.cf
packagesmatching.cf
parallel_exec.cf
parseintrealstringarray.cf
parsestringarray.cf
parsestringarrayidx.cf
pathtype.cf
pattern_and_edit.cf
peerleader.cf
peerleaders.cf
peers.cf
postfix.cf
process_kill.cf
process_matching.cf
process_matching2.cf
process_matching3.cf
process_restart.cf
process_restart_basic.cf
process_signalling.cf
processes_define_class_based_on_process_runtime.cf
product.cf
promise_knowledge.cf
promises.cf
quoting.cf
randomint.cf
readcsv.cf
readdata.cf
readenvfile.cf
readfile.cf
readintarray.cf
readintrealstringlist.cf
readlist.cf
readrealarray.cf
readstringarray.cf
readtcp.cf
reg_multiline.cf
regarray.cf
regcmp.cf
regex_replace.cf
regex_win.cf
regextract.cf
registry.cf
registry_cache.cf
registryvalue.cf
regline.cf
reglist.cf
remake_outputs.pl
remoteclasses.cf
remoteclasses2.cf
remotescalar.cf
remove_deadlinks.cf
rename.cf
repairedcommand.cf
report_custom.cf
report_diffs.cf
report_state.cf
reporting.cf
reports.cf
reporttofile.cf
resolveconf.cf
returnszero.cf
reverse.cf
root_passwd.cf
select_class.cf
select_mode.cf
select_region.cf
select_size.cf
selectservers.cf
server_callback.cf
server_copy_localhost.cf
server_copy_purge.cf
server_copy_remote.cf
server_flatcopy_localhost.cf
service_catalogue.cf
service_catalogue_separate.cf
service_disable.cf
service_start.cf
services.cf
services_concept.cf
services_default_service_bundle.cf
services_win.cf
setuidlog.cf
setvar.cf
shuffle.cf
simple_ssh_key_distribution.cf
software_dist.cf
software_update_version_yum.cf
some.cf
sort.cf
splitstring.cf
sql_table_structure.cf
storage.cf
strcmp.cf
strftime.cf
string_downcase.cf
string_head.cf
string_length.cf
string_mustache.cf
string_replace.cf
string_reverse.cf
string_split.cf
string_tail.cf
string_upcase.cf
stringarray.cf
sublist.cf
sum.cf
switchcase.cf
symlink.cf
symlink_children.cf
syslog.cf
syslog2.cf
template.cf
template2.cf
test_environment.cf
tidy_all_files.cf
topic_map.ltm
translatepath.cf
unique.cf
unpack_method_calls.cf
update.cf
user_edit.cf
user_edit_method.cf
userexists.cf
users_type.cf
varclass.cf
varexpansion.cf
variablesmatching.cf
variablesmatching_as_data.cf
varnet.cf
vars.cf
warnifline.cf
webserver.cf
win_dns_client.cf
win_emergency.cf
win_registry.cf
win_schedule.cf
with.cf
zenoss.cf

README.org

Examples

This directory contains simple stand alone examples that illustrate the language and how cfengine works.

These examples are shipped in our packages as part embedded package documentation and are commonly included from the documentation repository for inclusion in the reference manual.

Examples that contain an example_output src block are run as part of our common automated tests during ci builds.

Before running an example be sure to execute the commands inside the prep src block if one exists.

awk '/.*begin_src prep/ {p=1}; p; /.*end_src/ {p=0}' ./file_hash.cf
#+begin_src prep
#@ ```
#@ echo 1 > /tmp/1
#@ echo 2 > /tmp/2
#@ echo 3 > /tmp/3
#@ ```
#+end_src

They can be run directly:

chmod 600 ./countclassesmatching.cf
cf-agent -If ./countclassesmatching.cf
R: Found 1 classes matching

And their output can be compared with the example_output section.

awk '/.*begin_src example_output/ {p=1}; p; /.*end_src/ {p=0}' ./countclassesmatching.cf
#+begin_src example_output
#@ ```
#@ R: Found 1 classes matching
#@ ```
#+end_src

**Note:** Output inside of the example_output must be stable across runs of the agent in order to work for testing. If including an example that has unstable output from inside of the documentation repository consider adding a static section to show in the documentation and a section showing an example of the expected output. For example see the =randomint.cf= example, and the =randomint()= in the reference manual.

Running the examples:

cd ..
find . -name "*.cf*" | xargs chmod 600
tests/acceptance/testall --jobs=4\
          --printlog\
          --baseclasses=AUTO\
          --extraclasses=DEBUG\
          --bindir=/var/cfengine/bin\
          tests/acceptance/04_examples/outputs/check_outputs.cf
======================================================================
Testsuite started at 2018-04-14 00:12:10
----------------------------------------------------------------------
Total tests: 1

        COMMON_TESTS: enabled
         TIMED_TESTS: enabled
          SLOW_TESTS: enabled
     ERROREXIT_TESTS: enabled
        SERIAL_TESTS: enabled
       NETWORK_TESTS: enabled
       LIBXML2_TESTS: enabled
       LIBCURL_TESTS: enabled
        UNSAFE_TESTS: disabled
       STAGING_TESTS: disabled

Test run is PARALLEL with MAKEFLAGS= --jobs=4

./tests/acceptance/04_examples/outputs/check_outputs.cf Pass

======================================================================
Testsuite finished at 2018-04-14 00:12:11 (1 seconds)

Passed tests:  1
Failed tests:  0
Skipped tests: 0
Soft failures: 0
Total tests:   1
======================================================================
Testsuite started at 2018-04-14 00:12:10
----------------------------------------------------------------------
Total tests: 1

        COMMON_TESTS: enabled
         TIMED_TESTS: enabled
          SLOW_TESTS: enabled
     ERROREXIT_TESTS: enabled
        SERIAL_TESTS: enabled
       NETWORK_TESTS: enabled
       LIBXML2_TESTS: enabled
       LIBCURL_TESTS: enabled
        UNSAFE_TESTS: disabled
       STAGING_TESTS: disabled

Test run is PARALLEL with MAKEFLAGS= --jobs=4

----------------------------------------------------------------------
./tests/acceptance/04_examples/outputs/check_outputs.cf 
----------------------------------------------------------------------
R: /home/nickanderson/Northern.Tech/CFEngine/core/./tests/acceptance/04_examples/outputs/check_outputs.cf Pass

Return code is 0.

  ==> Pass


======================================================================
Testsuite finished at 2018-04-14 00:12:11 (1 seconds)

Passed tests:  1
Failed tests:  0
Skipped tests: 0
Soft failures: 0
Total tests:   1