gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 21:40:22 27 4
gpt4 key购买 nike

我在 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/有关如何存储和管理此密码的更多信息。

关于chef-infra - 尝试使用 Chef 在 Windows 上以指定用户身份运行执行和批处理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26089766/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com