0

Using the following commands I am able to get chef-shell to execute, pulling in all of my cookbooks and data bags:

kitchen login
cd /tmp/kitchen
sudo -E /opt/chef/embedded/bin/chef-zero -d
sudo knife cookbook upload -a -c client.rb
sudo knife upload data_bags -c client.rb
sudo -E /opt/chef/bin/chef-shell -z -c client.rb -j dna.json -o "role-web-server::default"

However, I get the following exception:

Chef::Exceptions::InvalidDataBagItemID
--------------------------------------
Data Bag items must have an id matching /^[\.\-[:alnum:]_]+$/, you gave: nil

Cookbook Trace:
---------------
  /tmp/kitchen/cache/cookbooks/chef-vault/libraries/chef_vault_item.rb:44:in `chef_vault_item'

... other stacktrace...

The value nil is provided to the chef_vault_item function, when I have an appropriate value specified in my .kitchen.yml, and it's in the dna.json that I passed in to chef-shell. I know the value is there because my regular 'kitchen converge' finds the attribute just fine.

Why are the node attributes in the Test Kitchen generated dna.json not being included in my chef-shell execution? Am I going about it all wrong to get chef-shell to run inside of a Test Kitchen VM?

Michał Perłakowski
  • 88,409
  • 26
  • 156
  • 177

1 Answers1

0

The -z option for chef-shell doesn't automatically involve the chef zero/local-mode systems. It predates those by a bunch, -z is the short form of --client which just uses the config in the client.rb. You would need to modify that to point at Chef Zero.

Are you sure you mean to be using chef-shell? It sounds more like you mean to use chef-client there.

coderanger
  • 52,400
  • 4
  • 52
  • 75
  • Thank you for the quick response! I was hoping to use chef-shell to diagnose what was going on with some issues with a chef-client run of a role cookbook that depended on a number of cookbooks I'm working with. I also tried with -S http://localhost:8889 and it did not work. Am I barking up the wrong tree trying to use chef-shell? I just figured it would be a good tool to interactively observe what's going on in a converge... – Kaleb Walton Jan 23 '16 at 02:57
  • You could use it, but you need to reconfigure a bunch of stuff. Probably easier to just use logging output to trace the execution. – coderanger Jan 23 '16 at 04:26
  • I did finally work through my problem without it via debug level run. Before I mark this as answered, are you able to point to what you'd need to reconfigure in order to get it to include those attributes in the chef-shell run? – Kaleb Walton Jan 28 '16 at 12:33
  • Thanks for the time spent in the earlier response. Although it's not fully answered, your pointing to logging output led me to a solution so I'll mark it answered :) – Kaleb Walton Mar 03 '16 at 19:34