Hey Ram,
So, there are two to three things wrong with your code:
svc
is a variable and shouldn’t be wrapped in quotes, as others have mentioned.require
takes a string, not a class, which is the error you’re getting. This line isn’t necessary at all, though; you can probably just remove it. If you need to explicitly specify a provider for your services, use theprovider
attribute as Tensibai suggested.- If your
/root/svc
file already contains the required contents at the start of the chef run, then there’s no need to complicate things by using aruby_block
resource. You really only need aruby_block
if some other chef resource is going to be dropping off that file and you want to wait to read the contents until as late as possible.I’m pretty sure what you want is something like this:
services = File.readlines("/root/svc") services.each do |svc| service svc.chomp do provider Chef::Provider::Service::Init::Redhat #This may not be necessary action [ :stop, :disable] end end
I added the
.chomp
because the results ofFile.readlines
appear to have new-lines on the end of them. I’m not 100% sure it’s required, but it won’t hurt.You might want to consider reading over this for a quick overview of ruby for chef users.
Hope that helps.
Matt Moretti
On Mon, Sep 15, 2014 at 12:31 AM, ram karthik < " target="_blank"> > wrote:Hi Tensibai,I have tried "svc" , svc , "#{svc}" - nothing worked . Basically the contents of the file is as below which leaves scope for adding more services as required ,
cat /root/svc
auditd
vsftpdOn Sun, Sep 14, 2014 at 9:56 AM, Tensibai Zhaoying < " target="_blank"> > wrote:Use the provider attribute if the service resource and your declaration should use the var without quotes or with #{svc}
See http://docs.getchef.com/resource_service.html for the service resource and provider attribute
Envoyé à partir de mon smartphone Sony Xperia™
---- ram karthik a écrit ----require "chef/provider/service/init/redhat" returned load error , or Am I missing somethingOn Sun, Sep 14, 2014 at 1:52 AM, Tensibai Zhaoying < " target="_blank"> > wrote:If it is inside a recipe you don't have to require the service provider, it will guess it.
If you really want to enforce it, there's a provider attribute to the service resource.For the error message, require take a path to a file without the extension, here it should be require "chef/provider/service/init/redhat"
Envoyé à partir de mon smartphone Sony Xperia™
---- " target="_blank"> a écrit ----
I have multiple services that I need to stop , my code is as below ,
ruby_block "stopsvc" do
block do
services = File.readlines("/root/svc")
services.each do |svc|
require
Chef::Provider::Service::Init::Redhat
service "svc" do
action [ :stop, :disable]
end
end
end
end
"can't convert Class into String" is the error I am seeing . Please point what
I need ,
Archive powered by MHonArc 2.6.16.