每次我尝试运行一本剧本来自动化 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的剧本,我需要在控制节点上安装 winrm 。
我已经完成以下工作:
pip install "pywinrm>=0.1.1"
我已经添加了Windows实例的公共(public)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中配置远程命令(如Windows system prep部分中所述)。执行以下操作(具有管理员权限):
iwr https://raw.githubusercontent.com/ansible/ansible/devel/examples/scripts/ConfigureRemotingForAnsible.ps1 -UseBasicParsing | iex
之前,根据您的设置,您可能还需要启用PowerShell执行策略,将网络接口(interface)设置为专用网络(注意下面的
InterfaceAlias
值),然后启用PowerShell远程处理。Set-ExecutionPolicy Unrestricted -Force
Set-NetConnectionProfile -InterfaceAlias Ethernet0 -NetworkCategory Private
Enable-PSRemoting
关于windows - 无法使用Ansible Playbook连接到Windows实例,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/39056883/