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 irc.freenode.net

On Nov 7, 2013, at 8:29 AM, Rodrigo de Campos <[email protected]> wrote:

> 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:
> 
> NoMethodError
> -------------
> undefined method `chef' for Chef::Resource::RubyBlock
> 
> 
> Thanks for your help.
> 
> Follows my default.rb file:
> 
> Code:
> ruby_block "edit etc hosts" do
>   block do
>     rc = Chef::Util::FileEdit.new("/etc/hosts")
>     rc.search_file_replace_line(
>       /^127\.0\.0\.1 localhost$/,
>       "127.0.0.1 #{new_fqdn} #{new_hostname} localhost"
>     )
>     rc.write_file
>   end
> end
> 
> -- 
> Rodrigo de Campos
> Unix System Administrator
> 
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Ruby on Rails: Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to [email protected].
> To post to this group, send email to [email protected].
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/rubyonrails-talk/527BA3B9.4070906%40netzmarkt.de.
> For more options, visit https://groups.google.com/groups/opt_out.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/4A14216C-7030-4F4A-B356-3E0571D683B0%40gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to