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


Chronological Thread 
  • From: Yonah Russ < >
  • To:
  • Subject: [chef] Re: Re: Re: Re: Using Role attributes inside bash resource
  • Date: Mon, 17 Jun 2013 19:52:57 +0300

The attributes json I'm using is approximately as follows:

{
"apache_net":"blah",
        "internal_net":"blah",
        "code_branch":"master",
        "circonus_broker":"blah",
        "datacenter":"blah",
"run_list": [ "role[ed-mobile]" ]
}

There is nothing there but a couple node specific attributes and a run list which is the role.
If I modify to this, everything works:
{
"apache_net":"blah",
        "internal_net":"blah",
        "code_branch":"master",
        "circonus_broker":"blah",
        "datacenter":"blah",
        "webconfig":{
            "newrelic": {
                "key" : "xxxxxxxxxxxxxxxxxxxxxxxxxxxx",
                "appname" : "WWW"
            }
        },
"run_list": [ "role[ed-mobile]" ]
}

If you think it will help trace the problem, I'll try throwing something non-existent into the role but it seems to me the role is pretty much working.

Thanks,
Yonah

On Mon, Jun 17, 2013 at 7:20 PM, Daniel DeLeo < " target="_blank"> > wrote:

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.

§