# Cannot connect to WindowsServer from Centos7 ProxyError

**URL:** <https://forum.ansible.com/t/cannot-connect-to-windowsserver-from-centos7-proxyerror/25278>\
**Category:** Ansible Project\
**Tags:** windows\
**Created:** [August 17, 2017, 2:00pm UTC](https://forum.ansible.com/t/cannot-connect-to-windowsserver-from-centos7-proxyerror/25278 "2017-08-17T14:00:45Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Aleksander\_Lipka](https://avatars.discourse-cdn.com/v4/letter/a/9fc348/32.png) [@Aleksander\_Lipka](https://forum.ansible.com/u/Aleksander_Lipka)\
**Post date:** [August 17, 2017, 2:00pm UTC](https://forum.ansible.com/t/cannot-connect-to-windowsserver-from-centos7-proxyerror/25278/1 "2017-08-17T14:00:45Z")

</div>

**Hi**  
I am trying to connect to Windows Server 2012 from my ansible server (Centos7).  
Let’s assume its host is x and port is y  
I managed to connect to other linux based servers but I cannot connect to the windows one.  
I followed the tutorial here: [http://docs.ansible.com/ansible/latest/intro\_windows.html](http://docs.ansible.com/ansible/latest/intro_windows.html) and after all setups and configurations I get the following error:

```auto
root@localhost: ansible# ansible windows -i hosts -m win_ping --ask-vault-pass
Vault password:
WindowsServer | UNREACHABLE! => {
    "changed": false,
    "msg": "ssl: HTTPSConnectionPool(host='x', port=y): Max retries exceeded with url: /wsman (Caused by ProxyError('Cannot connect to proxy.', error('Tunnel connection failed: 403 Forbidden',)))",

```

This is my group\_vars/windows.yml file:

```auto
# it is suggested that these be encrypted with ansible-vault:
# ansible-vault edit group_vars/windows.yml

ansible_user: Administrator
ansible_password: password
ansible_port: y
ansible_connection: winrm

```

This is my hosts file snippet:

```auto
[windows]
WindowsServer ansible_host=x

```

I did configure windows server with this file: [ConfigureRemotingForAnsible.ps1](https://github.com/ansible/ansible/blob/devel/examples/scripts/ConfigureRemotingForAnsible.ps1)

Please help, I have no idea what to do to make the connection work.

I also asked this question here: [https://stackoverflow.com/questions/45716102/ansible-cannot-connect-to-windowsserver-from-centos7](https://stackoverflow.com/questions/45716102/ansible-cannot-connect-to-windowsserver-from-centos7)

---

<div class="post-metadata">

**Author:** ![Mike\_Fennemore](https://avatars.discourse-cdn.com/v4/letter/m/45deac/32.png) [@Mike\_Fennemore](https://forum.ansible.com/u/Mike_Fennemore)\
**Post date:** [August 17, 2017, 5:01pm UTC](https://forum.ansible.com/t/cannot-connect-to-windowsserver-from-centos7-proxyerror/25278/2 "2017-08-17T17:01:21Z")

</div>

A few extra group\_vars:  
ansible\_winrm\_server\_cert\_validation: false and ansible\_port should be a port number not y. It should be 5985 or 5986. You could also use ntlm by adding ansible\_winrm\_transport:ntlm

---

<div class="post-metadata">

**Author:** ![Aleksander\_Lipka](https://avatars.discourse-cdn.com/v4/letter/a/9fc348/32.png) [@Aleksander\_Lipka](https://forum.ansible.com/u/Aleksander_Lipka)\
**Post date:** [August 18, 2017, 7:37am UTC](https://forum.ansible.com/t/cannot-connect-to-windowsserver-from-centos7-proxyerror/25278/3 "2017-08-18T07:37:28Z")

</div>

I know port shouldn’t be y, I just assumed in the example that it’s y.  
Anyway I added ansible\_winrm\_server\_cert\_validation: ignore and ansible\_winrm\_transport: ntlm and still didn’t work.  
However I tried the second port you mentioned: 5985 (I use 5986 as default) and the playbook stopped at gathering facts for longer than usual and returned a different error:

```auto
fatal: [WindowsServer]: UNREACHABLE! => 
{"changed": false, "msg": "ntlm: HTTPConnectionPool(host='161.90.234.10', port=8080): 
Read timed out. (read timeout=30)", "unreachable": true}

```

The IP and the port that you see in the error is actually the proxy that is set in IE in my WindowsServer2012 R2.

Still the connection was rejected, why?

W dniu czwartek, 17 sierpnia 2017 19:01:21 UTC+2 użytkownik Mike Fennemore napisał:

---

<div class="post-metadata">

**Author:** ![j.r.hawkesworth](https://avatars.discourse-cdn.com/v4/letter/j/a3d4f5/32.png) [@j.r.hawkesworth](https://forum.ansible.com/u/j.r.hawkesworth)\
**Post date:** [August 18, 2017, 1:29pm UTC](https://forum.ansible.com/t/cannot-connect-to-windowsserver-from-centos7-proxyerror/25278/4 "2017-08-18T13:29:19Z")

</div>

Please can you try exporting  
HTTP\_PROXY  
or  
HTTPS\_PROXY

environment variables before running ansible?

I _think_ this will let ansible (actually requests via pywinrm) know that you are using a proxy.

Hope this helps,

Jon

---

<div class="post-metadata">

**Author:** ![Aleksander\_Lipka](https://avatars.discourse-cdn.com/v4/letter/a/9fc348/32.png) [@Aleksander\_Lipka](https://forum.ansible.com/u/Aleksander_Lipka)\
**Post date:** [August 18, 2017, 2:10pm UTC](https://forum.ansible.com/t/cannot-connect-to-windowsserver-from-centos7-proxyerror/25278/5 "2017-08-18T14:10:58Z")

</div>

How do I export them?  
When I echo them, I can see:

root@localhost@localdomain: ansible# echo $http\_proxy  
[http://161.90.234.10:8080](http://161.90.234.10:8080)

root@localhost@localdomain: ansible# echo $https\_proxy  
[https://161.90.234.10:8080](https://161.90.234.10:8080)

W dniu piątek, 18 sierpnia 2017 15:29:19 UTC+2 użytkownik J Hawkesworth napisał:

---

<div class="post-metadata">

**Author:** ![Mike\_Klebolt](https://avatars.discourse-cdn.com/v4/letter/m/58956e/32.png) [@Mike\_Klebolt](https://forum.ansible.com/u/Mike_Klebolt)\
**Post date:** [August 18, 2017, 2:20pm UTC](https://forum.ansible.com/t/cannot-connect-to-windowsserver-from-centos7-proxyerror/25278/6 "2017-08-18T14:20:27Z")

</div>

Hi Aleksander,

Try adding no\_proxy= to your ~/.bashrc and reload it. If you will be working with many windows servers in the future, a more permanent solution that worked for me is the following…

1. Locate transport.py that comes with pywinrm2. modify the following line session.trust\_env to make it false.

`

125 # configure proxies from HTTP/HTTPS\_PROXY envvars  
126 # session.trust\_env = True  
127 session.trust\_env = False

`  
3. pywinrm will no longer check your local env for a proxy.

---

<div class="post-metadata">

**Author:** ![Aleksander\_Lipka](https://avatars.discourse-cdn.com/v4/letter/a/9fc348/32.png) [@Aleksander\_Lipka](https://forum.ansible.com/u/Aleksander_Lipka)\
**Post date:** [August 21, 2017, 7:39am UTC](https://forum.ansible.com/t/cannot-connect-to-windowsserver-from-centos7-proxyerror/25278/7 "2017-08-21T07:39:15Z")

</div>

Thanks a lot Mike!!  
Your suggestion works,  
the .bashrc shortcut didn’t work, but then I changed session.trust\_env = True to False in transport.py and ansible made the connection.

W dniu piątek, 18 sierpnia 2017 16:20:27 UTC+2 użytkownik Mike Klebolt napisał:

---

<div class="post-metadata">

**Author:** ![j.r.hawkesworth](https://avatars.discourse-cdn.com/v4/letter/j/a3d4f5/32.png) [@j.r.hawkesworth](https://forum.ansible.com/u/j.r.hawkesworth)\
**Post date:** [August 21, 2017, 8:39am UTC](https://forum.ansible.com/t/cannot-connect-to-windowsserver-from-centos7-proxyerror/25278/8 "2017-08-21T08:39:03Z")

</div>

Ah sorry I had misunderstood, so you wanted _not_ to use your http proxy to connect to winrm.

I am wondeing if, instead of modifying pywinrm’s transport.py you could get it to work by unsetting  
unset HTTP\_PROXY  
unset HTTPS\_PROXY  
in your ./bashrc (or before running ansible)?

This might be preferable otherwise you would have to make the change again if pywinrm gets upgraded.  
Jon

---

<div class="post-metadata">

**Author:** ![Mike\_Klebolt](https://avatars.discourse-cdn.com/v4/letter/m/58956e/32.png) [@Mike\_Klebolt](https://forum.ansible.com/u/Mike_Klebolt)\
**Post date:** [August 21, 2017, 1:35pm UTC](https://forum.ansible.com/t/cannot-connect-to-windowsserver-from-centos7-proxyerror/25278/9 "2017-08-21T13:35:19Z")

</div>

Unsetting it is a possibility or finding where the proxy is getting set in your profile in the first place and removing it from there. I previously attempted to have a task to unset the proxy during each run but it didn’t work. Turns out ansible uses whatever environment that it initially starts with.

In my situation, we had multiple users running ansible against windows servers. That’s why I found it best to just change the transport.py.

[https://groups.google.com/forum/#!searchin/ansible-project/klebolt|sort:relevance/ansible-project/iIsAbZTBubI/duAuT\_jKBAAJ](https://groups.google.com/forum/#!searchin/ansible-project/klebolt%7Csort:relevance/ansible-project/iIsAbZTBubI/duAuT_jKBAAJ)
