Movatterモバイル変換


[0]ホーム

URL:


CFEngine documentation homepage

File template examples

Suggest changes
Table of contents

Templating

With CFEngine you have a choice between editingdeltas into files or distributing more-or-less finished templates. Which method you should choose depends should be made by whatever is easiest.

code
If you are managing only part of the file, and something else (e.g. a package manager) is managing most of it, then it makes sense to use CFEngine file editing.If you are managing everything in the file, then it makes sense to make the edits by hand and install them using CFEngine. You can use variables within source text files and let CFEngine expand them locally in situ, so that you can make generic templates that apply netwide.

Example template:

code
MYVARIABLE=somethingorotherHOSTNAME=$(sys.host)# CFEngine fills this in

To copy and expand this template, you can use a pattern like this:

code
bundleagentget_template(final_destination,mode){vars:# This needs to ne preconfigured to your site"masterfiles"string=>"/home/mark/tmp";"this_template"string=>lastnode("$(final_destination)","/");files:"$(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)"),action=>if_elapsed("60");"$(final_destination)"comment=>"Expand the template",create=>"true",edit_line=>expand_template("$(final_destination).staging"),edit_defaults=>empty,perms=>mo("$(mode)","root"),action=>if_elapsed("60");}

The the following driving code (based oncopy then edit) can be placed in a library, after configuring to your environmental locations:

code
bundleagentget_template(final_destination,mode){vars:# This needs to ne preconfigured to your site"masterfiles"string=>"/home/mark/tmp";"this_template"string=>lastnode("$(final_destination)","/");files:"$(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)"),action=>if_elapsed("60");"$(final_destination)"comment=>"Expand the template",create=>"true",edit_line=>expand_template("$(final_destination).staging"),edit_defaults=>empty,perms=>mo("$(mode)","root"),action=>if_elapsed("60");}

Still need help?

Chat Ask a question on Github Mailing list
Version 
master3.24 (LTS)3.21 (LTS)view all versions

[8]ページ先頭

©2009-2025 Movatter.jp