【问题标题】:Azure Cloud Shell Ansible with Windows hosts带有 Windows 主机的 Azure Cloud Shell Ansible
【发布时间】:2025-12-26 14:55:12
【问题描述】:

announcement 开始,我可以使用 ansible 在 Azure Cloud Shell 中列出我的 Azure 基础架构。

我也想在 Windows 机器上使用它。我在本地安装了 winrm,因为似乎不支持全局。

pip install "pywinrm>=0.2.2" --user

据此我了解软件包已正确安装

pywinrm (0.3.0)
requests (2.18.4)
xmltodict (0.11.0)
...

然后我运行,the proper credentials 一个 win ping 但 ansible 抱怨 WinRM 不可用。

ansible -i workspace/azure_rm.py -m win_ping DC-01

是否可以在带有 windows 主机的云 shell 中运行 ansible?

【问题讨论】:

    标签: azure pip ansible winrm azure-cloud-shell


    【解决方案1】:

    确保您的 Windows 主机已设置为 WinRM 控制。这意味着您应该检查一些工作是否正常,您可以查看 Ansible 对此有何评论here

    • 网络路径在 TCP 端口 5985-5986 上打开(尝试远程登录)
    • 已安装 Powershell 3.0 或更高版本
    • 已为远程 Windows 主机配置 WinRM 远程处理。
    • 确保 ansible play 使用 WinRM 端口连接

    如果需要,您可以使用 ansible 提供的优秀 PS 脚本稍作修改来设置本地证书并从 here 配置框。

    【讨论】:

    • 对我来说,根据问题消息,它看起来像是缺少库问题。我已经有其他运行 Ansible 的 Windows 主机(使用 ubuntu VM)并且它们没有问题。我的问题是我不清楚 Cloud Shell 是否支持 WinRM 管理。
    • ansible 在 windows 主机上有服务吗?当它下降时会发生什么?
    • Ansible 在 Windows 主机上没有服务,它主要在 WinRM 上运行,并提供 powershell 脚本来运行模块命令。
    【解决方案2】:

    我终于打开了a post on MSDN forums,微软发现了缺少的依赖并添加到了 Cloud Shell 中!

    终于可以在 Cloud Shell 中使用 Ansible。唯一的考虑是目标 VM 应该在端口 5986 上具有 Internet 连接。

    还有a sample script to test it

    【讨论】:

      最近更新 更多