我在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/以获取有关如何存储和管理此密码的更多信息.
相关文章
- Windows 7从命令提示符处以非管理员用户身份运行
- windows-7 - 在Windows 7中将程序作为域管理员帐户运行并以“以管理员身份运行”运行程序之间的区别是什么?
- maven - 以非root用户身份运行docker或以root用户身份在tomcat上运行jenkins
- windows - 如何使用Powershell'revoke-expression'以不同的用户身份运行可执行文件
- windows - 如何以Bamboo的管理员身份运行批处理脚本?
- 批处理文件 - 如何创建批处理文件以管理员身份运行cmd
- 批处理文件 - 从Jenkins执行Windows批处理命令失败,但在cmd.exe中运行正常
- 批处理文件 - 以管理员身份自动运行批处理文件
转载注明原文:尝试使用Chef在Windows上以指定用户身份运行执行和批处理 - 代码日志