Ansible win_ping模块在窗口中超时



我是Ansible新手,并尝试使用win_ping模块来pingWindows Server 2016 (EC2 instance)。Ansible 在 RHEL 7.3 控制机器上,我在控制机上安装了pippywinrm

sudo pip install "pywinrm>=0.2.2"

这是我inventory文件:

test ansible_connection=winrm ansible_host=34.210.164.63
[test_group]
test
[super_group:children]
test_group
[super_group:vars]
ansible_user=Administrator
ansible_password=XXXX
ansible_port=5986
ansible_winrm_server_cert_validation=ignore

这是我尝试过的命令:

ansible all -i inventory -m win_ping

我收到此错误:

test | UNREACHABLE! => {
"changed": false,
"msg": "ssl: HTTPSConnectionPool(host='34.210.164.63', port=5986): Max retries exceeded with url: /wsman (Caused by ConnectTimeoutError(<urllib3.connection.VerifiedHTTPSConnection object at 0x30df350>, 'Connection to 34.210.164.63 timed out. (connect timeout=30)'))",
"unreachable": true
}

在Windows Server 2016中,默认情况下Server Manager Remoting is already enabled,我使用Configure-SMremoting.exe -enable命令对其进行了验证。我没有在Windows服务器上进行任何配置,因为此远程处理已经启用。请让我知道如何解决此问题。

编辑:不确定这些步骤是否必需,但我尝试使用以下命令启用PowerShell Remoting

Enable-PSRemoting -Force

然后尝试powershell.exe -File ConfigureRemotingForAnsible.ps1,我得到一个错误:

At C:UsersAdministratorDesktopConfigureRemotingForAnsible.ps1:128 char:13
+ </a>        <a href="/business" class="js-selected-navigation-item na ...
+             ~
The '<' operator is reserved for future use.
At C:UsersAdministratorDesktopConfigureRemotingForAnsible.ps1:130 char:13
+ </a>        <a href="/explore" class="js-selected-navigation-item nav ...
+             ~
The '<' operator is reserved for future use.
At C:UsersAdministratorDesktopConfigureRemotingForAnsible.ps1:132 char:17
+ </a>            <a href="/marketplace" class="js-selected-navigation- ...
+                 ~
The '<' operator is reserved for future use.
At C:UsersAdministratorDesktopConfigureRemotingForAnsible.ps1:134 char:13
+ </a>        <a href="/pricing" class="js-selected-navigation-item nav ...
+             ~
The '<' operator is reserved for future use.
At C:UsersAdministratorDesktopConfigureRemotingForAnsible.ps1:136 char:11
+ </a>      </nav>
+           ~
The '<' operator is reserved for future use.
At C:UsersAdministratorDesktopConfigureRemotingForAnsible.ps1:3221 char:227
+ ... g:0;display:inline"><input name="utf8" type="hidden" value="&#x2713;" ...
+                                                                 ~
The ampersand (&) character is not allowed. The & operator is reserved for future use; wrap an ampersand in double
quotation marks ("&") to pass it as part of a string.
At C:UsersAdministratorDesktopConfigureRemotingForAnsible.ps1:3224 char:10
+ </form>  </div>
+          ~
The '<' operator is reserved for future use.
At C:UsersAdministratorDesktopConfigureRemotingForAnsible.ps1:3252 char:11
+       <li>&copy; 2017 <span title="0.13767s from github-fe-df0f95a.cp ...
+           ~
The ampersand (&) character is not allowed. The & operator is reserved for future use; wrap an ampersand in double
quotation marks ("&") to pass it as part of a string.
At C:UsersAdministratorDesktopConfigureRemotingForAnsible.ps1:3252 char:23
+       <li>&copy; 2017 <span title="0.13767s from github-fe-df0f95a.cp ...
+                       ~
The '<' operator is reserved for future use.
At C:UsersAdministratorDesktopConfigureRemotingForAnsible.ps1:3252 char:29
+ ...  2017 <span title="0.13767s from github-fe-df0f95a.cp1-iad.github.net ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Unexpected token 'title="0.13767s from github-fe-df0f95a.cp1-iad.github.net">GitHub</span>' in expression or statement.
Not all parse errors were reported.  Correct the reported errors and try again.
+ CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : RedirectionNotSupported

我想我需要在我的 Windows 服务器中配置启用远程电源外壳来解决此问题,但不确定如何,因为我得到上述 erorr - 请提出建议。

我会浏览Windows日志。如果它们不包含您需要的信息 - 增加详细程度。 平靠的是温姆在上。WinRM 需要执行策略更改、服务配置、SSL 证书等。 也许最安全的途径是使用文档重新配置 ansible。

必须配置 powershell 远程处理,在 ec2 中,您可以通过添加用户数据、在那里运行脚本、将命令粘贴到那里来做到这一点。

此外,您的 ansible 主计算机必须能够连接到目标主机,通常通过安全组允许它并在该组中创建实例来完成。

因此,为了调试你的东西,你应该展示你为设置安全组、可能的路由和实例创建所做的代码/操作。

这可能是AWS方面的问题,而不是一个问题。是否允许您的 ansible 服务器通过安全组规则与您的 Windows EC2 实例通信?默认情况下,所有内容都被拒绝。您需要允许 ICMP 来自 Windows EC2 实例安全组规则中的 ansible 服务器地址以及来自 ansible 服务器安全组规则中的 Windows 服务器(如果您的 ansible 服务器也是 EC2 实例(。如果 ansible 服务器不是 EC2 实例,请确保您的防火墙不会出于某种原因阻止 ICMP 的传入或传出。

这两个服务器是否位于您账户中的同一子网/VPC 上?如果没有,您必须在它们所在的 VPC 之间创建 VPC 对等连接,并在流量来自/流向其他 VPC 时编辑路由表以将 VPC 指向对等连接。这样做的目的是让不同 VPC 中的两个实例可以相互识别和通信

我可能迟到了,但我注意到你在运行powershell.exe -File ConfigureRemotingForAnsible.ps1时遇到的错误。它抱怨语法,据我所知,该文件中有 HTML。您是否可能从脚本中保存了 GitLab HTML 页面?

在此处下载原始文件:https://raw.githubusercontent.com/ansible/ansible/devel/examples/scripts/ConfigureRemotingForAnsible.ps1,然后重试。

最新更新