如何使用openSSH和Ansible连接到WIndows节点?

时间:2017-08-15 15:22:30

标签: windows ssh ansible openssh

我正在尝试使用OpenSSH和Ansible连接到我的Windows计算机 我能够使用常规ssh进行连接,但是当我尝试使用Ansible进行连接时,每次更改内容时都会出现相同的错误。

我还尝试以root身份运行Ansible,但仍然没有

   fatal: [IVU]: 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 remote directory. Consider changing the remote temp path in ansible.cfg to a path rooted in \"/tmp\". Failed command was: ( umask 77 && mkdir -p \"` echo /tmp/ansible-tmp-1502794936.2073953-164132649383245 `\" && echo ansible-tmp-1502794936.2073953-164132649383245=\"` echo /tmp/ansible-tmp-1502794936.2073953-164132649383245 `\" ), exited with result 1", "unreachable": true}

我试图将ansible.cfg中的ssh_args更改为ssh_args = -o ControlMaster = no并且没有对输出进行任何更改。

我已经尝试将ansible.cfg中的可执行文件更改为C:/Windows/System32/cmd.exe并且出现了同样的错误

我尝试过更改remote_dir = / tmp /但仍然没有。

我的ansible库存是:

[IVU]
IVU ansible_host=**IP**

[IVU:vars]
ansible_port=22
ansible_user=**user**
ansible_ssh_pass=**pass**
ansible_ssh_private_key_file=** Keyfile **

在执行任何任务之前似乎都失败了,但是从Windows计算机上的openssh日志中我看到当ansible连接到它并且当我进入它时没有区别。

3724 09:27:38:720 error: Couldn't create pid file "C:\\Program Files\\OpenSSH\\sshd.pid": Permission denied
3724 09:27:41:376 Accepted publickey for **User** from **IP** port 42700 ssh2: RSA SHA256:clNmiKxygl/TLEb5Ob4lZs6JqztoQyxOsjMoHQ2HYgo
3724 09:27:58:533 Received disconnect from **IP** port 42700:11: disconnected by user
3724 09:27:58:533 Disconnected from user **User** **IP** port 42700
3360 09:28:41:398 error: Couldn't create pid file "C:\\Program Files\\OpenSSH\\sshd.pid": Permission denied
3360 09:28:41:616 Accepted publickey for **User** from **IP** port 42704 ssh2: RSA SHA256:clNmiKxygl/TLEb5Ob4lZs6JqztoQyxOsjMoHQ2HYgo
3360 09:28:41:741 Received disconnect from **IP** port 42704:11: disconnected by user
3360 09:28:41:741 Disconnected from user **User** **IP** port 42704

9:27是我使用ssh连接时,9:28是ansible连接时。

为了让Ansible在Windows上使用openSSH,我是否需要更改?

1 个答案:

答案 0 :(得分:0)

我通过使用反向ssh隧道找到了解决方案。

我放弃了尝试在Windows上使用ssh ansible模块的想法,因为除非你有windows 10更新,否则Windows根本无法很好地使用它。我决定改用winrm ansible模块。

我所做的是通过使用以下命令打开反向SSH隧道,将Windows计算机连接到运行Ansible的计算机:

ssh -p5983 -R 5982:localhost:5986 **my_user**@**my_ip**   

出于我的目的,我不得不向前移动,因为我的电脑与Windows计算机不同 然后在Ansible中我指定主机是端口5982的localhost。

这与使用openssh和windows时的解决方案一样好,至少在Ansible支持windows上的openssh之前。

相关问题