Hello,
There could be a few things not correctly configured or missed that could result into below error:
First and foremost, while installing Ansible, did you resolve dependencies for paramiko, PyYAML, Jinja2 and httplib2 packages? If not, you may execute below commands on the linux machine with Ansible installation.
-
$ sudo pip install paramiko PyYAML Jinja2 httplib2
-
$ pip install “pywinrm>=0.1.1”
-
$ pip install http://github.com/diyan/pywinrm/archive/master.zip#egg=pywinrm
Secondly, verify that the version of Microsoft.NET Framework is 4.0 or later. If not you may follow below steps to get it upgraded.
-
Click on Start → Control Panel → Program and Features → Add or Remove Programs.
-
Scroll down to the M’s and look for Microsoft .NET Framework. If you don’t have version 4.0 or later, download and install it from here “https://www.microsoft.com/en-us/download/details.aspx?id=30653”.
Thirdly, the ansible_user used in windows.yml file should have admin privileges on remote windows machine to make connection to PowerShell. You may follow below steps to grant admin privileges to the user, if not provided already.
-
Click on Start → Control Panel → User Accounts → Manage User Accounts.
-
Select your new account and click on Properties.
-
Click on the Group Membership tab and change the Group Membership from Standard User to Administrator.
-
Click OK, OK and Close. Restart computer.
Note:- The remote computer need not be logged into this account for Ansible to make a remote connection to PowerShell, but the account must exist.
Last but not the least, you need to execute a PowerShell script in order to enable WinRM/PS Remoting. Below are the steps to be followed.
-
Start PowerShell and run the command Set-ExecutionPolicy -ExecutionPolicy Unrestricted
-
Download PowerShell script (named ConfigureRemotingForAnsible.ps1) for enabling WinRM/PSRemoting. You can get the most recent version here:
“https://github.com/ansible/ansible/blob/devel/examples/scripts/ConfigureRemotingForAnsible.ps1”.
-
And then run the PowerShell script :
• powershell.exe -File ConfigureRemotingForAnsible.ps1
Pass the -CertValidityDays option to customize the expiration date of the generated certificate:
• powershell.exe -File ConfigureRemotingForAnsible.ps1 -CertValidityDays 100
Pass the -EnableCredSSP switch to enable CredSSP as an authentication option:
• powershell.exe -File ConfigureRemotingForAnsible.ps1 –EnableCredSSP
Pass the -ForceNewSSLCert switch to force a new SSL certificate to be attached to an already existing winrm listener.
• powershell.exe -File ConfigureRemotingForAnsible.ps1 –ForceNewSSLCert
Pass the -SkipNetworkProfileCheck switch to configure winrm to listen on PUBLIC zone interfaces.
• powershell.exe -File ConfigureRemotingForAnsible.ps1 –SkipNetworkProfileCheck
Additionally the -Verbose option can be used to get more information on screen about what it is doing
• powershell.exe -File ConfigureRemotingForAnsible.ps1 –Verbose
Output of this command should be like this:
VERBOSE: Verifying WinRM service.
VERBOSE: PS Remoting is already enabled.
VERBOSE: SSL listener is already active.
VERBOSE: Basic auth is already enabled.
VERBOSE: Firewall rule already exists to allow WinRM HTTPS.
VERBOSE: HTTP: Enabled | HTTPS: Enabled
VERBOSE: PS Remoting has been successfully configured for Ansible.
-
Run the PowerShell command Set-ExecutionPolicy -ExecutionPolicy Restricted.
-
Close PowerShell.
If all of the above steps are performed correctly, you should get a successful ping-pong from your remote windows node.
Thanks
Soniya