Connection to Windows via winrm

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 )

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”
  • }

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

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”
]
}
}

Thank you for your answer and hints.

Complete the data 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