[chef] LWRP: How to set attribute default to another attribute


Chronological Thread 
  • From: Todd Michael Bushnell < >
  • To:
  • Subject: [chef] LWRP: How to set attribute default to another attribute
  • Date: Sun, 21 Apr 2013 23:19:47 -0700

Ohai Chefs,

Finally settled in today and wrote my first LWRP.  Lamenting not getting off my arse and doing this earlier as it's pretty simple and super powerful!  Anyway, running into minor issue and could use some guidance.  Within my resource I tried and failed at setting defaults of some attributes to another attribute in resources.rb, like so:

# resources/instance.rb
actions :create, :delete

attribute :instance_name, :name_attribute => true, :kind_of => String, :required => true
attribute :project_name,  :kind_of => String, :required => true
attribute :webdav_host,   :kind_of => String, :required => true
attribute :webdav_path,   :kind_of => String, :default =>  "/files/ "
attribute :db_host,       :kind_of => String, :required => true
attribute :db_name,       :kind_of => String, :default => @project_name
...

I wasn't able to figure out how to "get to" @project_name from within resources.rb so I could set it as a default for some other attributes.  I tried a number of different ways and all gave me nil.  Is this possible and/or advisable?  Curious how the cool kids handle this one.  Thanks much.


::toddmichael



Archive powered by MHonArc 2.6.16.

§