0

In my chef cookbook's attributes/default.rb I have the following:

default['dt'] = ActiveSupport::TimeZone.new('America/Chicago').local_to_utc(Time.now)

In my recipe/default.rb I have

chef_gem 'active_support/time'

Which if I understood correctly, would work same as a

gem install 'active_support/time'
require 'active_support/time'

But upon running the cookbook I get

NameError
---------
uninitialized constant Class::TZInfo

How do I resolve the NameError?

Sam Hammamy
  • 10,819
  • 10
  • 56
  • 94

1 Answers1

0

all attribute files are evaluated prior to any recipe files being evaluated. Therefore, when your recipe code runs, the gem has not yet been installed. Even if it had been, it would not be included in your attributes file, and therefore would not be available there. As for how to fix it, that's a tough one. I'd suggest you move the attribute setting code out of the attributes file and into the recipe. Generally I frown on that, but sometimes it is unavoidable.

Tejay Cardon
  • 4,193
  • 2
  • 16
  • 31