chef-infratest-kitchenohai-gem

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. On a regular node, I've done it by adding:

ohai.optional_plugins = [
      :Passwd
]

to /etc/chef/client.rb.

I wanted to achieve the same in a test node, so I added to 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).

How can I enable Ohai plugin on a test kitchen node?


Solution

  • 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. 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. 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

    not sure if that's very helpful but I think that fact might be pertinent