Using Role attributes inside bash resource

Hi,

I’m using chef-solo v10.26
I moved some attributes from the json attributes file into a role.

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

Other attributes which I’ve moved to the role seem to work fine so maybe
there is a specific issue with the bash resource which I don’t use very
often?

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

Thanks,
Yonah

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]

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 :frowning:

Thanks
Yonah

On Thu, Jun 6, 2013 at 4:36 PM, Steven Danna steve@opscode.com 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]
Chef 11 In-Depth: Attributes Changes - Chef Blog | Chef

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 opscode@yonahruss.com 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'
Index of /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 :frowning:

Thanks
Yonah

On Thu, Jun 6, 2013 at 4:36 PM, Steven Danna steve@opscode.com 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]

Chef 11 In-Depth: Attributes Changes - Chef Blog | Chef

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

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 dan@kallistec.com 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

On Monday, June 17, 2013 at 9:52 AM, Yonah Russ wrote:

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

It's worth a try. When you're debugging, something in the system is operating contrary to your mental model of how it operates. I find that trying to make something fail in a way you think it should is often a good way to narrow down what part of reality is conflicting with your model. In this case, careful evaluation of the debug logs could be just as helpful, YMMV.

--
Daniel DeLeo