0

CFEngine 很棒,但我不知道如何将策略服务器上定义的模板复制到相关主机。

例如,我正在寻找部署一个 nginx.conf,我在我的主服务器上制定了一个策略:

bundle agent loadbalancers{

 files:
  ubuntu::
   "/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,
        }
    ');
}

但不知不觉中,CFEngine 在所有其他客户端上都找不到 /tmp/nginx.conf.template ......

看起来模板没有从服务器复制到客户端,我错过了什么?我想我想念什么……

文档没有解释如何传播模板文件,所以我希望你能帮助我,谢谢!

4

1 回答 1

1

我很高兴你喜欢 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,
       }
    ');

}

将模板作为主要策略集的一部分发送到所有主机并不总是合适的,这实际上取决于您的环境需求。

于 2018-11-05T01:17:30.500 回答