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