简体   繁体   English

如何在测试厨房的节点上启用特定的 Ohai 插件

[英]How to enable specific Ohai plugin on a node in Test Kitchen

I wanted to enable Passwd ohai plugin in my node in test kitchen.我想在测试厨房的节点中启用 Passwd ohai 插件。 On a regular node, I've done it by adding:在常规节点上,我通过添加:

ohai.optional_plugins = [
      :Passwd
]

to /etc/chef/client.rb ./etc/chef/client.rb

I wanted to achieve the same in a test node, so I added to my.kitchen.yml:我想在测试节点中实现同样的效果,所以我在 my.kitchen.yml 中添加了:

provisioner:
  name: chef_zero
  client_rb:
    Ohai::Config[:optional_plugins] =
      - passwd

But when I converge the node, the plugin is not enabled.但是当我收敛节点时,插件没有启用。 On a test node, in /home/vagrant/.chef/client.rb there is no entry about ohai optional plugins and templates that I am using during converge, can not see node['etc']['group']['SOME_USERNAME']['gid'] attribute (even after second converge, because Ohai have to run first time and then save attributes).在测试节点上,在/home/vagrant/.chef/client.rb中没有关于我在收敛期间使用的 ohai 可选插件和模板的条目,看不到node['etc']['group']['SOME_USERNAME']['gid']属性(即使在第二次收敛后,因为 Ohai 必须第一次运行然后保存属性)。

How can I enable Ohai plugin on a test kitchen node?如何在测试厨房节点上启用 Ohai 插件?

Try尝试

client_rb:
    ohai.optional_plugins: [':Passwd']

I don't have an exact answer to your question, but one thing to know is that when running test kitchen, any references to the node object in a recipe under test won't have the actual node object from one run to the next, since it's not being saved back to any chef server.我对您的问题没有确切的答案,但要知道的一件事是,在运行测试厨房时,在被测配方中对节点 object 的任何引用都不会有实际的节点 object 从一次运行到下一次运行,因为它没有被保存回任何厨师服务器。 It's kind of a 'clean slate' for each run.每次运行都是一种“干净的石板”。 You can save the node object to a local file on one run then access it again later, but really can't get changing ohai data from within test kitchen easily in the cookbook as far as I know.您可以在一次运行时将节点 object 保存到本地文件,然后稍后再次访问它,但据我所知,实际上无法在食谱中轻松地从测试厨房中更改 ohai 数据。 You can do something like this to save it and get it in a test:您可以执行以下操作来保存它并在测试中获取它:

http://www.hurryupandwait.io/blog/accessing-chef-node-attributes-from-kitchen-tests http://www.hurryupandwait.io/blog/accessing-chef-node-attributes-from-kitchen-tests

not sure if that's very helpful but I think that fact might be pertinent不确定这是否很有帮助,但我认为这个事实可能是相关的

I was able to get this working in recent Chef version 18.0.6 with the following in .kitchen.yml :我能够在最近的 Chef 版本18.0.6中使用.kitchen.yml中的以下内容来实现此功能:

provisioner:
  name: chef_zero
  client_rb:
    'ohai.optional_plugins = ':
        - :Passwd

Including the = equals sign in the hash key as a quoted string ( 'foo =': bar ) forces test-kitchen to template the client.rb correctly:在 hash 键中包含=等号作为带引号的字符串 ( 'foo =': bar ) 会强制test-kitchen正确模板化client.rb

ohai.optional_plugins =  [:Passwd]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM