2

我正在尝试将 chef-client 配置为将日志输出到测试厨房运行中的文件,但我的配置.kitchen.yml似乎没有反映在client.rb准备好的和注入到测试节点中。

我在 virtualbox 上使用 ChefDK 0.3.6、chef_zero 配置器和 vagrant 驱动程序。

.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测试节点上的内容:

[root@TRSTWPRTSTAPV99 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,我猜这是在指定路径中未创建日志文件的原因。

您能否帮助我了解如何通过厨房的 chef-client 正确启用对文件的日志记录?

目前使用的参考文献:

  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
4

1 回答 1

2

根据厨师零供应商文档 并阅读供应商代码

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

可以做什么(我认为从代码中)是log_file在沿着 chef_omnibus_url 的供应商定义中定义 a (上面供应商代码的第 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 食谱在您的节点上配置厨师,我会将其包含在运行列表中以尽可能接近现实。

于 2015-03-25T14:39:27.070 回答