简体   繁体   中英

How to fix “Unreachable” when ping windows with ansible over ssh?

I'm trying to use Ansible with ssh for interact with Windows machines

i have successfully install OpenSSH on a Windows machine that mean i can connect from linux to windows with:

 ssh username@ipAdresse

i've tried using a lot of version of ansible (2.6, 2.7.12, 2.7.14, 2.8.5 and 2.8.6) and i always test if i can ping an other Linux machine with this line(it work):

ansible linux -m ping

There is my hosts file

[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

there is the error with verbose:

[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
}

I don't know what i'm doing wrong, i also try to change the remote_tmp in ansible.cfg but nothing more.

Actual value for remote_tmp=C:/Users/root/AppData/Local/Temp

Any idea?

To use SSH as the connection to a Windows host (starting from Ansible 2.8), set the following variables in the inventory:

  • ansible_connection=ssh
  • ansible_shell_type =cmd/powershell (Set either cmd or powershell not both)

Finally, the inventory file:

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

[all:vars]
ansible_connection=ssh
ansible_user=root

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

Note for the variable ansible_password . Use single quotation for password with special characters.

Ok solved, the problem was

ansible_ssh_pass=*****

the correct syntax is

ansible_password=*****

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM