ruby - 如何使用 Puppet 因子在 Windows 2008 R2 中导入模块?
问题描述
我正在使用 ruby 脚本创建一个 puppet 自定义事实来输出一些与 AD 相关的详细信息。我了解到 ServerManager 是一个必备模块,因为它还没有自动添加到 Windows 2008 R2 构建中。我已经在我的一台 2008 R2 服务器中手动运行了我的 powershell 命令并且它工作正常。但是,每次我将它作为傀儡因素运行时都会出现以下错误。
感谢您对此的帮助。谢谢!
成功通过 Powershell 在 Windows 2008 R2 服务器中手动运行
Import-Module ServerManager
脚本
if ( $operatingsystemrelease == '2008 R2' )
Facter::Core::Execution.execute(%q[powershell Import-Module ServerManager])
end
错误
error while resolving custom fact "mycustomfact": execution of command "powershell Import-Module ServerManager" failed: command not found.
Source: Facter
谢谢你。
解决方案
您提供的方法对我来说效果很好(我用 Ruby 2.5.8、2.6.6 和 2.7.1 对其进行了测试),因此必须有更深层次的原因导致它不起作用。不过,我有一个解决方案。根据我个人使用 Ruby 和 PowerShell 的经验,我一直使用 ` 运算符,它也执行命令并返回输出。例如,您可以这样做:
if ( $operatingsystemrelease == '2008 R2' )
`powershell.exe Import-Module ServerManager`
end
如果这仍然不起作用,我会转向您的 Windows Server 安装,特别是确保您的环境变量没有被弄乱。尽管事情有时看起来不太可能和疯狂,但总有一些时刻只能用“因为窗户”来解释;)
推荐阅读
- c++ - 为什么 std::equal_to 会导致动态分配?
- bash - 使用 Shell 在 printf 中显示数字和 %d 之间的数学表达式的结果
- excel - 更新数据用户表单后存储为文本的值
- xamarin - MvvmCross iOS UILabel AttributedText 与语言转换器
- spring-boot - POST请求中的Oauth2纯文本凭据?
- reactjs - 为什么 GraphQL 将数组中的第一项显示为所有项?
- java - 错误:intellij 错误 cucumber.api.cli.Main
- javascript - CORS 策略已阻止访问来自原点 'null' 的脚本
- java - 如何在不遇到 OutOfMemoryError 的情况下将工作表附加到现有 Excel 文件?
- java - 绘制新卡时出现总和问题 - 二十一点