Attempt to run to execute and execute the package as the specified user in Windows with the chef

I am using the Chef Execute resource on Windows. When I set the resource user attribute, I get this error:

Mixlib::ShellOut::InvalidCommandOption
--------------------------------------
You must supply both a username and password when supplying a user in windows

This makes sense, but the password attribute is missing. I tried all kinds of ways, but did not understand how to do it. In this situation, a clear text password is not a problem. Perhaps password passing is not really a feature? Looking here ( https://github.com/opscode/mixlib-shellout/blob/master/lib/mixlib/shellout/windows.rb ), it seems that a password option is expected.

I tried to use the Batch resource. The command works fine until I set a custom attribute. I get the following error:

NoMethodError
-------------
undefined method `uid' for nil:NilClass

, , - , , . ! !

+4
1

. , Windows + Chef, - , , , Windows. , , :

class Chef
  class Resource::WindowsExecute < Resource::Execute
    def initialize(name, run_context=nil)
      super
      @resource_name = :windows_execute
    end

    def password(arg=nil)
      set_or_return(:password, arg, :kind_of => String)
    end
  end

  class Provider::WindowsExecute < Provider::Execute
    def shell_out!(cmd, opts)
      opts[:password] = new_resource.password if new_resource.password
      super
    end
  end
end

, libraries/windows_execute.rb windows_execute . https://coderanger.net/chef-secrets/ , .

+1

All Articles