Unreachable : Failed to connect to the host via ssh

Dear All,

I have created my RHEL 8, AWS EC2 instances and Windows 2019 AWS EC2 instance

And, have installed Ansible and followed the prerequisites on control node.

Equally I have created user and ran the script https://raw.githubusercontent.com/ansible/ansible/devel/examples/scripts/**ConfigureRemotingForAnsible.ps1** from windows machine.

Also installed Pywinrm on control node and updated inventory file carefully as below:

[winhost:vars]
ansible_user=mahesh
ansible_password=password
ansible_connection=winrm
ansible_winrm_server_cert_validation=ignore

Now when I start ping my windows machine it is returning me an error: -

UNREACHABLE! => {
“changed”: false,
“msg”: “Failed to connect to the host via ssh: ssh: connect to host XX.XX.XX.XX port 22: Connection timed out”,
“unreachable”: true

}

Though I mentioned the host vars section is: ansible_winrm_server_cert_validation=ignore, it is still checking ssh and kept on faily.

I request can someone suggest in this regards

Thank you very much in advance for your suggestions!

  • Is this your entire inventory file? If not please post that
  • What is the actual command you used to “ping” the windows machine?

Thanks for your response!

Entire Inventory file -

[windows]
XX.XX.XX.XX

[winhost:vars]
ansible_user=mahesh
ansible_password=India@1234
ansible_connection=winrm
ansible_winrm_server_cert_validation=ignore

Command used to ping windows servers -

ansible windows -m win_ping

You have defined the vars for the group ‘winhost’ but have defined the host in the group ‘windows’. That’s why the connection and other vars are not being applied to the host when running.

Thanks a ton, it’s a great clue.

I confirm now my windows server is started responding from Ansible.

Ping = Success.

Thanks again!