Thanks for the inputs.
I noticed Event viewer.The WinRM service is not listening for WS-Management requests.
User Action
If you did not intentionally stop the service, use the following command to see the WinRM configuration:
winrm enumerate winrm/config/listener
Let me explain the things what I have done.
1. We provisioned a machine say hostname1, Ran ConfigureAnsibleForRemoting.ps1
2. Took standard image of that machine.
3.Provisioned new machine say hostname2 using that template
4. Noticing this winrm connection refused error randomly.
As per the event viewer, suggestion ran winrm enumerate winrm/config/listener
I see listener running on port 5986 has hostname mentioned as hostname1 . Will that be a reason for these connection issues ?
We are Configuring Ansibleremoting first and then taking image as we could not get an option to run this ConfigureAnsibleForRemoting powershell script at runtime. As these machines are provisioned runtime.