加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Windows > 正文

尝试使用Chef在Windows上以指定用户身份运行执行和批处理

发布时间:2020-12-14 05:43:18 所属栏目:Windows 来源:网络整理
导读:我在 Windows上使用Chef资源执行.当我设置资源的用户属性时,我收到此错误: Mixlib::ShellOut::InvalidCommandOption--------------------------------------You must supply both a username and password when supplying a user in windows 这是有道理的,
我在 Windows上使用Chef资源执行.当我设置资源的用户属性时,我收到此错误:

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

这是有道理的,但没有密码属性.我尝试了各种各样的方法,但还没弄明白如何传入.对于这种情况,明文密码不是问题.也许传入密码实际上不是一个功能?看这里(https://github.com/opscode/mixlib-shellout/blob/master/lib/mixlib/shellout/windows.rb),似乎可以选择密码.

我尝试使用Batch资源.该命令运行正常,直到我设置用户属性.我收到以下错误:

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

我不知道这些是否应该有用,我做错了什么或者如果它们不起作用我需要一个可能的解决方法.任何帮助表示赞赏!谢谢!

解决方法

情况似乎确实如此. Windows Chef问题的最佳资源通常是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/以获取有关如何存储和管理此密码的更多信息.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读