# On Windows, how can we configure Ansible's modules to go through an HTTP Proxy?

**URL:** <https://forum.ansible.com/t/on-windows-how-can-we-configure-ansibles-modules-to-go-through-an-http-proxy/23751>\
**Category:** Ansible Project\
**Tags:** windows\
**Created:** [February 16, 2017, 10:26pm UTC](https://forum.ansible.com/t/on-windows-how-can-we-configure-ansibles-modules-to-go-through-an-http-proxy/23751 "2017-02-16T22:26:19Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![JS1](https://avatars.discourse-cdn.com/v4/letter/j/51bf81/32.png) [@JS1](https://forum.ansible.com/u/JS1)\
**Post date:** [February 16, 2017, 10:26pm UTC](https://forum.ansible.com/t/on-windows-how-can-we-configure-ansibles-modules-to-go-through-an-http-proxy/23751/1 "2017-02-16T22:26:19Z")

</div>

As per [this post on the Ansible Github](https://github.com/ansible/ansible/issues/21506), how can Ansible be configured to run through an HTTP proxy?

Ultimately it is ideal to use the win\_chocolatey module through the proxy, but I’m unable to just run a simple curl (i.e curl [http://www.google.com](http://www.google.com)) through win\_shell.

---

<div class="post-metadata">

**Author:** ![JS1](https://avatars.discourse-cdn.com/v4/letter/j/51bf81/32.png) [@JS1](https://forum.ansible.com/u/JS1)\
**Post date:** [February 16, 2017, 11:21pm UTC](https://forum.ansible.com/t/on-windows-how-can-we-configure-ansibles-modules-to-go-through-an-http-proxy/23751/2 "2017-02-16T23:21:27Z")

</div>

From Github:

##### SUMMARY

Ansible modules executed on a Windows host are unable to access the internet via an HTTP Proxy. Ideally modules would function similarly to setting the environment on Linux hosts, i.e

```auto

environment:
   http_proxy: http://gateway:port
   https_proxy: http://gateway:port

```

The following workarounds have been attempted:

- Making changes to the Registry (i.e HKCU:Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyServer)
- Using netsh (i.e `netsh winhttp set proxy proxy-server="http://gateway:port"`)
- Setting the environment variable in cmd.exe, then running Curl as suggested [here](https://sites.google.com/site/softwaretechforge/Downhome/Programminglanguage/sethttpproxydoesntworkinpowershell). For example:

```auto

- name: Fire and forget iexplore.exe 
  win_shell: set HTTP_PROXY=http://management-gateway.c.ansible-proj.internal:3128 & powershell.exe curl http://www.google.com
  args:
    executable: cmd

```

- Simulating a new session on the Windows host by starting notepad.exe, setting the registry, then attempting Curl (see below playbook)

**NOTE:** The local administrator account is being used and a formal session via RDP is never initiated.

##### STEPS TO REPRODUCE

Attempt to `curl` an external website via `win_shell`. Some examples:

``

`ansible windows-host -i inventory-file -m win_shell -a "curl http://www.google.com"`

``

` `

- name: run  
hosts: windows-host  
tasks:
- name: Fire and forget notepad.exe  
win\_shell: notepad.exe  
args:  
exectable: cmd  
async: 60  
poll: 0
- name: Set registry  
win\_shell: “{{ item }}”  
with\_items: - set-itemproperty -path “hkcu:Software\Microsoft\Windows\CurrentVersion\Internet Settings” -name ProxyServer -value "http=gateway:port;https=gateway:port; -type string
- set-itemproperty -path “hkcu:Software\Microsoft\Windows\CurrentVersion\Internet Settings” -name ProxyEnable -value “1”
- name: Run curl  
win\_shell: curl [http://www.google.com](http://www.google.com)  
register: result

`

```auto

```

`  
``

---

<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:** [February 28, 2017, 1:54pm UTC](https://forum.ansible.com/t/on-windows-how-can-we-configure-ansibles-modules-to-go-through-an-http-proxy/23751/3 "2017-02-28T13:54:42Z")

</div>

There is some discussion here on this issue that might relevant to the issue you are having:  
[https://github.com/diyan/pywinrm/issues/110](https://github.com/diyan/pywinrm/issues/110)

Hope this helps,

Jon

---

<div class="post-metadata">

**Author:** ![mhaswell.london](https://avatars.discourse-cdn.com/v4/letter/m/2bfe46/32.png) [@mhaswell.london](https://forum.ansible.com/u/mhaswell.london)\
**Post date:** [March 6, 2017, 2:14pm UTC](https://forum.ansible.com/t/on-windows-how-can-we-configure-ansibles-modules-to-go-through-an-http-proxy/23751/4 "2017-03-06T14:14:00Z")

</div>

I’ve just been through this exact thing for 2 annoying days. You’re not going to like the answer.

Despite setting the proxy through the registry - and I could see it in there using ansible debug tasks - it didn’t actually apply the proxy setting until I logged in through interactive RDP, using the same account.

No idea how to do this automatically - and I now face having to set the proxy and then log into every windows system we own. ☹

Any ideas on automating this would be helpful.
