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

问题描述 投票:0回答:2

我正在使用ruby脚本创建人偶自定义事实,以输出一些与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 powershell puppet windows-server-2008-r2 facter
2个回答
0
投票

您提供的方法对我来说非常好(我用Ruby 2.5.8、2.6.6和2.7.1对其进行了测试),因此必须有更深层的理由才能使此方法不起作用。不过,我有一个解决方案。以我自己在Ruby和PowerShell中的亲身经历,我一直使用`运算符,该运算符还执行命令并返回输出。例如,您可以这样做:

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

如果仍然不起作用,我将转向您的Windows Server安装,特别是要确保您的环境变量没有被弄乱。尽管有时看起来似乎不太可能发生,但有时总是只有用“因为窗口”才能解释这些时刻;)


0
投票

检查Powershell模块是否在目标服务器中存在-我认为它在默认情况下直到2008 R2才可用。

它应该在以下同名文件夹中:

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

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

© www.soinside.com 2019 - 2024. All rights reserved.