Is it possible to do this inside ruby_block?
krzkrzkrz opened this issue · 7 comments
I have the following in a recipe:
ruby_block "add LD_PRELOAD" do
block do
replace_or_add "LD_PRELOAD" do
path "/etc/environment"
pattern "LD_PRELOAD*"
line "LD_PRELOAD=/usr/lib/libjemalloc.so.2"
end
end
end
I end up with an error:
================================================================================
Error executing action `run` on resource 'ruby_block[add LD_PRELOAD]'
================================================================================
NoMethodError
-------------
undefined method `replace_or_add' for Chef::Resource::RubyBlock
@krzkrzkrz
Why do you want to put that resource in a ruby block? For myself anything complicated where I would think of using a ruby block would end up in a custom resource. If it's not complicated then there's no need for ruby block.
How do you mean by "end up in a custom resource"? Can I have an example
@krzkrzkrz a resource in Chef is one of the included resources e.g. file, in this context a custom resource is replace_or_add
Docs: https://docs.chef.io/custom_resources.html
hope that helps!
@krzkrzkrz
Why do you want to put that resource in a ruby block? I've never seen a resource used in a ruby block. I can imagine how you would do it, but can't see any reason for it.
For jemalloc to be configured with Ruby. The environment variable LD_PRELOAD
needs to be set in ruby_block
. It is needed for MRI to determine which additional libraries it needs to preload. And this can only happen if it is set during chef-client run.
I'm not sure if a custom resource will achieve the same results
@krzkrzkrz
Options:
- You could move the replace_or_add out of the ruby block. The resource doesn't use environment settings. You might want things grouped though.
- I've used ENV settings inside custom resources. That does work.
- Slack Chef Community general or cookbook-design channels would probably be a good place to discuss the design if you think you really need to use a ruby block.
I'm going to close this one as ruby blocks are not really in scope for the line cookbook.
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.