无法使用Ansible剧本

问题描述:

每次我尝试运行的剧本来自动的Windows Server一些设施连接到Windows实例,我的Windows远程主机似乎可达无法使用Ansible剧本

在这里,我尝试安装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实例的公网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 

然后,我创建了一个目录“ group_vars“ in /etc/ansible,并且其中文件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执行策略,网络接口设置为专用网络(介意低于InterfaceAlias值)并启用PowerShell远程处理。

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

@prudhvi在你想连接的Windows机器上。通过在PowerShell窗口中键入它们来执行PowerShell命令。 – techraf

+0

当我输入“Set-NetConnectionProfile -InterfaceAlias Ethernet0-NetworkCategory Private”命令....我得到以下错误:Set-NetConnectionProfile:没有MSFT_NetConnectionProfile对象属性'InterfaceAlias'找到等于'Ethernet0'。验证该属性的值并重试。 + FullyQualifiedErrorId:CmdletizationQuery_NotFound_InterfaceAlias,Set-NetConnectionProfile – prudhvi

+0

请在运行命令之前阅读并尝试理解我的答案。 – techraf