Set node attrs at compile-time from pure-ruby code in a recipe


#1

Does anyone have a quick example showing how to set a node attribute
from within (our) Ruby code that is executing during the compile phase?
Probably very simple to do, but I’m in uncharted territory here and not
a Ruby-as-primary-lang person.


#2

node.set[‘foo’][‘bar’] or node.default, all these outside the ruby_block
resource should be invoked during compile time

On Mon, Jul 22, 2013 at 1:00 PM, Jeff Blaine jblaine@kickflop.net wrote:

Does anyone have a quick example showing how to set a node attribute from
within (our) Ruby code that is executing during the compile phase? Probably
very simple to do, but I’m in uncharted territory here and not a
Ruby-as-primary-lang person.


#3

On 7/22/2013 4:06 PM, Ranjib Dey wrote:

node.set[‘foo’][‘bar’] or node.default, all these outside the
ruby_block resource should be invoked during compile time

Hmm, so ‘node’ is a global object that exists? I can just have arbitrary
non-DSL Ruby code in, for example, recipes/compiletest.rb and that can
call node.set?

On Mon, Jul 22, 2013 at 1:00 PM, Jeff Blaine <jblaine@kickflop.net
mailto:jblaine@kickflop.net> wrote:

Does anyone have a quick example showing how to set a node
attribute from within (our) Ruby code that is executing during the
compile phase? Probably very simple to do, but I'm in uncharted
territory here and not a Ruby-as-primary-lang person.

#4

In most cases (recipe, attribute files, lwrps) you have it via an accessor
method. Otherwise you can always invoke Chef::Node.load , but that’s low
level api. Note , in recipes node is a DSL mixin like search or data_bag
which you can always get via include Chef::DSL::Recipe/DataQuery etc
On Jul 22, 2013 1:38 PM, “Jeff Blaine” jblaine@kickflop.net wrote:

On 7/22/2013 4:06 PM, Ranjib Dey wrote:

node.set[‘foo’][‘bar’] or node.default, all these outside the
ruby_block resource should be invoked during compile time

Hmm, so ‘node’ is a global object that exists? I can just have arbitrary
non-DSL Ruby code in, for example, recipes/compiletest.rb and that can call
node.set?

On Mon, Jul 22, 2013 at 1:00 PM, Jeff Blaine <jblaine@kickflop.net<mailto:
jblaine@kickflop.net>> wrote:

Does anyone have a quick example showing how to set a node
attribute from within (our) Ruby code that is executing during the
compile phase? Probably very simple to do, but I'm in uncharted
territory here and not a Ruby-as-primary-lang person.