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


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

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

On Thu, Jun 6, 2013 at 4:48 PM, Yonah Russ < " target="_blank"> > wrote:
Here is the resource:

bash "install_newrelic" do
  not_if {!Dir.glob('/etc/newrelic').empty?}
  user "root"
  cwd "/opt/local"
  code <<-EOH
    /usr/bin/wget -r -nH --cut-dirs=5 -np -A 'newrelic-php5-*-solaris.tar.gz' http://download.newrelic.com/php_agent/release/
    /opt/local/bin/tar -xvzf newrelic-php5-*-solaris.tar.gz
    /opt/local/bin/rm newrelic-php5-*-solaris.tar.gz
    /opt/local/bin/chown -R root:root newrelic-php5-*
    (cd newrelic-php5-*; NR_INSTALL_SILENT=true NR_INSTALL_KEY=#{node['webconfig']['newrelic']['key']} ./newrelic-install install)
  EOH
  notifies :restart, resources(:service => "php54-fpm")
end

We tried chef 11 and, unfortunately, so much broke that it just isn't an option for us.
It would set us back weeks to rewrite, test and redeploy everything :(

Thanks
Yonah

On Thu, Jun 6, 2013 at 4:36 PM, Steven Danna < " target="_blank"> > wrote:
Hi,

On 6/5/13 5:25 AM, Yonah Russ wrote:

> When a recipe tries to use one of the role attributes inside the code, I
> get an error:
> /tmp/chef-script20130605-45783-1h9fd78: line 6:
> Chef::Node::Attribute:0x0000000628e1b8: No such file or directory

Could you post the bash resource that is causing this problem?

>
> Is this a known issue?
> Am I doing something wrong?

Errors such as this is one of the reasons that Dan reworked much of the
attribute code for Chef 11 [0].  The typical solution is to coerce the
attribute into a well-known type using #to_s, #to_hash, or similar
methods which are easier to use elsewhere.

Cheers,

Steven


--
Steven Danna
Systems Engineer, Opscode, Inc
GPG Key: http://stevendanna.github.com/downloads/code/public.key

[0]
http://www.opscode.com/blog/2013/02/05/chef-11-in-depth-attributes-changes/






Archive powered by MHonArc 2.6.16.

§