Question

So I have some code for running a batch file as a specific user. This was my attempt to automate the following syntax

runas /user:thisguy "C:\ThisGuysScript.bat"

so it looks like this in Ruby

Process.create(:command_line => "C:\\ThisGuysScript.bat ", :domain => "MYServer", :with_logon => "thisguy", :password => "thisguyspassword", :cwd =>"C:\\")

So I try to put this in a recipe in chef and disaster strikes

require 'win32/process'

::Process.create(:command_line => "C:\\ThisGuysScript.bat ", :domain => "MYServer", :with_logon => "thisguy", :password => "thisguyspassword", :cwd =>"C:\\")

Is failing with the following error

[Tue, 30 Oct 2012 15:57:03 +0000] FATAL: ArgumentError: You must supply a name when declaring a user resource

So it seems to not realise that I want to use the win32 flavour process. Chef seems to override the win32 module (I know recipes are the opscode DSL rather than really ruby right?)

Anyone been able to get this working? Or the same function with a different implementation. Checked out the windows cookbook but didn't spot much

Was it helpful?

Solution

It sounds like you want to make an LWRP for creating a process on a windows machine.

The error you are getting means you have something like

user do # Missing name
  gid 500
  home "..."
end

the correct syntax is

user "apache" do # or whatever the user name should be
   # ...
end

If you don't have the above in your cookbook, it is possible that the included file has a variable named user which would also cause this issue.

To answer your subquestion, Chef is straight ruby with some functions made available and a frame work to run things. Note, there are several stages in a chef run. I think you are having issues in the compilation stage.

Making an LWRP seems like the way to go. If you don't want to go that far you could do something like.

ruby_block "Firing process lazers" do
   require 'win32/process'
   ::Process.create(:command_line => "C:\\ThisGuysScript.bat ", :domain => "MYServer", :with_logon => "thisguy", :password => "thisguyspassword", :cwd =>"C:\\")
end
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top