Error – Failed to connect to the host via ssh
[root@ip-172-31-12-86 ansible]# ansible all -i inventory -m win_ping
13.233.160.153 | UNREACHABLE! => {
"changed": false,
"msg": "Failed to connect to the host via ssh: ssh: connect to host 13.233.160.153 port 22: Connection refused",
"unreachable": true
}Code language: PHP (php)
Solution – You need to set ansible_connection=winrm to connect to windows
[windows]
13.233.160.153
[windows:vars]
ansible_connection=winrm
Error – auth method ssl requires a username
[root@ip-172-31-12-86 ansible]# ansible all -i inventory -m win_ping
13.233.160.153 | UNREACHABLE! => {
"changed": false,
"msg": "ssl: auth method ssl requires a username",
"unreachable": true
}Code language: PHP (php)
Solution – You need to set ansible_user and ansible_password to connect to windows remote
[windows]
13.233.160.153
[windows:vars]
ansible_connection=winrm
ansible_user=administrator
ansible_password=”w$y%O.ubjQhQhfa&ME@5=TeEd4Yhfy”ansible_winrm_scheme=http
ansible_winrm_scheme=https
#Reference
https://docs.ansible.com/ansible/latest/user_guide/windows_winrm.html
Error – certificate verify failed
[root@ip-172-31-12-86 ansible]# ansible all -i inventory -m win_ping
13.233.160.153 | UNREACHABLE! => {
"changed": false,
"msg": "ssl: HTTPSConnectionPool(host='13.233.160.153', port=5986): Max retries exceeded with url: /wsman (Caused by SSLError(SSLError(1, u'[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:579)'),))",
"unreachable": true
}Code language: PHP (php)
Solution – You need to set ansible_winrm_transport=basic and ansible_winrm_server_cert_validation=ignore
[windows]
13.233.160.153
[windows:vars]
ansible_user=LocalUsername
ansible_password=Password
ansible_connection=winrm
ansible_winrm_transport=basic
ansible_winrm_server_cert_validation=ignore
winrm set winrm/config/client/auth '@{Basic="true"}'
winrm set winrm/config/service/auth '@{Basic="true"}'
Set-Item -Path WSMan:\localhost\Service\Auth\Basic -Value $true
winrm set winrm/config/service/auth '@{Basic="true"}'
winrm set winrm/config/service '@{AllowUnencrypted="true"}'
ansible_user=Administrator
ansible_password=Raju$123456
ansible_connection=winrm
ansible_winrm_transport=basic
ansible_winrm_scheme=http
ansible_winrm_server_cert_validation=ignore
ansible_port=5985
Code language: PHP (php)
I’m Rajesh Kumar, a DevOps, SRE, DevSecOps, Cloud, and Platform Engineering expert passionate about sharing practical knowledge, real-world experiences, and industry best practices. I have worked at Cotocus and regularly write about technology, travel, investing, health, product reviews, and digital marketing through my various platforms.
I publish technical articles at DevOps School, travel stories at Holiday Landmark, stock market insights at Stocks Mantra, health and fitness guidance at My Medic Plus, product reviews at TrueReviewNow, and SEO and digital marketing strategies at Wizbrand.
Find Trusted Cardiac Hospitals
Compare heart hospitals by city and services โ all in one place.
Explore Hospitals
Thanks Author. THis article helped me overcome the issue.
God bless you and your family