2015-03-25 92 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