【问题标题】:How can I capture chef-client log output to a file in a kitchen run?如何将 chef-client 日志输出捕获到厨房运行中的文件?
【发布时间】:2015-03-25 22:39:27
【问题描述】:

我正在尝试将 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"

如您所见,client.rb 中没有包含预期的log_location 条目,我猜这就是在指定路径中没有创建日志文件的原因。

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

目前使用的参考资料:

  1. client.rb参考:https://docs.chef.io/config_rb_client.html
  2. .kitchen.yml:https://docs.chef.io/config_yml_kitchen.html#chef-client-specific-settings 中的厨师客户特定设置

【问题讨论】:

  • 您的运行列表中是否包含 chef_client 食谱? IIRC 提到的属性供chef_client::config 配方使用。 (我可能错了,因为我没有使用测试厨房)
  • @Tensibai 我的运行列表中不包括chef_client::config,因为供应商(chef_zero)自带。我试图为其配置日志记录的是嵌入在配置器中的厨师客户端。

标签: chef-infra test-kitchen


【解决方案1】:

根据chef-zero provisionner doc阅读provisioner code

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

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

【讨论】:

  • 在provisioner下添加log_file属性对我有用,谢谢!
猜你喜欢
  • 1970-01-01
  • 2016-12-23
  • 2020-02-28
  • 2023-03-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-10-21
  • 1970-01-01
相关资源
最近更新 更多