【问题标题】:Unable to connect to a Windows Instance using Ansible Playbook无法使用 Ansible Playbook 连接到 Windows 实例
【发布时间】:2016-08-20 17:24:09
【问题描述】:

每次我尝试在 Windows Server 中运行 playbook 以自动执行某些安装时,我的 Windows 远程主机似乎无法访问

在这里,我正在尝试安装 IIS 服务器,而我的 playbook 看起来像这样:

---
- hosts : windows
  tasks :
- name : Install Microsoft IIS
  win_feature :
    name : Web-Server
    state : present

错误是:

fatal: [ec2-54-197-197-91.compute-1.amazonaws.com]: UNREACHABLE! => {
"changed": false,
"msg": "ssl: HTTPSConnectionPool(host='ec2-54-197-197-91.compute-1.amazonaws.com', port=5986): Max retries exceeded with url: /wsman (Caused by ConnectTimeoutError(<requests.packages.urllib3.connection.VerifiedHTTPSConnection object at 0x1b11310>, 'Connection to ec2-54-197-197-91.compute-1.amazonaws.com timed out. (connect timeout=30)'))",
"unreachable": true
}

但是,现在我知道,要运行适用于 Windows 的 playbook,我需要在我的控制节点上安装 winrm

我做了以下事情:

pip install "pywinrm>=0.1.1"

我已经添加了 Windows 实例的公共 ip,我的 hosts 文件看起来像:

[local]
127.0.0.1

[aws]
ec2-54-152-85-197.compute-1.amazonaws.com

[windows]
ec2-54-197-197-91.compute-1.amazonaws.com

然后,我在 /etc/ansible 中创建了一个目录 "group_vars",并在其中创建了一个文件 windows.yml,内容如下:

ansible_user: Administrator
ansible_password: SecretPasswordGoesHere
ansible_port: 5986
ansible_connection: winrm
ansible_winrm_server_cert_validation: ignore 

请告诉我哪里出错了。

【问题讨论】:

    标签: windows ansible winrm


    【解决方案1】:

    (很可能,因为你没有提到它)

    您需要在 Windows 实例上的 PowerShell 中配置远程命令(如Windows system prep 部分所述)。执行以下命令(具有管理员权限):

    iwr https://raw.githubusercontent.com/ansible/ansible/devel/examples/scripts/ConfigureRemotingForAnsible.ps1 -UseBasicParsing | iex
    

    之前,根据您的设置,您可能还需要启用 PowerShell 执行策略,将网络接口设置为专用网络(注意下面的 InterfaceAlias 值)并启用 PowerShell 远程处理。

    Set-ExecutionPolicy Unrestricted -Force
    Set-NetConnectionProfile -InterfaceAlias Ethernet0 -NetworkCategory Private
    Enable-PSRemoting
    

    【讨论】:

    • @prudhvi 在您要连接的 Windows 机器上。您可以通过在 PowerShell 窗口中键入来执行 PowerShell 命令。
    • 当我输入“Set-NetConnectionProfile -InterfaceAlias Ethernet0 -NetworkCategory Private”命令时......我收到以下错误:Set-NetConnectionProfile:没有找到属性“InterfaceAlias”等于“Ethernet0”的 MSFT_NetConnectionProfile 对象'。验证属性的值并重试。 + FullyQualifiedErrorId : CmdletizationQuery_NotFound_InterfaceAlias,Set-NetConnectionProfile
    • 请在运行命令之前阅读并尝试理解我的答案。
    • 我应该为 InterfaceAlias 使用值“Ethernet0”吗?我完全不知道该用什么
    • 我不知道你应该使用什么值。这是你的系统,我无权访问它。我什至不知道您是否需要运行它(例如,如果您将网络设置为“私有”,或者禁用防火墙)。我已经写得很清楚了:首先,作为与 Ansible 相关的答案分开的旁注,其次;前面加上“它取决于”和可能的形式“你可能需要”。
    猜你喜欢
    • 2018-01-03
    • 2016-08-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-05
    • 2022-11-10
    • 1970-01-01
    相关资源
    最近更新 更多