# Ansible to windows client connection

**URL:** <https://forum.ansible.com/t/ansible-to-windows-client-connection/29463>\
**Category:** Ansible Project\
**Tags:** windows\
**Created:** [January 18, 2019, 12:29pm UTC](https://forum.ansible.com/t/ansible-to-windows-client-connection/29463 "2019-01-18T12:29:42Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![sindhu\_shree](https://avatars.discourse-cdn.com/v4/letter/s/b5e925/32.png) [@sindhu\_shree](https://forum.ansible.com/u/sindhu_shree)\
**Post date:** [January 18, 2019, 12:29pm UTC](https://forum.ansible.com/t/ansible-to-windows-client-connection/29463/1 "2019-01-18T12:29:42Z")

</div>

Hi.  
Am facing some authentication issues when i run ansible all -m win\_ping. Response - 10.67.104.45 | UNREACHABLE! =\> {  
“changed”: false,  
“msg”: “basic: the specified credentials were rejected by the server”,  
“unreachable”: true  
}

The user which am trying to connect is administrator user. I followed some steps to add user and change the permissions using

winrm configSDDL default, but no luck.  
Am using basic authentication.

Am new to Linux , i would appreciate if i get any help on this.

---

<div class="post-metadata">

**Author:** ![Dinesh\_Singh](https://avatars.discourse-cdn.com/v4/letter/d/57b2e6/32.png) [@Dinesh\_Singh](https://forum.ansible.com/u/Dinesh_Singh)\
**Post date:** [January 18, 2019, 12:34pm UTC](https://forum.ansible.com/t/ansible-to-windows-client-connection/29463/2 "2019-01-18T12:34:13Z")

</div>

This basically means server rejecting the login. If you have firewall at windows server then allow Linux server to communicate.

With Regards,  
Dinesh Singh  
Email - [dineshpmv06@gmail.com](mailto:dineshpmv06@gmail.com)

---

<div class="post-metadata">

**Author:** ![Dinesh\_Singh](https://avatars.discourse-cdn.com/v4/letter/d/57b2e6/32.png) [@Dinesh\_Singh](https://forum.ansible.com/u/Dinesh_Singh)\
**Post date:** [January 18, 2019, 12:37pm UTC](https://forum.ansible.com/t/ansible-to-windows-client-connection/29463/3 "2019-01-18T12:37:48Z")

</div>

Also enable remote execution policy on your windows server.

With Regards,  
Dinesh Singh  
Email - [dineshpmv06@gmail.com](mailto:dineshpmv06@gmail.com)

---

<div class="post-metadata">

**Author:** ![sindhu\_shree](https://avatars.discourse-cdn.com/v4/letter/s/b5e925/32.png) [@sindhu\_shree](https://forum.ansible.com/u/sindhu_shree)\
**Post date:** [January 18, 2019, 12:41pm UTC](https://forum.ansible.com/t/ansible-to-windows-client-connection/29463/4 "2019-01-18T12:41:39Z")

</div>

which option should i enable? winrm is allowed and no such specific options for linux.

---

<div class="post-metadata">

**Author:** ![Dinesh\_Singh](https://avatars.discourse-cdn.com/v4/letter/d/57b2e6/32.png) [@Dinesh\_Singh](https://forum.ansible.com/u/Dinesh_Singh)\
**Post date:** [January 18, 2019, 12:45pm UTC](https://forum.ansible.com/t/ansible-to-windows-client-connection/29463/5 "2019-01-18T12:45:14Z")

</div>

Follow this once and see if it works

[https://www.ansible.com/blog/connecting-to-a-windows-host](https://www.ansible.com/blog/connecting-to-a-windows-host)

With Regards,  
Dinesh Singh  
Email - [dineshpmv06@gmail.com](mailto:dineshpmv06@gmail.com)

---

<div class="post-metadata">

**Author:** ![sindhu\_shree](https://avatars.discourse-cdn.com/v4/letter/s/b5e925/32.png) [@sindhu\_shree](https://forum.ansible.com/u/sindhu_shree)\
**Post date:** [January 18, 2019, 12:47pm UTC](https://forum.ansible.com/t/ansible-to-windows-client-connection/29463/6 "2019-01-18T12:47:17Z")

</div>

Execution policy has set to Unrestricted (Using Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Force), still the same.

---

<div class="post-metadata">

**Author:** ![sindhu\_shree](https://avatars.discourse-cdn.com/v4/letter/s/b5e925/32.png) [@sindhu\_shree](https://forum.ansible.com/u/sindhu_shree)\
**Post date:** [January 18, 2019, 12:50pm UTC](https://forum.ansible.com/t/ansible-to-windows-client-connection/29463/7 "2019-01-18T12:50:58Z")

</div>

I followed this article and also ansible windows doc.

---

<div class="post-metadata">

**Author:** ![Rahamath](https://avatars.discourse-cdn.com/v4/letter/r/db5fbb/32.png) [@Rahamath](https://forum.ansible.com/u/Rahamath)\
**Post date:** [January 18, 2019, 2:15pm UTC](https://forum.ansible.com/t/ansible-to-windows-client-connection/29463/8 "2019-01-18T14:15:54Z")

</div>

There is a PS script which will set required winrm settings (auth to basic). You need to run that script on windows host.

---

<div class="post-metadata">

**Author:** ![jborean](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/jborean/32/1525_2.png) [@jborean](https://forum.ansible.com/u/jborean)\
**Post date:** [January 18, 2019, 10:42pm UTC](https://forum.ansible.com/t/ansible-to-windows-client-connection/29463/9 "2019-01-18T22:42:43Z")

</div>

Setting the execution policy or firewall is unrelated to authentication failures. If you really want to use Basic auth make sure you have run the following to enable it on the WIndows host;

`  
Set-Item -Path WSMan:\localhost\Service\Auth\Basic -Value True

`

You can verify what have been enabled and disabled by running ‘winrm get winrm/config/service’. By default Basic auth is not enabled for security reasons.

Thanks

Jordan

---

<div class="post-metadata">

**Author:** ![jborean](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/jborean/32/1525_2.png) [@jborean](https://forum.ansible.com/u/jborean)\
**Post date:** [January 18, 2019, 10:43pm UTC](https://forum.ansible.com/t/ansible-to-windows-client-connection/29463/10 "2019-01-18T22:43:59Z")

</div>

I forgot to mention that running over http (like you are) for basic auth will only work if you have disabled message encryption on the Windows host. Do not do this, do something sane like running over https or use an authentication option that supports message encryption like Kerberos or NTLM.

---

<div class="post-metadata">

**Author:** ![sindhu\_shree](https://avatars.discourse-cdn.com/v4/letter/s/b5e925/32.png) [@sindhu\_shree](https://forum.ansible.com/u/sindhu_shree)\
**Post date:** [January 22, 2019, 9:48am UTC](https://forum.ansible.com/t/ansible-to-windows-client-connection/29463/11 "2019-01-22T09:48:21Z")

</div>

I did that. Am getting some certificate related errors.

I just checked the connection with other windows power shell as follows.

PS C:\Users\sindhu.p\> winrs -r:[https://ipaddress:5986/wsman](https://ipaddress:5986/wsman) -u:username -p:password ipconfig

Error :

Winrs error:The server certificate on the destination computer (10.67.104.45:5986) has the following errors:  
The SSL certificate is signed by an unknown certificate authority.  
The SSL certificate contains a common name (CN) that does not match the hostname.

---

<div class="post-metadata">

**Author:** ![sindhu\_shree](https://avatars.discourse-cdn.com/v4/letter/s/b5e925/32.png) [@sindhu\_shree](https://forum.ansible.com/u/sindhu_shree)\
**Post date:** [January 22, 2019, 9:54am UTC](https://forum.ansible.com/t/ansible-to-windows-client-connection/29463/12 "2019-01-22T09:54:20Z")

</div>

Am trying for https.  
Power shell basic script as follows

$url = “[https://raw.githubusercontent.com/ansible/ansible/devel/examples/scripts/ConfigureRemotingForAnsible.ps1](https://raw.githubusercontent.com/ansible/ansible/devel/examples/scripts/ConfigureRemotingForAnsible.ps1)”  
$file = “$env:temp\ConfigureRemotingForAnsible.ps1”  
$username = “username”  
$password = "password "

Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Force  
$browser = New-Object System.Net.WebClient  
$browser.Proxy.Credentials =[System.Net.CredentialCache]::DefaultNetworkCredentials  
$browser.DownloadFile($url, $file)

# version can be 3.0, 4.0 or 5.1

#&$file -Version 3.0 -Username $username -Password $password -Verbose

#(New-Object -TypeName System.Net.WebClient).DownloadFile($url, $file)

powershell.exe -ExecutionPolicy ByPass -File $file

Setting up a listener :

$selector\_set = @{  
Address = “\*”  
Transport = “HTTPS”  
}  
$value\_set = @{  
CertificateThumbprint = “EF39ECD8A40F83ACC2BE85D95303EED2EB7DCE5C”  
}

New-WSManInstance -ResourceURI “winrm/config/Listener” -SelectorSet $selector\_set -ValueSet $value\_set

And i followed the steps mention here :  
[https://docs.ansible.com/ansible/latest/user\_guide/windows\_setup.html#host-requirements](https://docs.ansible.com/ansible/latest/user_guide/windows_setup.html#host-requirements).

1. Power shell upgrade
2. Hotfix
3. Basic winrm setup
4. Setting up listener

---

<div class="post-metadata">

**Author:** ![sindhu\_shree](https://avatars.discourse-cdn.com/v4/letter/s/b5e925/32.png) [@sindhu\_shree](https://forum.ansible.com/u/sindhu_shree)\
**Post date:** [January 22, 2019, 9:56am UTC](https://forum.ansible.com/t/ansible-to-windows-client-connection/29463/13 "2019-01-22T09:56:40Z")

</div>

I did that. Am getting some certificate related errors.

I just checked the connection with other windows power shell as follows.

PS C:\Users\sindhu.p\> winrs -r:[https://ipaddress:5986/wsman](https://ipaddress:5986/wsman) -u:username -p:password ipconfig

Error :

Winrs error:The server certificate on the destination computer ([10.67.104.45:5986](http://www.google.com/url?q=http%3A%2F%2F10.67.104.45%3A5986&sa=D&sntz=1&usg=AFQjCNGbPspFWnu-c2p7l4Fbl4njC8yq4g)) has the following errors:  
The SSL certificate is signed by an unknown certificate authority.  
The SSL certificate contains a common name (CN) that does not match the hostname.

- show quoted text -

---

<div class="post-metadata">

**Author:** ![sindhu\_shree](https://avatars.discourse-cdn.com/v4/letter/s/b5e925/32.png) [@sindhu\_shree](https://forum.ansible.com/u/sindhu_shree)\
**Post date:** [January 22, 2019, 10:08am UTC](https://forum.ansible.com/t/ansible-to-windows-client-connection/29463/14 "2019-01-22T10:08:51Z")

</div>

How to connect windows client without using user name and password, in linux we can have certificate for password less authentication. How can i achieve the same with windows client?

---

<div class="post-metadata">

**Author:** ![sindhu\_shree](https://avatars.discourse-cdn.com/v4/letter/s/b5e925/32.png) [@sindhu\_shree](https://forum.ansible.com/u/sindhu_shree)\
**Post date:** [January 22, 2019, 10:39am UTC](https://forum.ansible.com/t/ansible-to-windows-client-connection/29463/15 "2019-01-22T10:39:54Z")

</div>

After seeing your suggestion, tried with Kerberos and NTLM

This is what i see

10.67.104.45 | UNREACHABLE! =\> {  
“changed”: false,  
“msg”: “Failed to connect to the host via ssh: OpenSSH\_7.4p1, OpenSSL 1.0.2k-fips 26 Jan 2017\r\ndebug1: Reading configuration data /etc/ssh/ssh\_config\r\ndebug1: /etc/ssh/ssh\_config line 51: Applying options for \*\r\ndebug1: auto-mux: Trying existing master\r\ndebug1: Control socket "/root/.ansible/cp/966bc611a0" does not exist\r\ndebug2: resolving "10.67.104.45" port 22\r\ndebug2: ssh\_connect\_direct: needpriv 0\r\ndebug1: Connecting to 10.67.104.45 [10.67.104.45] port 22.\r\ndebug2: fd 3 setting O\_NONBLOCK\r\ndebug1: connect to address 10.67.104.45 port 22: Connection timed out\r\nssh: connect to host 10.67.104.45 port 22: Connection timed out\r\n”,  
“unreachable”: true  
}

I must be missing something, please guide me where exactly going wrong.
