2015-03-25 90 views
2

我试图配置厨师客户端在测试厨房运行中将日志输出到文件,但我的配置在.kitchen.yml似乎没有反映在client.rb准备好并注入到测试节点中。如何在厨房运行中将厨师 - 客户端日志输出捕获到文件中?

我使用ChefDK 0.3.6,chef_zero provisioner和vagrant driver over virtualbox。

从我.kitchen.yml文件的摘录:

... 
provisioner: 
    name: chef_zero 
... 
- name: install-only 
    run_list: 
    - recipe[my_cookbook::test_recipe] 
    attributes: 
     chef_client: 
     config: 
      log_location: "/var/log/chef/chef-client.log" 
... 

另一种提取物,这从kitchen diagnose输出:

... 
provisioner: 
    attributes: 
    chef_client: 
     config: 
     log_location: "/var/log/chef/chef-client.log" 
    chef_client_path: "/opt/chef/bin/chef-client" 
    chef_omnibus_install_options: 
    chef_omnibus_root: "/opt/chef" 
... 

最后的/tmp/kitchen/client.rb测试节点上的内容:

[[email protected] log]# cat /tmp/kitchen/client.rb 
node_name "install-only-rhel65-x86-64" 
checksum_path "/tmp/kitchen/checksums" 
file_cache_path "/tmp/kitchen/cache" 
file_backup_path "/tmp/kitchen/backup" 
cookbook_path ["/tmp/kitchen/cookbooks", "/tmp/kitchen/site-cookbooks"] 
data_bag_path "/tmp/kitchen/data_bags" 
environment_path "/tmp/kitchen/environments" 
node_path "/tmp/kitchen/nodes" 
role_path "/tmp/kitchen/roles" 
client_path "/tmp/kitchen/clients" 
user_path "/tmp/kitchen/users" 
validation_key "/tmp/kitchen/validation.pem" 
client_key "/tmp/kitchen/client.pem" 
chef_server_url "http://127.0.0.1:8889" 
encrypted_data_bag_secret "/tmp/kitchen/encrypted_data_bag_secret" 

正如你所看到的,预期的log_location条目未被包含在client.rb中,我猜是没有在指定路径中创建日志文件的原因。

您能否帮我理解如何通过厨房中的厨师客户端正确启用日志记录到文件?

参考使用至今:

  1. client.rb参考:https://docs.chef.io/config_rb_client.html
  2. 厨师客户机专用设置在.kitchen.ymlhttps://docs.chef.io/config_yml_kitchen.html#chef-client-specific-settings
+0

你在运行列表中包含chef_client cookbook吗? IIRC提到的属性是由'chef_client :: config'配方使用的。 (我可能错了,因为我没有使用测试厨房) – Tensibai 2015-03-25 13:05:22

+0

@Tensibai作为提供者(chef_zero)自带的我没有在我的runlist中包含'chef_client :: config'。这是嵌入在配置程序中的厨师客户端,我正在尝试配置日志记录功能。 – 2015-03-25 14:23:02

回答

2

根据chef-zero provisionner doc和读取provisioner code

它不考虑att ributesand听起来很逻辑,因为它们是现实世界中的食谱所使用的属性。

什么可以做(我想从代码)被定义在供应者定义一个log_file沿chef_omnibus_url(以上置备代码的第42行):

你.kitche.yml将变成:

... 
provisioner: 
    name: chef_zero 
    log_file: "/var/log/chef/chef-client.log" 
... 
- name: install-only 
    run_list: 
    - recipe[my_cookbook::test_recipe] 
... 

... 
provisioner: 
    name: chef_zero 
... 
- name: install-only 
    run_list: 
    - recipe[chef-client::config] 
    - recipe[my_cookbook::test_recipe] 
attributes: 
    chef_client: 
    config: 
     log_location: "/var/log/chef/chef-client.log" 
... 

如果你使用chef_client食谱您节点上配置的厨师,我将其包括在运行列表匹配的CL尽可能的现实。

+0

在配置器下添加'log_file'属性对我有效,谢谢! – 2015-03-25 14:48:06