Can't use powershell_out command

Hello all,

I’m trying to use the powershell_out command, but get an error while including the Chef::Mixin::PowerShellOut.

This is my recipe:
Chef::Resource.send(:include, Chef::Mixin::WindowsArchitectureHelper)
Chef::Resource.send(:include, Chef::Mixin::PowershellOut)

cmd = powershell_out!(‘write-host Hello World’);
Chef::Log::info(“cmd.stdout = #{cmd.stdout}”)
Chef::Log::info(“cmd.stderr = #{cmd.stderr}”)

And this is the error I get:

Recipe Compile Error in c:/chef/cache/cookbooks/lan_driver/recipes/default.rb

NameError

uninitialized constant Chef::Mixin::PowershellOut

Cookbook Trace:

c:/chef/cache/cookbooks/lan_driver/recipes/default.rb:13:in `from_file’

Relevant File Content:

c:/chef/cache/cookbooks/lan_driver/recipes/default.rb:

6: #
7: # All rights reserved - Do Not Redistribute
8: #
9:
10:
11:
12: Chef::Resource.send(:include, Chef::Mixin::WindowsArchitectureHelper)
13>> Chef::Resource.send(:include, Chef::Mixin::PowershellOut)
14:
15:
16: cmd = powershell_out!(‘write-host Hello World’);
17: Chef::Log::info(“cmd.stdout = #{cmd.stdout}”)
18: Chef::Log::info(“cmd.stderr = #{cmd.stderr}”)
19:
20:
21:
22:

Running handlers:
[2014-09-15T22:35:51+03:00] ERROR: Running exception handlers
Running handlers complete
[2014-09-15T22:35:51+03:00] ERROR: Exception handlers complete
[2014-09-15T22:35:51+03:00] FATAL: Stacktrace dumped to c:/chef/cache/chef-stacktrace.out
Chef Client failed. 0 resources updated in 8.967519 seconds
[2014-09-15T22:35:51+03:00] FATAL: NameError: uninitialized constant Chef::Mixin::PowershellOut

Please note that there is no error at the first line (Chef::Resource.send(:include, Chef::Mixin::WindowsArchitectureHelper)), only at the second line.
I added the first line just for debugging.

I use Chef version 11.12.8.

What do I miss here?

Thanks,
Raanan.


Intel Israel (74) Limited

This e-mail and any attachments may contain confidential material for
the sole use of the intended recipient(s). Any review or distribution
by others is strictly prohibited. If you are not the intended
recipient, please contact the sender and delete all copies.

Few months ago I ran into same issue and I was suggested on this forum to have a “library” file with following content:

class Chef
class Resource
include Chef::Mixin::PowershellOut
end
end

This helped me. Try that and see if it works for you.

Thanks

-Kapil

From: Avargil, Raanan [mailto:raanan.avargil@intel.com]
Sent: Monday, September 15, 2014 3:46 PM
To: chef@lists.opscode.com
Cc: Avargil, Raanan
Subject: [chef] Can’t use powershell_out command

Hello all,

I’m trying to use the powershell_out command, but get an error while including the Chef::Mixin::PowerShellOut.

This is my recipe:
Chef::Resource.send(:include, Chef::Mixin::WindowsArchitectureHelper)
Chef::Resource.send(:include, Chef::Mixin::PowershellOut)

cmd = powershell_out!(‘write-host Hello World’);
Chef::Log::info(“cmd.stdout = #{cmd.stdout}”)
Chef::Log::info(“cmd.stderr = #{cmd.stderr}”)

And this is the error I get:

Recipe Compile Error in c:/chef/cache/cookbooks/lan_driver/recipes/default.rb

NameError

uninitialized constant Chef::Mixin::PowershellOut

Cookbook Trace:

c:/chef/cache/cookbooks/lan_driver/recipes/default.rb:13:in `from_file’

Relevant File Content:

c:/chef/cache/cookbooks/lan_driver/recipes/default.rb:

6: #
7: # All rights reserved - Do Not Redistribute
8: #
9:
10:
11:
12: Chef::Resource.send(:include, Chef::Mixin::WindowsArchitectureHelper)
13>> Chef::Resource.send(:include, Chef::Mixin::PowershellOut)
14:
15:
16: cmd = powershell_out!(‘write-host Hello World’);
17: Chef::Log::info(“cmd.stdout = #{cmd.stdout}”)
18: Chef::Log::info(“cmd.stderr = #{cmd.stderr}”)
19:
20:
21:
22:

Running handlers:
[2014-09-15T22:35:51+03:00] ERROR: Running exception handlers
Running handlers complete
[2014-09-15T22:35:51+03:00] ERROR: Exception handlers complete
[2014-09-15T22:35:51+03:00] FATAL: Stacktrace dumped to c:/chef/cache/chef-stacktrace.out
Chef Client failed. 0 resources updated in 8.967519 seconds
[2014-09-15T22:35:51+03:00] FATAL: NameError: uninitialized constant Chef::Mixin::PowershellOut

Please note that there is no error at the first line (Chef::Resource.send(:include, Chef::Mixin::WindowsArchitectureHelper)), only at the second line.
I added the first line just for debugging.

I use Chef version 11.12.8.

What do I miss here?

Thanks,
Raanan.


Intel Israel (74) Limited

This e-mail and any attachments may contain confidential material for
the sole use of the intended recipient(s). Any review or distribution
by others is strictly prohibited. If you are not the intended
recipient, please contact the sender and delete all copies.

Hi Kapil,
Thank for youe answer!

It didn’t work for me. The source of the error moved to the library instead of the recipe.
See below:

Compiling Cookbooks…

================================================================================
Recipe Compile Error in c:/chef/cache/cookbooks/lan_driver/libraries/default.rb

NameError

uninitialized constant Chef::Mixin::PowershellOut

Cookbook Trace:

c:/chef/cache/cookbooks/lan_driver/libraries/default.rb:3:in <class:Resource>' c:/chef/cache/cookbooks/lan_driver/libraries/default.rb:2:inclass:Chef
c:/chef/cache/cookbooks/lan_driver/libraries/default.rb:1:in `<top (required)>’

Relevant File Content:

c:/chef/cache/cookbooks/lan_driver/libraries/default.rb:

1: class Chef
2: class Resource
3>> include Chef::Mixin::PowershellOut
4: end
5: end
6:

Running handlers:
[2014-09-16T07:44:12+03:00] ERROR: Running exception handlers
Running handlers complete
[2014-09-16T07:44:12+03:00] ERROR: Exception handlers complete
[2014-09-16T07:44:12+03:00] FATAL: Stacktrace dumped to c:/chef/cache/chef-stacktrace.out
Chef Client failed. 0 resources updated in 9.402607 seconds
[2014-09-16T07:44:12+03:00] FATAL: NameError: uninitialized constant Chef::Mixin::PowershellOut

I feel like I miss something very basic.

Raanan

From: Kapil Shardha [mailto:Kapil.Shardha@SimulationIQ.com]
Sent: Monday, September 15, 2014 22:54
To: chef@lists.opscode.com
Subject: [chef] RE: Can’t use powershell_out command

Few months ago I ran into same issue and I was suggested on this forum to have a “library” file with following content:

class Chef
class Resource
include Chef::Mixin::PowershellOut
end
end

This helped me. Try that and see if it works for you.

Thanks

-Kapil

From: Avargil, Raanan [mailto:raanan.avargil@intel.com]
Sent: Monday, September 15, 2014 3:46 PM
To: chef@lists.opscode.commailto:chef@lists.opscode.com
Cc: Avargil, Raanan
Subject: [chef] Can’t use powershell_out command

Hello all,

I’m trying to use the powershell_out command, but get an error while including the Chef::Mixin::PowerShellOut.

This is my recipe:
Chef::Resource.send(:include, Chef::Mixin::WindowsArchitectureHelper)
Chef::Resource.send(:include, Chef::Mixin::PowershellOut)

cmd = powershell_out!(‘write-host Hello World’);
Chef::Log::info(“cmd.stdout = #{cmd.stdout}”)
Chef::Log::info(“cmd.stderr = #{cmd.stderr}”)

And this is the error I get:

Recipe Compile Error in c:/chef/cache/cookbooks/lan_driver/recipes/default.rb

NameError

uninitialized constant Chef::Mixin::PowershellOut

Cookbook Trace:

c:/chef/cache/cookbooks/lan_driver/recipes/default.rb:13:in `from_file’

Relevant File Content:

c:/chef/cache/cookbooks/lan_driver/recipes/default.rb:

6: #
7: # All rights reserved - Do Not Redistribute
8: #
9:
10:
11:
12: Chef::Resource.send(:include, Chef::Mixin::WindowsArchitectureHelper)
13>> Chef::Resource.send(:include, Chef::Mixin::PowershellOut)
14:
15:
16: cmd = powershell_out!(‘write-host Hello World’);
17: Chef::Log::info(“cmd.stdout = #{cmd.stdout}”)
18: Chef::Log::info(“cmd.stderr = #{cmd.stderr}”)
19:
20:
21:
22:

Running handlers:
[2014-09-15T22:35:51+03:00] ERROR: Running exception handlers
Running handlers complete
[2014-09-15T22:35:51+03:00] ERROR: Exception handlers complete
[2014-09-15T22:35:51+03:00] FATAL: Stacktrace dumped to c:/chef/cache/chef-stacktrace.out
Chef Client failed. 0 resources updated in 8.967519 seconds
[2014-09-15T22:35:51+03:00] FATAL: NameError: uninitialized constant Chef::Mixin::PowershellOut

Please note that there is no error at the first line (Chef::Resource.send(:include, Chef::Mixin::WindowsArchitectureHelper)), only at the second line.
I added the first line just for debugging.

I use Chef version 11.12.8.

What do I miss here?

Thanks,
Raanan.


Intel Israel (74) Limited

This e-mail and any attachments may contain confidential material for
the sole use of the intended recipient(s). Any review or distribution
by others is strictly prohibited. If you are not the intended
recipient, please contact the sender and delete all copies.

Intel Israel (74) Limited

This e-mail and any attachments may contain confidential material for
the sole use of the intended recipient(s). Any review or distribution
by others is strictly prohibited. If you are not the intended
recipient, please contact the sender and delete all copies.

On Tue, Sep 16, 2014 at 12:53 AM, Avargil, Raanan
raanan.avargil@intel.com wrote:

Hi Kapil,

Thank for youe answer!

It didn’t work for me. The source of the error moved to the library instead
of the recipe.

See below:

Compiling Cookbooks...

================================================================================

Recipe Compile Error in
c:/chef/cache/cookbooks/lan_driver/libraries/default.rb

================================================================================

NameError


uninitialized constant Chef::Mixin::PowershellOut

Have you declared a dependency on the 'windows' cookbook in your
metadata for lan_driver?

  • Julian

--
[ Julian C. Dunn jdunn@aquezada.com * Sorry, I'm ]
[ WWW: http://www.aquezada.com/staff/julian * only Web 1.0 ]
[ gopher://sdf.org/1/users/keymaker/ * compliant! ]
[ PGP: 91B3 7A9D 683C 7C16 715F 442C 6065 D533 FDC2 05B9 ]

Hello Julian,
Bingo! Indeed I missed the depends "windows" declaration in the metadata.rb file.
When I added the dependency, I got the following error:

Recipe Compile Error in c:/chef/cache/cookbooks/lan_driver/recipes/default.rb

NoMethodError

No resource or method named powershell_out!' for Chef::Recipe "default"'

Cookbook Trace:

c:/chef/cache/cookbooks/lan_driver/recipes/default.rb:15:in `from_file'

Relevant File Content:

c:/chef/cache/cookbooks/lan_driver/recipes/default.rb:

8: #
9:
10:
11:
12: #Chef::Resource.send(:include, Chef::Mixin::WindowsArchitectureHelper)
13: Chef::Resource.send(:include, Chef::Mixin::PowershellOut)
14:
15>> cmd = powershell_out!('write-host Hello World');
16: Chef::Log::info("cmd.stdout = #{cmd.stdout}")
17: Chef::Log::info("cmd.stderr = #{cmd.stderr}")
18:

But, when I changed the line
Chef::Resource.send(:include, Chef::Mixin::PowershellOut) to Chef::Recipe.send(:include, Chef::Mixin::PowershellOut) it worked!

Thank you!
Raanan

-----Original Message-----
From: Julian C. Dunn [mailto:jdunn@aquezada.com]
Sent: Tuesday, September 16, 2014 08:58
To: chef@lists.opscode.com
Subject: [chef] Re: RE: Can't use powershell_out command

On Tue, Sep 16, 2014 at 12:53 AM, Avargil, Raanan raanan.avargil@intel.com wrote:

Hi Kapil,

Thank for youe answer!

It didn’t work for me. The source of the error moved to the library
instead of the recipe.

See below:

Compiling Cookbooks...

======================================================================

Recipe Compile Error in
c:/chef/cache/cookbooks/lan_driver/libraries/default.rb

======================================================================

NameError


uninitialized constant Chef::Mixin::PowershellOut

Have you declared a dependency on the 'windows' cookbook in your metadata for lan_driver?

  • Julian

--
[ Julian C. Dunn jdunn@aquezada.com * Sorry, I'm ]
[ WWW: http://www.aquezada.com/staff/julian * only Web 1.0 ]
[ gopher://sdf.org/1/users/keymaker/ * compliant! ]
[ PGP: 91B3 7A9D 683C 7C16 715F 442C 6065 D533 FDC2 05B9 ]

Intel Israel (74) Limited

This e-mail and any attachments may contain confidential material for
the sole use of the intended recipient(s). Any review or distribution
by others is strictly prohibited. If you are not the intended
recipient, please contact the sender and delete all copies.