Stan Morsky
Stan Morsky

Reputation: 53

Why can't I include Win32 in my chef recipe?

This code at the beginning of my chef recipe:

require "win32/service"
include Win32

results in the following error:

No resource or method named `include' for `Chef::Recipe "install"'

This works in ruby, why doesn't it work in a chef recipe?

Thanks!

Upvotes: 1

Views: 310

Answers (1)

Ivan
Ivan

Reputation: 169

Following code will work(in a recipe without the include/require),

target_service = "FreeSSHDService" if ::Win32::Service.exists?(target_service) Chef::Log.info target_service + "Found!" else Chef::Log.info target_service + "NOT Found!" end

The leading :: tells it not to look in the Chef namespace.

Reason for include not working,

In normal, non-Chef Ruby, you can include other classes in your own by using the include syntax; for example, include Opscode::OpenSSL::Password. Used in a recipe, however, the recipe compiler will try to find a provider for a resource of type “include” and it will fail.

Upvotes: 1

Related Questions