[chef] Re: Re: Re: Using Role attributes inside bash resource


Chronological Thread 
  • From: Daniel DeLeo < >
  • To:
  • Subject: [chef] Re: Re: Re: Using Role attributes inside bash resource
  • Date: Mon, 17 Jun 2013 09:20:12 -0700


On Sunday, June 16, 2013 at 9:22 PM, Yonah Russ wrote:

Hi,

I'm having similar issues in another context.

I have a role defined (approximately) as follows:
{
  "name":"ed-mobile",
  "chef_type":"role",
  "json_class": "Chef::Role",
  "default_attributes": {
    "webconfig":{
        "server_path":"/opt/local/www/",
        "newrelic": {
            "key" : "xxxxxxxxxxxxxxxxxxxxxxxxxxxx",
            "appname" : "WWW"
        }
    }
  },
  "description": "Static Mobile Sites or Applications",
  "run_list": [
                ....
  ]
}

In my default recipe I have this resource:

template "/opt/local/etc/nrsysmond.cfg" do
  source "nrsysmond.cfg.erb"
  owner "root"
  group "root"
  mode "0644"
  notifies :restart, resources(:service => "nrsysmond")
end

The template tries to use the role attribute as follows:
license_key=<%= node['webconfig']['newrelic']['key'] %>

I get the following error:

on line #16
 14: # Default: none
 15: #
 16: license_key=<%= node['webconfig']['newrelic']['key'] %>
 17:
 18: #

[2013-06-16T16:02:00+00:00] ERROR: Running exception handlers
[2013-06-16T16:02:00+00:00] ERROR: Exception handlers complete
[2013-06-16T16:02:00+00:00] FATAL: Stacktrace dumped to /etc/chef/chef-solo/chef-stacktrace.out
[2013-06-16T16:02:00+00:00] FATAL: Chef::Mixin::Template::TemplateError: undefined method `[]' for nil:NilClass

If I move
"webconfig":{
            "newrelic": {
                "key" : "xxxxxxxxxxxxxxxxxxxxxxxxxxxx",
                "appname" : "WWW"
            }
        },
into my json attributes file instead, everything works perfectly.

Any ideas?
Yonah

Are you sure the role is getting picked up by the expanded run list? For example, if you put a nonexistent recipe in that role's run list, does it fail the way you'd expect it to?

-- 
Daniel DeLeo




Archive powered by MHonArc 2.6.16.

§