如何用rundeck控制window AD

How to control window AD with rundeck

我正在寻找通过 Rundeck 自动化 Windows 服务器 2012r2 的最佳解决方案。我对 Rundeck 非常熟悉,但将其用于 linux 虚拟机。我在网上搜索过这个主题,但没有找到任何看起来可靠的东西。理想情况下,我想启动一个 Runeck 作业,它可以在 Active Directory 中添加用户,但不确定如何处理它。我试过使用 winrm 但得到的结果好坏参半。具有讽刺意味的是,它会 运行 基本的 powershell 命令,但在尝试对 AD 执行任何操作时会出错。我什至尝试在 AD 服务器上创建一个 powershell 脚本,让 Rundeck 简单地执行 powershell 脚本无济于事。希望有人已经成功地使用 Rundeck 控制了 windows 个节点。以下是我在尝试 运行 powershell 脚本时收到的错误。

    Execution failed: 27 in project windows: [Workflow result: , step failures: {1=Dispatch failed on 1 nodes: [Windows_AD_Server: NonZeroResultCode: [WinRMPython] Result code: 1 + {dataContext=MultiDataContextImpl(map={ContextView(node:Windows_AD_Server)=BaseDataContext{{exec={exitCode=1}}}, ContextView(step:1, node:Windows_AD_Server)=BaseDataContext{{exec={exitCode=1}}}}, base=null)} ]}, Node failures: {Windows_AD_Server=[NonZeroResultCode: [WinRMPython] Result code: 1 + {dataContext=MultiDataContextImpl(map={ContextView(node:Windows_AD_Server)=BaseDataContext{{exec={exitCode=1}}}, ContextView(step:1, node:Windows_AD_Server)=BaseDataContext{{exec={exitCode=1}}}}, base=null)} ]}, status: failed]

首先,PowerShell 已经提供了一种内置的方式来执行作业,没有第 3 方插件。

About Jobs 提供有关 PowerShell 后台如何在不与当前会话交互的情况下在后台作业 运行 命令或表达式的信息。

About Remote Jobs 描述如何 运行 远程计算机上的后台作业。

PowerShell Jobs Week: Remote Jobs

正如 Paul 所指出的那样,我从未听说过/使用过 Rundeck,所以这只是 Rundeck 具有需要首先发挥作用的细节。然而,查看文档和关于该主题的快速 youtube 视频,对于您在这里所说的内容,有几件事必须到位...

I've tried using winrm but have gotten mixed results.

…上班。 Video - Running commands remotely using the console with WinRM/WinRS

如果 Rundeck 类似于 SCCM 或计划任务,则适用相同的方法。 编写您的 PowerShell 脚本。让 Rundeck/ScheduedTask 调用 powershell.exe 到 运行 脚本

How to execute a PowerShell script automatically using Windows task scheduler?

此外,这很可能被视为此 Whosebug 讨论和答案的副本。

rundeck unable to execute powershell script with import-module

我正在设置类似的东西并且有同样的问题。 AD 操作执行成功,但是 returns exit code 1 并抛出你提到的错误。我正在调试插件,但响应处理中似乎存在错误。

虽然抛出错误,但请检查广告操作是否有效,请post您用于控制广告的脚本块。

编辑:与此同时,我能够缩小问题范围并打开项目问题:github

我通过在 winrm-session.py 的第 89 行之后添加以下行来临时解决了这个问题:

new_msg = msg

前一行是:

" error message: %s" % (e))

下一行是:

else:

如果这不能解决您的问题,请post您的脚本块。

最佳托比亚斯