无法使用Ansible Playbook连接到Windows实例

无法使用Ansible Playbook连接到Windows实例,windows,ansible,winrm,Windows,Ansible,Winrm,每次我尝试运行playbook来自动化Windows Server中的某些安装时,我的Windows远程主机似乎无法访问 在这里,我正在尝试安装IIS服务器,我的剧本如下所示: --- - hosts : windows tasks : - name : Install Microsoft IIS win_feature : name : Web-Server state : present 而错误是: fatal: [ec2-54-197-197-91.compute

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

在这里,我正在尝试安装IIS服务器,我的剧本如下所示:

---
- 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实例的公共ip,我的主机文件如下所示:

[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实例上的PowerShell中配置远程命令(如本节所述)。执行以下操作(具有管理员权限):


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

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

@您要连接到的Windows计算机上的prudhvi。您可以通过在PowerShell窗口中键入来执行PowerShell命令。当我键入“Set-NetConnectionProfile-InterfaceAlias Ethernet0-NetworkCategory Private”时命令…我收到以下错误:Set-NetConnectionProfile:未找到属性“InterfaceAlias”等于“Ethernet0”的MSFT\U-NetConnectionProfile对象。验证属性的值,然后重试。+FullyQualifiedErrorId:CmdletionQuery\u NotFound\u InterfaceAlias,Set-NetConnectionProfile请在运行命令之前阅读并尝试理解我的答案。我是否应该为InterfaceAlias使用值“Ethernet0”??我完全不知道该用什么我不知道你应该用什么价值。这是你的系统,我无法访问。我甚至不知道您是否需要运行它(例如,如果您将网络设置为“专用”,或禁用防火墙)。我写得很清楚:第一,作为与Ansible相关的答案分开的旁注,第二;前面加上“视情况而定”和潜在形式“您可能需要”。
iwr https://raw.githubusercontent.com/ansible/ansible/devel/examples/scripts/ConfigureRemotingForAnsible.ps1 -UseBasicParsing | iex
Set-ExecutionPolicy Unrestricted -Force
Set-NetConnectionProfile -InterfaceAlias Ethernet0 -NetworkCategory Private
Enable-PSRemoting