无法使用 win_ping ping 我的 Windows 服务器

Unable to ping my Windows Server using win_ping

当我尝试使用 ansible windows -i hosts.ini -m win_ping ping Windows 实例时,出现以下错误:

54.197.197.91 | UNREACHABLE! => {
"changed": false,
"msg": "plaintext: the specified credentials were rejected by the server",
"unreachable": true
}

我的 hosts.ini 文件如下所示:

[windows]
54.197.197.91

[windows:vars]
ansible_ssh_user=Administrator
ansible_ssh_pass=MyPassword123!
ansible_ssh_port=5985
ansible_connection=winrm

为了解决这个问题,我这样做了:

ansible-vault create secret.yml

然后像这样输入我的密码:

win_initial_password: MyPassword123!

然后,我的 hosts.ini 文件看起来像:

[windows]
54.197.197.91

[windows:vars]
ansible_ssh_user=Administrator
ansible_ssh_pass={{ win_initial_password }}
ansible_ssh_port=5985
ansible_connection=winrm

当我尝试 ping 时,出现以下错误:

54.197.197.91 | FAILED! => {
"failed": true,
"msg": "the field 'password' has an invalid value, which appears to include a variable that is undefined. The error was: 'win_initial_password' is undefined"
}

我哪里错了?

我通过改变这些解决了它:

ansible_ssh_port=5986
ansible_winrm_server_cert_validation=ignore

这有效。

对我来说仍然是个问题。我的解决方案是从头开始重新安装 python-pipwinrm 相关的软件包。我不得不使用官方Ansible documentation。根据文档:

  1. apt-get install python-pip git libffi-dev libssl-dev -y
  2. pip install ansible pywinrm
  3. Windows 的端口号是 5986 所以你的 var 配置应该是 ansible_ssh_port: 5986

因为我遵循了一个类似于原始 post 的 Ansible 示例,所以接受的答案对我不起作用,下面的答案起作用了

注意:这是以纯文本形式发送密码,所以不要在生产中使用

在目标机器上,运行 具有管理员权限的 powershell 并输入这些命令:

Set-Item -Path WSMan:\localhost\Service\Auth\Basic -Value $true winrm set winrm/config/service '@{AllowUnencrypted="true"}'

还要验证您的防火墙配置是否正确,允许必要的端口通过(TCP/5985、TCP/5986)

来源:

http://docs.ansible.com/ansible/latest/user_guide/windows_winrm.html#authentication-options https://github.com/diyan/pywinrm/issues/114

即使 "AllowUnencrypted" 设置为 true,我也遇到了同样的问题。我观察到 win_ping 正在为添加到管理员组但因

而失败的 IEUser 工作
windows-server | UNREACHABLE! => {
  "changed": false,
  "msg": "plaintext: the specified credentials were rejected by the server",
  "unreachable": true
}

对于不在管理员组中的 test-user

所以我将 test-user 添加到管理员组,问题得到解决。

我在谷歌上搜索了很多,最后下面的配置对我有用。我已将 ntlm 添加到我的配置文件中。

ansible_user: user@DOMAIN.COM
ansible_password: password
ansible_connection: winrm
ansible_ssh_port: 5986
ansible_winrm_transport: ntlm
ansible_winrm_server_cert_validation: ignore

Windows:
我已经在 windows 安装了 UBUNTU18-LTE 并且遇到了很多问题。所以分享我遇到同样错误的经验。希望这会有所帮助。

用户必须是本地的。 伙计们记住用户(ansible)必须是本地(主机 - 192.168.11.22)管理员用户否则无法使用以下过程。

  1. 主机文件示例。
    猫/etc/ansible/hosts
    [赢]
    192.168.11.22

    [胜利:变量]
    ansible_connection=winrm
    ansible_user=ansible # 宿主机的本地管理员用户 192.168.11.22
    ansible_password=ansible123
    ansible_winrm_server_cert_validation=忽略
    ansible_winrm_trasport=基本
    ansible_port=5985 #HTTP

  2. 运行 下面的命令 在主机 PowerShell windows.
    winrm configsddl default #给ansible用户权限

  3. Post 步骤 2 配置在主机 PowerShell.
    上执行以下 2 个命令 winrm 设置 winrm/config/service/auth '@{Basic="true"}'
    winrm 设置 winrm/config/service '@{AllowUnencrypted="true"}'

  4. 其他使用完整的 PowerShell 命令来测试 winrm 连接。

    1. winrm 枚举 winrm/config/Listener.
    2. winrm 获取 winrm/config
    3. WinRM quickconfig #检查winrm服务是运行
    4. winrs -r:http://hostservername:5985/wsman -u:RDPusername -p:RDPpassword ipconfig/all