Connection to Windows via winrm

54 views
Skip to first unread message

Lukasz

unread,
Nov 18, 2020, 3:07:21 PM11/18/20
to Ansible Project

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"
  • }
    ....

  • ansible-inventory all -i ~/.ansible/group_var/ldap_inventory.yaml --list
  • {
  • "_meta": {
  • "hostvars": {
  • "ansible-win.leme.lcl": {
  • "ansible_connection": "winrm",
  • "ansible_password": "invisible-password;)",
  • "ansible_port": 5986,
  • "ansible_user": "ansible",
  • "ansible_winrm_scheme": "https",
  • "ansible_winrm_server_cert_validation": "ignore",
  • "ansible_winrm_transport": "kerberos"
  • }
  • }
  • },
    ....

Jerin J

unread,
Nov 18, 2020, 4:37:17 PM11/18/20
to ansible...@googlegroups.com
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 

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/775ff29c-2df2-4ba0-b762-85f179326f6en%40googlegroups.com.

Lukasz

unread,
Nov 19, 2020, 1:21:19 AM11/19/20
to Ansible Project

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

Lukasz

unread,
Nov 19, 2020, 4:23:29 AM11/19/20
to Ansible Project
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
Reply all
Reply to author
Forward
0 new messages