首页 > 解决方案 > 在 Linux 控制器上使用 Ansible 通过 ssh 管理 Windows 主机?

问题描述

Ansible v2.11.1

我在我的 Windows 主机上安装了 OpenSSH,并且正确设置了我的 SSH 密钥。因此,我可以通过 ssh 从我的 Linux 节点连接到我的 Windows 10 节点,这意味着它可以在不提示输入密码的情况下工作。

$ ssh jenkins@10.123.45.67

我有以下库存和 group_var 文件

inventory/windows.yaml
----------------------
[windows10]
windows-10-os-only ansible_host=10.123.45.67

group_vars/windows10.yaml
-------------------------
---
ansible_user: "jenkins"
ansible_connection: "ssh"

我收到以下临时命令错误。我错过了什么?注意我可以使用 WinRM 完成这项工作,但我正在尝试使用 SSH,因此我不必存储用户名/密码凭据。

$ ansible -i inventory/windows.yaml windows-10-os-only -m win_ping -vvv
ansible [core 2.11.1] 
  config file = /home/jenkins/ansible-test/ansible.cfg
  configured module search path = ['/home/jenkins/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/jenkins/.local/lib/python3.8/site-packages/ansible
  ansible collection location = /home/jenkins/.ansible/collections:/usr/share/ansible/collections
  executable location = /home/jenkins/.local/bin/ansible
  python version = 3.8.0 (default, Feb 25 2021, 22:10:10) [GCC 8.4.0]
  jinja version = 2.10
  libyaml = False
Using /home/jenkins/ansible-test/ansible.cfg as config file
host_list declined parsing /home/jenkins/ansible-test/inventory/windows.yaml as it did not pass its verify_file() method
script declined parsing /home/jenkins/ansible-test/inventory/windows.yaml as it did not pass its verify_file() method
Parsed /home/jenkins/ansible-test/inventory/windows.yaml inventory source with ini plugin
Skipping callback 'default', as we already have a stdout callback.
Skipping callback 'minimal', as we already have a stdout callback.
Skipping callback 'oneline', as we already have a stdout callback.
META: ran handlers
<10.227.26.78> ESTABLISH SSH CONNECTION FOR USER: jenkins
<10.227.26.78> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o 'User="jenkins"' -o ConnectTimeout=10 -o ControlPath=/home/jenkins/.ansible/cp/4d20c11b7a 10.227.26.78 '/bin/sh -c '"'"'( umask 77 && mkdir -p "` echo c:\jenkins\tmp `"&& mkdir "` echo c:\jenkins\tmp/ansible-tmp-1622667580.5927646-3243-198782318105723 `" && echo ansible-tmp-1622667580.5927646-3243-198782318105723="` echo c:\jenkins\tmp/ansible-tmp-1622667580.5927646-3243-198782318105723 `" ) && sleep 0'"'"''
<10.227.26.78> (1, b'', b'The system cannot find the path specified.\r\n')
<10.227.26.78> Failed to connect to the host via ssh: The system cannot find the path specified.
windows-10-os-only | UNREACHABLE! => {
    "changed": false,
    "msg": "Failed to create temporary directory.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\", for more error information use -vvv. Failed command was: ( umask 77 && mkdir -p \"` echo c:\\jenkins\\tmp `\"&& mkdir \"` echo c:\\jenkins\\tmp/ansible-tmp-1622667580.5927646-3243-198782318105723 `\" && echo ansible-tmp-1622667580.5927646-3243-198782318105723=\"` echo c:\\jenkins\\tmp/ansible-tmp-1622667580.5927646-3243-198782318105723 `\" ), exited with result 1",
    "unreachable": true
}

标签: ansible

解决方案


推荐阅读