Learner
Learner

Reputation: 162

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?

Upvotes: 2

Views: 781

Answers (3)

TrinitronX
TrinitronX

Reputation: 5223

I was able to get this working in recent Chef version 18.0.6 with the following in .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:

ohai.optional_plugins =  [:Passwd]

Upvotes: 1

deef
deef

Reputation: 26

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

Upvotes: 1

Draco Ater
Draco Ater

Reputation: 21226

Try

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

Upvotes: 1

Related Questions