recipe_name converted to empty list


#1

when I run the following recipe I get this output:

==> zs1: [2014-12-09T19:35:15+00:00] ERROR: hey john
==> zs1: [2014-12-09T19:35:15+00:00] ERROR: hey []

why is recipe_name altered inside the logrotate_app block? The
resulting config files
have [] in the place where I would expect the recipe name.

—recipe—
Chef::Log.error(“hey #{recipe_name}”)
logrotate_app recipe_name do
Chef::Log.error(“hey #{recipe_name}”)
cookbook 'logrotate’
path %W|/var/log/careverge/#{recipe_name}.console
/var/log/careverge/#{recipe_name}.json|
frequency 'daily’
rotate 2
size '100M’
options %w|copytruncate compress nodelaycompress missingok|
end


#2

On Tue, Dec 9, 2014 at 2:37 PM, John de la Garza
john.garza@rallyhealth.com wrote:

when I run the following recipe I get this output:

==> zs1: [2014-12-09T19:35:15+00:00] ERROR: hey john
==> zs1: [2014-12-09T19:35:15+00:00] ERROR: hey []

why is recipe_name altered inside the logrotate_app block? The
resulting config files
have [] in the place where I would expect the recipe name.

—recipe—
Chef::Log.error(“hey #{recipe_name}”)
logrotate_app recipe_name do
Chef::Log.error(“hey #{recipe_name}”)
cookbook 'logrotate’
path %W|/var/log/careverge/#{recipe_name}.console
/var/log/careverge/#{recipe_name}.json|
frequency 'daily’
rotate 2
size '100M’
options %w|copytruncate compress nodelaycompress missingok|
end

ok, I think I understand why I get this behavior

logrotate_app is a definition so it gets handled before recipe_name is available

can someone confirm if my understanding is correct


#3

On Dec 9, 2014, at 12:04 PM, John de la Garza john.garza@rallyhealth.com wrote:

On Tue, Dec 9, 2014 at 2:37 PM, John de la Garza
john.garza@rallyhealth.com wrote:

when I run the following recipe I get this output:

==> zs1: [2014-12-09T19:35:15+00:00] ERROR: hey john
==> zs1: [2014-12-09T19:35:15+00:00] ERROR: hey []

why is recipe_name altered inside the logrotate_app block? The
resulting config files
have [] in the place where I would expect the recipe name.

—recipe—
Chef::Log.error(“hey #{recipe_name}”)
logrotate_app recipe_name do
Chef::Log.error(“hey #{recipe_name}”)
cookbook 'logrotate’
path %W|/var/log/careverge/#{recipe_name}.console
/var/log/careverge/#{recipe_name}.json|
frequency 'daily’
rotate 2
size '100M’
options %w|copytruncate compress nodelaycompress missingok|
end

ok, I think I understand why I get this behavior

logrotate_app is a definition so it gets handled before recipe_name is available

can someone confirm if my understanding is correct

No, the issue is that the block for definitions are evaluated in a weird context. Just assign the value to a variable outside the block so it can be a normal closure instead

r = recipe_name
logrotate_app do

path "/foo/#{r}"
end

Alternatively stop using definitions because they are eeeeevil :slight_smile:

–Noah


#4

For what it’s worth, while definitions might be evil, I found the same thing happening on an LWRP after the chef 12 release; I don’t think this is isolated to definitions, if it’s the same issue:

  • Martin

From: Noah Kantrowitz [noah@coderanger.net]
Sent: Tuesday, December 09, 2014 2:13 PM
To: chef@lists.opscode.com
Subject: [chef] Re: Re: recipe_name converted to empty list

On Dec 9, 2014, at 12:04 PM, John de la Garza john.garza@rallyhealth.com wrote:

On Tue, Dec 9, 2014 at 2:37 PM, John de la Garza
john.garza@rallyhealth.com wrote:

when I run the following recipe I get this output:

==> zs1: [2014-12-09T19:35:15+00:00] ERROR: hey john
==> zs1: [2014-12-09T19:35:15+00:00] ERROR: hey []

why is recipe_name altered inside the logrotate_app block? The
resulting config files
have [] in the place where I would expect the recipe name.

—recipe—
Chef::Log.error(“hey #{recipe_name}”)
logrotate_app recipe_name do
Chef::Log.error(“hey #{recipe_name}”)
cookbook 'logrotate’
path %W|/var/log/careverge/#{recipe_name}.console
/var/log/careverge/#{recipe_name}.json|
frequency 'daily’
rotate 2
size '100M’
options %w|copytruncate compress nodelaycompress missingok|
end

ok, I think I understand why I get this behavior

logrotate_app is a definition so it gets handled before recipe_name is available

can someone confirm if my understanding is correct

No, the issue is that the block for definitions are evaluated in a weird context. Just assign the value to a variable outside the block so it can be a normal closure instead

r = recipe_name
logrotate_app do

path "/foo/#{r}"
end

Alternatively stop using definitions because they are eeeeevil :slight_smile:

–Noah