[英]Ansible fails to connect from Linux to Windows via SSH
我已經在 choco 上設置了 Windows 10 機器和 OpenSSH 8.0.0.1,如此處所述。 我已經設置了一個公鑰,現在我可以從我的 Linux 機器連接到 Windows。
$ ssh windows-machine echo test
test
運行以下命令將導致錯誤:
$ ansible -m win_command -a "echo test" windows-machine
windows-machine | 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 ~/.ansible/tmp `\"&& mkdir \"` echo ~/.ansible/tmp/ansible-tmp-1619774767.22-15575-62648242524392 `\" && echo ansible-tmp-1619774767.22-15575-62648242524392=\"` echo ~/.ansible/tmp/ansible-tmp-1619774767.22-15575-62648242524392 `\" ), exited with result 1",
"unreachable": true
}
這些是當前目錄中的文件:
$ ls
ansible.cfg hosts
$ cat ansible.cfg
[defaults]
inventory = ./hosts
ansible_connection = ssh
ansible_shell_type = powershell
$ cat hosts
windows-machine
我已經將 windows 上的默認 shell 設置為 powershell。 我還使用 cmd 作為默認 shell 對其進行了測試,但這並沒有改變任何東西。 錯誤仍然存在。
我已將 ansible 更新到最新版本:
pip3 install --user --upgrade pip
pip3 install --user ansible
hash -r
現在我得到了:
$ ansible --version
ansible 2.10.8
config file = /home/user/git/ansible-win/ansible.cfg
configured module search path = ['/home/user/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/user/.local/lib/python3.6/site-packages/ansible
executable location = /home/user/.local/bin/ansible
python version = 3.6.9 (default, Jan 26 2021, 15:33:00) [GCC 8.4.0]
使用-vvv
運行相同的命令:
$ ansible -m win_command -vvv -a "echo test" windows-machine
給出了我保存到pastebin的以下 output
關鍵部分beeing: <windows-machine> (1, '', '/bin/sh: Die Benennung "/bin/sh" wurde nicht als Name eines Cmdlet, einer Funktion, einer Skriptdatei oder eines \r\nausf\x81hrbaren Programms erkannt.
我看過:
缺少的部分是ansible.cfg
文件中的選項ansible_shell_type=powershell
和shell_type=powershell
被命令行 ansible 調用忽略。
命令行需要選項--extra-vars
或短版本-e
來告訴 shell 需要使用什么。
So with a windows machine where calling ssh windows-machine
from the linux machine is working, this windows machine configured with a default shell set to powershell and the following files on the linux machine:
$ ls
ansible.cfg hosts
$ cat ansible.cfg
[defaults]
inventory = ./hosts
$ cat hosts
windows-machine
我得到這個結果:
$ ansible -m win_ping -e 'ansible_shell_type=powershell' windows-machine
windows-machine | SUCCESS => {
"changed": false,
"ping": "pong"
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.