繁体   English   中英

如何使用 Puppet 因子在 Windows 2008 R2 中导入模块?

[英]How to Import-Module in Windows 2008 R2 using Puppet facter?

我正在使用 ruby 脚本到 output 一些与 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 的个人经验,我一直使用 ` 运算符,它也执行命令并返回 output。 例如,您可以这样做:

if ( $operatingsystemrelease == '2008 R2' )
    `powershell.exe Import-Module ServerManager`
end

如果这仍然不起作用,我会转向您安装 Windows 服务器,特别是确保您的环境变量没有被弄乱。 尽管事情有时看起来不太可能和疯狂,但总有一些时刻只能用“因为窗户”来解释;)

检查目标服务器中是否存在 Powershell 模块 - 我相信它在 2008 R2 之前默认不可用。

它应该位于同名文件夹中:

C:\Windows\System32\WindowsPowerShell\v1.0\Modules

您可能还需要使用 32 位 Powershell 而不是 64 位。

好的。 所以我决定改用外部事实。 它工作正常。

您可以查看 Puppet 的外部事实页面。

更新

我设法使用 ruby puppet custom factor。 我只删除了%q[] 这是脚本。

if ( $operatingsystemrelease == '2008 R2' )
     Facter::Core::Execution.execute('powershell Import-Module ServerManager')
end

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM