Chef-apply and node attribute


#1

Hi everyone,

Does anyone knows how to use attribute with the use of chef-apply ?
I have the following structure:
generator/metadata.rb
generator/attributes/default.rb
generator/templates/default/test.erb
generator/recipes/default.rb

cat generator/attributes/default.rb
default[‘generator’][‘test’] = 'test’
cat generator/recipe/default.rb
puts node[‘generator’][‘test’]

Of course by running in another directory:
/tmp/generator $ chef-apply recipes/default.rb -l debug
[2015-02-04T01:10:47+01:00] DEBUG: Building node object for XXXXXXXX
[2015-02-04T01:10:47+01:00] DEBUG: Extracting run list from JSON attributes provided on command line
[2015-02-04T01:10:47+01:00] DEBUG: Applying attributes from json file
[2015-02-04T01:10:47+01:00] DEBUG: Platform is debian version 8.0
[2015-02-04T01:10:47+01:00] INFO: Run List is []
[2015-02-04T01:10:47+01:00] INFO: Run List expands to []
[2015-02-04T01:10:47+01:00] INFO: Unable to access cache at /var/chef. Switching cache to /home/jmauro/.chef
[2015-02-04T01:10:47+01:00] INFO: Unable to access cache at /var/chef. Switching cache to /home/jmauro/.chef
[2015-02-04T01:10:47+01:00] FATAL: Stacktrace dumped to /home/jmauro/.chef/cache/chef-stacktrace.out
[2015-02-04T01:10:47+01:00] DEBUG: NoMethodError: undefined method []' for nil:NilClass recipes/default.rb:20:inrun_chef_recipe’
/home/jmauro/.gem/ruby/2.1.0/gems/chef-11.18.0/lib/chef/application/apply.rb:141:in instance_eval' /home/jmauro/.gem/ruby/2.1.0/gems/chef-11.18.0/lib/chef/application/apply.rb:141:inrun_chef_recipe’
/home/jmauro/.gem/ruby/2.1.0/gems/chef-11.18.0/lib/chef/application/apply.rb:153:in run_application' /home/jmauro/.gem/ruby/2.1.0/gems/chef-11.18.0/lib/chef/application/apply.rb:166:inrun’
/home/jmauro/.gem/ruby/2.1.0/gems/chef-11.18.0/bin/chef-apply:25:in <top (required)>' /home/jmauro/.gem/ruby/2.1.0/bin/chef-apply:23:inload’
/home/jmauro/.gem/ruby/2.1.0/bin/chef-apply:23:in <main>' [2015-02-04T01:10:47+01:00] FATAL: NoMethodError: undefined method[]’ for nil:NilClass

Is there a way to use attribute or this is simply an anti-pattern?


#2

I think chef apply is meant to work on a single recipe file. You may be
able to specify -j for --json-attribs like chef-solo/client, but I am not
sure. It looks like you could make use of chef client in zero mode, or
solo, to get the Cookbook-style behavior with attributes you are looking
for.

cheers,

–aj

On Wed, Feb 4, 2015 at 1:12 PM, Jeremy Mauro j.mauro@criteo.com wrote:

Hi everyone,

Does anyone knows how to use attribute with the use of chef-apply ?

I have the following structure:

generator/metadata.rb

generator/attributes/default.rb

generator/templates/default/test.erb

generator/recipes/default.rb

cat generator/attributes/default.rb

default[‘generator’][’test’] = ’test’

cat generator/recipe/default.rb

puts node[‘generator’][’test’]

Of course by running in another directory:

/tmp/generator $ chef-apply recipes/default.rb -l debug

[2015-02-04T01:10:47+01:00] DEBUG: Building node object for XXXXXXXX

[2015-02-04T01:10:47+01:00] DEBUG: Extracting run list from JSON
attributes provided on command line

[2015-02-04T01:10:47+01:00] DEBUG: Applying attributes from json file

[2015-02-04T01:10:47+01:00] DEBUG: Platform is debian version 8.0

[2015-02-04T01:10:47+01:00] INFO: Run List is []

[2015-02-04T01:10:47+01:00] INFO: Run List expands to []

[2015-02-04T01:10:47+01:00] INFO: Unable to access cache at /var/chef.
Switching cache to /home/jmauro/.chef

[2015-02-04T01:10:47+01:00] INFO: Unable to access cache at /var/chef.
Switching cache to /home/jmauro/.chef

[2015-02-04T01:10:47+01:00] FATAL: Stacktrace dumped to
/home/jmauro/.chef/cache/chef-stacktrace.out

[2015-02-04T01:10:47+01:00] DEBUG: NoMethodError: undefined method `[]'
for nil:NilClass

recipes/default.rb:20:in `run_chef_recipe’

/home/jmauro/.gem/ruby/2.1.0/gems/chef-11.18.0/lib/chef/application/apply.rb:141:in
`instance_eval’

/home/jmauro/.gem/ruby/2.1.0/gems/chef-11.18.0/lib/chef/application/apply.rb:141:in
`run_chef_recipe’

/home/jmauro/.gem/ruby/2.1.0/gems/chef-11.18.0/lib/chef/application/apply.rb:153:in
`run_application’

/home/jmauro/.gem/ruby/2.1.0/gems/chef-11.18.0/lib/chef/application/apply.rb:166:in
`run’

/home/jmauro/.gem/ruby/2.1.0/gems/chef-11.18.0/bin/chef-apply:25:in `<top
(required)>’

/home/jmauro/.gem/ruby/2.1.0/bin/chef-apply:23:in `load’

/home/jmauro/.gem/ruby/2.1.0/bin/chef-apply:23:in `’

[2015-02-04T01:10:47+01:00] FATAL: NoMethodError: undefined method `[]'
for nil:NilClass

Is there a way to use attribute or this is simply an anti-pattern?


#3

yup, you cant use attribute files in chef-apply, use chef-client in
localmode with -o (similar to solo) , or just read some external config
file (json or yaml)

On Tue, Feb 3, 2015 at 4:16 PM, AJ Christensen aj@junglistheavy.industries
wrote:

I think chef apply is meant to work on a single recipe file. You may be
able to specify -j for --json-attribs like chef-solo/client, but I am not
sure. It looks like you could make use of chef client in zero mode, or
solo, to get the Cookbook-style behavior with attributes you are looking
for.

cheers,

–aj

On Wed, Feb 4, 2015 at 1:12 PM, Jeremy Mauro j.mauro@criteo.com wrote:

Hi everyone,

Does anyone knows how to use attribute with the use of chef-apply ?

I have the following structure:

generator/metadata.rb

generator/attributes/default.rb

generator/templates/default/test.erb

generator/recipes/default.rb

cat generator/attributes/default.rb

default[‘generator’][’test’] = ’test’

cat generator/recipe/default.rb

puts node[‘generator’][’test’]

Of course by running in another directory:

/tmp/generator $ chef-apply recipes/default.rb -l debug

[2015-02-04T01:10:47+01:00] DEBUG: Building node object for XXXXXXXX

[2015-02-04T01:10:47+01:00] DEBUG: Extracting run list from JSON
attributes provided on command line

[2015-02-04T01:10:47+01:00] DEBUG: Applying attributes from json file

[2015-02-04T01:10:47+01:00] DEBUG: Platform is debian version 8.0

[2015-02-04T01:10:47+01:00] INFO: Run List is []

[2015-02-04T01:10:47+01:00] INFO: Run List expands to []

[2015-02-04T01:10:47+01:00] INFO: Unable to access cache at /var/chef.
Switching cache to /home/jmauro/.chef

[2015-02-04T01:10:47+01:00] INFO: Unable to access cache at /var/chef.
Switching cache to /home/jmauro/.chef

[2015-02-04T01:10:47+01:00] FATAL: Stacktrace dumped to
/home/jmauro/.chef/cache/chef-stacktrace.out

[2015-02-04T01:10:47+01:00] DEBUG: NoMethodError: undefined method `[]'
for nil:NilClass

recipes/default.rb:20:in `run_chef_recipe’

/home/jmauro/.gem/ruby/2.1.0/gems/chef-11.18.0/lib/chef/application/apply.rb:141:in
`instance_eval’

/home/jmauro/.gem/ruby/2.1.0/gems/chef-11.18.0/lib/chef/application/apply.rb:141:in
`run_chef_recipe’

/home/jmauro/.gem/ruby/2.1.0/gems/chef-11.18.0/lib/chef/application/apply.rb:153:in
`run_application’

/home/jmauro/.gem/ruby/2.1.0/gems/chef-11.18.0/lib/chef/application/apply.rb:166:in
`run’

/home/jmauro/.gem/ruby/2.1.0/gems/chef-11.18.0/bin/chef-apply:25:in `<top
(required)>’

/home/jmauro/.gem/ruby/2.1.0/bin/chef-apply:23:in `load’

/home/jmauro/.gem/ruby/2.1.0/bin/chef-apply:23:in `’

[2015-02-04T01:10:47+01:00] FATAL: NoMethodError: undefined method `[]'
for nil:NilClass

Is there a way to use attribute or this is simply an anti-pattern?