Forum: Ruby on Rails Ruby code on Chef as a "ruby_block" not working

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Rodrigo de Campos (Guest)
on 2013-11-07 19:17
(Received via mailing list)
Hi Ruby hackers,

I have very limited knowledge of the Ruby programming language, however,
I need to implement on Chef (check-solo) something similar to "augeas"
(which works with Puppet, but here I need a solution for Chef).

I got the example code below but it's not working and I am now for a few
days trying to figure out what is wrong.

Basically I need to be able to select specific strings in a text file
and modify these values. I could use sed but perhaps I can do it in a
more elegant way using the ruby_block from Chef.

Please let me know what can be possibly wrong with the code below. Why
is my /etc/hosts not being updated with new values?

Always when I re-run chef-solo, I get the following error:

**undefined method `chef' for Chef::Resource::RubyBlock*

Thanks for your help.

Follows my *default.rb* file:


ruby_block "edit etc hosts" do
   block do
     rc ="/etc/hosts")
       /^127\.0\.0\.1 localhost$/,
       " #{new_fqdn} #{new_hostname} localhost"

Rodrigo de Campos
Unix System A.
tamouse m. (Guest)
on 2013-11-07 19:28
(Received via mailing list)
You should really ask about this in a chef support area, as it is
something very specific to chef.

As it is, you cannot define local functions in chef recipes, they have
to be defined in libraries and called from such.

Stackoverflow is really your best bet for help on chef things, or the
#chef channel on
This topic is locked and can not be replied to.