# Connection to Windows via winrm

**URL:** <https://forum.ansible.com/t/connection-to-windows-via-winrm/34208>\
**Category:** Ansible Project\
**Tags:** windows\
**Created:** [November 18, 2020, 8:07pm UTC](https://forum.ansible.com/t/connection-to-windows-via-winrm/34208 "2020-11-18T20:07:21Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lukasz1](https://avatars.discourse-cdn.com/v4/letter/l/5f9b8f/32.png) [@Lukasz1](https://forum.ansible.com/u/Lukasz1)\
**Post date:** [November 18, 2020, 8:07pm UTC](https://forum.ansible.com/t/connection-to-windows-via-winrm/34208/1 "2020-11-18T20:07:21Z")

</div>

Hello, I am having trouble connecting ansible via winrm. Something is wrongly defined and ansible connects to windows via ssh.  
( more [https://dpaste.org/6LdQ](https://dpaste.org/6LdQ) )

Where else can I look for problems?  
…

- ansible-playbook -vvv -i ~/.ansible/group\_vars/ldap\_inventory.yaml ~/.ansible/playbook/zabbix-agent.a.yml  
…  
fatal: [ansible-win.leme.lcl]: UNREACHABLE! =\> {

- “changed”: false,

- “msg”: “Failed to connect to the host via ssh: ssh: connect to host ansible-win.leme.lcl port 22: Connection timed out”,

- “unreachable”: true

- }  
…

- ansible ansible-win.leme.lcl -m debug -a “var=ansible\_connection”

- ansible-win.leme.lcl | SUCCESS =\> {

- “ansible\_connection”: “winrm”

- }

- ​

* * *

- ​
- ansible -v ansible-win.leme.lcl -m ansible.windows.win\_ping
- Using /home/ansible/.ansible/ansible.cfg as config file
- ansible-win.leme.lcl | SUCCESS =\> {
- “changed”: false,
- “ping”: “pong”
- }  
…

---

<div class="post-metadata">

**Author:** ![Jerin\_J](https://avatars.discourse-cdn.com/v4/letter/j/34f0e0/32.png) [@Jerin\_J](https://forum.ansible.com/u/Jerin_J)\
**Post date:** [November 18, 2020, 9:36pm UTC](https://forum.ansible.com/t/connection-to-windows-via-winrm/34208/2 "2020-11-18T21:36:36Z")

</div>

How did you define your group vars ? Are you using both windows and Linux servers and defined connection in vars in all vars ?? If so you need to segregate the vars per group …

Simple solution would be to have connection details in your host file …let’s say -i inventory/environment/host or environment.ini  
In environment.ini  
[Environment]  
Server ansible-connection=winrm winrm port=5986 …etc .  
Define this here instead of defining it at vars if you using both windows and \*nix servers

---

<div class="post-metadata">

**Author:** ![Lukasz1](https://avatars.discourse-cdn.com/v4/letter/l/5f9b8f/32.png) [@Lukasz1](https://forum.ansible.com/u/Lukasz1)\
**Post date:** [November 19, 2020, 6:21am UTC](https://forum.ansible.com/t/connection-to-windows-via-winrm/34208/3 "2020-11-19T06:21:19Z")

</div>

In ~/.ansible/group\_vars/

i have a file named firma\_city\_dit\_test.yml  
with content:

ansible\_connection: winrm  
ansible\_port: 5986  
ansible\_user: ansible  
ansible\_winrm\_scheme: https  
ansible\_password: \*\*\*\*\*  
ansible\_winrm\_transport: kerberos  
ansible\_winrm\_server\_cert\_validation: ignore

now there really is a problem

ansible-inventory all -i ~/.ansible/group\_vars/ldap\_inventory.yaml --list  
{  
“\_meta”: {  
“hostvars”: {}  
},  
“all”: {  
“children”: [  
“firma”,  
“ungrouped”  
]  
},  
“firma”: {  
“children”: [  
“firma\_city”  
]  
},  
“firma\_city”: {  
“children”: [  
“firma\_city\_dit”  
]  
},  
“firma\_city\_dit”: {  
“children”: [  
“firma\_city\_dit\_test”  
]  
},  
“firma\_city\_dit\_test”: {  
“hosts”: [  
“ansible-win.leme.lcl”  
]  
}  
}

---

<div class="post-metadata">

**Author:** ![Lukasz1](https://avatars.discourse-cdn.com/v4/letter/l/5f9b8f/32.png) [@Lukasz1](https://forum.ansible.com/u/Lukasz1)\
**Post date:** [November 19, 2020, 9:23am UTC](https://forum.ansible.com/t/connection-to-windows-via-winrm/34208/4 "2020-11-19T09:23:28Z")

</div>

Thank you for your answer and hints.

Complete the data [https://dpaste.org/vHS2](https://dpaste.org/vHS2)

The main ansible file i have in ~/ansible.cfg

The inventory of hosts is automatic so what would I enter in the “inventory” option in ansible.cfg

I’d like the variables to be included in group\_vars, how do I define an ansible.cfg ?

I save a file in group\_vars with content :  
all:  
children:  
firma:  
children:  
firma\_city:  
children:  
firma\_city\_dit:  
children:  
firma\_city\_dit\_test:  
vars:  
ansible\_connection: winrm  
ansible\_port: 5986  
ansible\_user: ansible  
ansible\_winrm\_scheme: https  
ansible\_password: \*\*\*\*\*  
ansible\_winrm\_transport: kerberos  
ansible\_winrm\_server\_cert\_validation: ignore
