【问题标题】:How to fix "Unreachable" when ping windows with ansible over ssh?使用ansible over ssh ping windows时如何修复“无法访问”?
【发布时间】:2019-10-23 14:58:38
【问题描述】:

我正在尝试使用 Ansible 和 ssh 与 Windows 机器交互

我已在 Windows 机器上成功安装 OpenSSH,这意味着我可以通过以下方式从 linux 连接到 windows:

 ssh username@ipAdresse

我尝试过使用很多版本的 ansible(2.6、2.7.12、2.7.14、2.8.5 和 2.8.6)并且我总是测试我是否可以用这条线 ping 另一台 Linux 机器(它工作):

ansible linux -m ping

有我的主机文件

[windows]
192.***.***.***

[linux]
192.***.***.***

[all:vars]
ansible_connection=ssh
ansible_user=root

[windows:vars]
ansible_ssh_pass=*******
remote_tmp=C:\Users\root\AppData\Local\Temp\
become_method=runas

有详细的错误:

[root@oel76-template ~]# ansible windows -m win_ping -vvv

ansible 2.8.6
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/site-packages/ansible
  executable location = /usr/bin/ansible
  python version = 2.7.5 (default, Aug  7 2019, 08:19:52) [GCC 4.8.5 20150623 (Red Hat 4.8.5-39.0.1)]
Using /etc/ansible/ansible.cfg as config file
host_list declined parsing /etc/ansible/hosts as it did not pass it's verify_file() method
script declined parsing /etc/ansible/hosts as it did not pass it's verify_file() method
auto declined parsing /etc/ansible/hosts as it did not pass it's verify_file() method
Parsed /etc/ansible/hosts inventory source with ini plugin
META: ran handlers
<192.***.***.***> ESTABLISH SSH CONNECTION FOR USER: root
<192.***.***.***> SSH: EXEC sshpass -d8 ssh -C -o ControlMaster=auto -o ControlPersist=60s -o 'User="root"' -o ConnectTimeout=10 -o ControlPath=/root/.ansible/cp/91df1ca379 192.168.46.99 '/bin/sh -c '"'"'( umask 77 && mkdir -p "` echo C:/Users/root/AppData/Local/Temp/ansible-tmp-1571839448.66-279092717123794 `" && echo ansible-tmp-1571839448.66-279092717123794="` echo C:/Users/root/AppData/Local/Temp/ansible-tmp-1571839448.66-279092717123794 `" ) && sleep 0'"'"''
<192.***.***.***> (1, '', 'The system cannot find the path specified.\r\n')
<192.***.***.***> Failed to connect to the host via ssh: The system cannot find the path specified.

192.***.***.*** | UNREACHABLE! => {
"changed": false,
    "msg": "Authentication or permission failure. In some cases, you may have been able to authenticate and did not have permissions on the target directory. Consider changing the remote tmp path in ansible.cfg to a path rooted in \"/tmp\". Failed command was: ( umask 77 && mkdir -p \"` echo C:/Users/root/AppData/Local/Temp/ansible-tmp-1571839448.66-279092717123794 `\" && echo ansible-tmp-1571839448.66-279092717123794=\"` echo C:/Users/root/AppData/Local/Temp/ansible-tmp-1571839448.66-279092717123794 `\" ), exited with result 1",
    "unreachable": true
}

我不知道自己做错了什么,我也尝试更改 ansible.cfg 中的 remote_tmp 但仅此而已。

remote_tmp=C:/Users/root/AppData/Local/Temp 的实际值

有什么想法吗?

【问题讨论】:

  • 请问可以使用哪个版本的 OpenSSH 吗?我安装了可在 Windows Server 2019 中默认安装的 Microsoft OpenSSH 分支,但我没有成功...我可以从远程 shell 连接,但无法从 Ansilble 连接,即使下面有您和 ariwk 的注释,或者跟随其他指南

标签: windows ssh ansible


【解决方案1】:

要使用 SSH 作为与 Windows 主机的连接(从 Ansible 2.8 开始),请在清单中设置以下变量:

  • ansible_connection=ssh
  • ansible_shell_type=cmd/powershell(设置为 cmd 或 powershell,不能同时设置)

最后是库存文件:

[windows]
192.***.***.***

[all:vars]
ansible_connection=ssh
ansible_user=root

[windows:vars]
ansible_password='*******'
ansible_shell_type=cmd

注意变量 ansible_password。对带有特殊字符的密码使用单引号。

【讨论】:

  • ssh 是 Ansible 中的默认连接类型,因此 ansible_connection=ssh 在这里不是绝对必要的,即使对于 Windows 主机也是如此
【解决方案2】:

好的,问题解决了

ansible_ssh_pass=*****

正确的语法是

ansible_password=*****

【讨论】:

  • 兄弟我有同样的问题我已经做了你所做的仍然存在。
猜你喜欢
  • 1970-01-01
  • 2017-04-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-12-21
  • 1970-01-01
  • 2018-02-09
  • 2014-08-31
相关资源
最近更新 更多