我很高兴你喜欢 CFEngine。如果您希望一个文件成为另一个文件的副本,您可以使用 copy_from 正文来指定它的来源。
例如:
bundle agent loadbalancers{
files:
ubuntu::
"/tmp/nginx.conf.template"
comment => "We want to be sure and have an up to date template",
copy_from => remote_dcp( "/var/cfengine/masterfiles/templates/nginx.conf.mustache",
$(sys.policy_hub));
"/etc/nginx/nginx.conf"
create => "true",
edit_template => "/tmp/nginx.conf.template",
template_method => "mustache",
template_data => parsejson('
{
"worker_processes": "auto",
"worker_rlimit_nofile": 32768,
"worker_connections": 16384,
}
');
}
有些人安排将他们的模板作为其正常策略更新的一部分进行复制,那么仅引用与您的策略文件相关的模板非常方便。
例如,假设您的策略在 中
services/my_nginx_app/policy/loadbalancers.cf,而您的模板在
services/my_nginx_app/templates/nginx.conf.mustache. 然后,如果该模板作为正常策略更新的一部分进行更新,则您不必承诺单独的文件副本,而只需引用与策略文件相关的模板的路径。
bundle agent loadbalancers{
files:
ubuntu::
"/etc/nginx/nginx.conf"
create => "true",
edit_template => "$(this.promise_dirname)/../templates/nginx.conf.mustache",
template_method => "mustache",
template_data => parsejson('
{
"worker_processes": "auto",
"worker_rlimit_nofile": 32768,
"worker_connections": 16384,
}
');
}
将模板作为主要策略集的一部分发送到所有主机并不总是合适的,这实际上取决于您的环境需求。