Create files and directories and set permissions.
[%CFEngine_include_snippet(create_files_and_directories.cf, .* )%]
Copy single files, locally (local_cp) or from a remote site (secure_cp). The Community Open Promise-Body Library (COPBL; cfengine_stdlib.cf) should be included in the /var/cfengine/inputs/ directory and input as below.
[%CFEngine_include_snippet(copy_single_files.cf, .* )%]
Copy directory trees, locally (local_cp) or from a remote site (secure_cp). (depth_search => recurse(ββ)) defines the number of sublevels to include, (βinfβ) gets entire tree.
[%CFEngine_include_snippet(copy_directory_trees.cf, .* )%]
Use the following simple steps to disable and rotate files. See the Community Open Promise-Body Library if you wish more details on what disable and rotate does.
[%CFEngine_include_snippet(disabling_and_rotating_files.cf, .* )%]
There are numerous approaches to adding lines to a file. Often the order of a configuration file is unimportant, we just need to ensure settings within it. A simple way of adding lines is show below.
[%CFEngine_include_snippet(add_lines_to_a_file.cf, .* )%]
Also you could write this using a list variable:
[%CFEngine_include_snippet(add_lines_to_a_file_1.cf, .* )%]
[%CFEngine_include_snippet(check_file_or_directory_permissions.cf, .* )%]
[%CFEngine_include_snippet(commenting_lines_in_a_file.cf, .* )%]
[%CFEngine_include_snippet(copy_files.cf, .* )%]
[%CFEngine_include_snippet(copy_and_flatten_directory.cf, .* )%]
To convergently chain a copy followed by edit, you need a staging file. First you copy to the staging file. Then you edit the final file and insert the staging file into it as part of the editing. This is convergent with respect to both stages of the process.
[%CFEngine_include_snippet(copy_then_edit_a_file_convergently.cf, .* )%]
[%CFEngine_include_snippet(deleting_lines_from_a_file.cf, .* )%]
[%CFEngine_include_snippet(deleting_lines_exception.cf, .* )%]
The [rm_rf][lib/bundles.cf#rm_rf] and [rm_rf_depth][lib/bundles.cf#rm_rf_depth] bundles in the standard library make it easy to prune directory trees.
This is a huge topic. See also See Add lines to a file, See Editing tabular files, etc. Editing a file can be complex or simple, depending on needs.
Here is an example of how to comment out lines matching a number of patterns:
[%CFEngine_include_snippet(editing_files.cf, .* )%]
[%CFEngine_include_snippet(editing_tabular_files.cf, .* )%]
[%CFEngine_include_snippet(inserting_lines_in_a_file.cf, .* )%]
[%CFEngine_include_snippet(back_references_in_filenames.cf, .* )%]
[%CFEngine_include_snippet(add_variable_definitions_to_a_file.cf, .* )%]
Results in:
An example of this would be to add variables to /etc/sysctl.conf on Linux:
[%CFEngine_include_snippet(add_variable_definitions_to_a_file_1.cf, .* )%]
[%CFEngine_include_snippet(linking_files.cf, .* )%]
[%CFEngine_include_snippet(listing_files-pattern_in_a_directory.cf, .* )%]
[%CFEngine_include_snippet(locate_and_transform_files.cf, .* )%]
[%CFEngine_include_snippet(bsd_flags.cf, .* )%]
[%CFEngine_include_snippet(search_and_replace_text.cf, .* )%]
[%CFEngine_include_snippet(selecting_a_region_in_a_file.cf, .* )%]
[%CFEngine_include_snippet(warn_if_matching_line_in_file.cf, .* )%]