【问题标题】:How to connect to WIndows node using openSSH and Ansible?如何使用 openSSH 和 Ansible 连接到 WIndows 节点?
【发布时间】:2018-01-23 13:28:50
【问题描述】:

我正在尝试使用 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 连接到它和我 ssh 进入它时没有区别。

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 一起工作,我是否缺少一些需要更改的东西?

【问题讨论】:

    标签: windows ssh ansible openssh


    【解决方案1】:

    我想出了一个使用反向 ssh 隧道的解决方案。

    我放弃了尝试在 windows 中使用 ssh ansible 模块的想法,因为除非您有 windows 10 更新,否则 windows 不能很好地使用它。我决定改用 winrm ansible 模块。

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

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

    出于我的目的,我必须进行端口转发,因为我的计算机与 windows 计算机位于单独的 vlan 上
    然后在 Ansible 中我指定主机是 localhost 的 5982 端口。

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

    【讨论】:

      猜你喜欢
      • 2016-01-25
      • 1970-01-01
      • 1970-01-01
      • 2021-07-11
      • 2021-01-13
      • 1970-01-01
      • 1970-01-01
      • 2019-09-10
      • 1970-01-01
      相关资源
      最近更新 更多