# delegate\_to and winrm is broken

**URL:** <https://forum.ansible.com/t/delegate-to-and-winrm-is-broken/22788>\
**Category:** Ansible Project\
**Tags:** windows\
**Created:** [October 13, 2016, 8:15pm UTC](https://forum.ansible.com/t/delegate-to-and-winrm-is-broken/22788 "2016-10-13T20:15:31Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Stephen\_Bunn](https://avatars.discourse-cdn.com/v4/letter/s/4da419/32.png) [@Stephen\_Bunn](https://forum.ansible.com/u/Stephen_Bunn)\
**Post date:** [October 13, 2016, 8:15pm UTC](https://forum.ansible.com/t/delegate-to-and-winrm-is-broken/22788/1 "2016-10-13T20:15:31Z")

</div>

It seems that it is impossible to run a local task when talking to windows hosts. This is pretty much a show stopper for my current use case of Ansbile.

ansible version: ansible 2.1.1.0

using any of the following, all result in the same error

- name: deploy some stuff  
hosts: somewindowshosts  
gather\_facts: True  
serial: 1  
pre\_tasks:
- name: disable {{ inventory\_hostname }} from LB  
delegate\_to: localhost  
connection: local  
command: /usr/bin/magic\_lb\_removal\_script  
#local\_action: command foo  
#delegate\_to: 127.0.0.1  
roles:
- { role: foo }
- { role: bar }

ESTABLISH WINRM CONNECTION FOR USER: Administrator on PORT 5985 TO localhost  
fatal: [172.28.18.158]: UNREACHABLE! =\> {“changed”: false, “msg”: “plaintext: HTTPConnectionPool(host=‘localhost’, port=5985): Max retries exceeded with url: /wsman (Caused by NewConnectionError(‘\<requests.packages.urllib3.connection.HTTPConnection object at 0x21aa610\>: Failed to establish a new connection: [Errno 111] Connection refused’,))”, “unreachable”: true}

---

<div class="post-metadata">

**Author:** ![Matt\_Davis](https://avatars.discourse-cdn.com/v4/letter/m/ce7236/32.png) [@Matt\_Davis](https://forum.ansible.com/u/Matt_Davis)\
**Post date:** [October 14, 2016, 12:22am UTC](https://forum.ansible.com/t/delegate-to-and-winrm-is-broken/22788/2 "2016-10-14T00:22:02Z")

</div>

I suspect you may have an inventory or command issue that’s reassigning localhost’s connection type to winrm (you’re not adding -c winrm, are you?) - this sample works fine for me on both 2.1.1 and devel. The connection: local is not necessary, and works fine for me with either local\_action or delegate\_to: localhost.

There are definitely some issues with cross-connection delegation with pseudo-connection-var rewriting when going the other way (delegating from Linux hosts to Windows), but this one looks like a busted inventory to me.

---

<div class="post-metadata">

**Author:** ![Stephen\_Bunn](https://avatars.discourse-cdn.com/v4/letter/s/4da419/32.png) [@Stephen\_Bunn](https://forum.ansible.com/u/Stephen_Bunn)\
**Post date:** [October 18, 2016, 5:26pm UTC](https://forum.ansible.com/t/delegate-to-and-winrm-is-broken/22788/3 "2016-10-18T17:26:17Z")

</div>

I’m not sure how. Can you provide a complete working example? My inventory file is pretty straight forward. My inventory looks like this

[box1]  
ip.address

[box2]  
another.ip.address

[alpha:children]  
ip.address

[beta:children]  
another.ip.address

[somewindowshosts]  
alpha  
beta

---

<div class="post-metadata">

**Author:** ![Matt\_Davis](https://avatars.discourse-cdn.com/v4/letter/m/ce7236/32.png) [@Matt\_Davis](https://forum.ansible.com/u/Matt_Davis)\
**Post date:** [October 18, 2016, 5:39pm UTC](https://forum.ansible.com/t/delegate-to-and-winrm-is-broken/22788/4 "2016-10-18T17:39:00Z")

</div>

Where are you setting the connection types to winrm then?

---

<div class="post-metadata">

**Author:** ![Stephen\_Bunn](https://avatars.discourse-cdn.com/v4/letter/s/4da419/32.png) [@Stephen\_Bunn](https://forum.ansible.com/u/Stephen_Bunn)\
**Post date:** [October 19, 2016, 12:54am UTC](https://forum.ansible.com/t/delegate-to-and-winrm-is-broken/22788/5 "2016-10-19T00:54:35Z")

</div>

It is being include in a group\_var for the hosts, is there a better way to do this?
