Ansible WinRM: Bails out with "[Errno 111] Connection refused"
15,671
I'm not configured the WinRM.
Fix:
- https://docs.ansible.com/ansible/latest/user_guide/windows_setup.html#winrm-setup
- Add
ansible_winrm_server_cert_validation: ignore
in my group_vars file.
Related videos on Youtube
Author by
user3265618
Updated on June 04, 2022Comments
-
user3265618 almost 2 years
When i try to connect to my windows host via WinRM module i get execption "Connection refused" in Ansible.
There is structure of ansible direcory:
Command:
user@ansible:~/git/ansible-test$ ansible-playbook test.yml -i inventories/hosts PLAY [install vm] *************************************************************************************************************************************************************************** TASK [Gathering Facts] *********************************************************************************************************************************************************************** fatal: [10.10.10.10]: UNREACHABLE! => {"changed": false, "msg": "ssl: HTTPSConnectionPool(host='10.10.10.10', port=5986): Max retries exceeded with url: /wsman (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7f6298184d50>: Failed to establish a new connection: [Errno 111] Connection refused',))", "unreachable": true} to retry, use: --limit @/home/user/git/ansible-test/test.retry PLAY RECAP *********************************************************************************************************************************************************************************** 10.10.10.10 : ok=0 changed=0 unreachable=1 failed=0
ansible-test direcroty hierarchy:
ansible-test$ tree . ├── group_vars │ └── all ├── inventories │ └── hosts └── test.yml 2 directories, 3 files
test.yaml:
- name: test hosts: vm tasks: - name: get ipconfig information raw: ipconfg register: ipconfig_out - name: print stdout debug: var=ipconfig_out.stdout_lines
inventories/hosts
[vm] 10.10.10.10
group_vars/all
ansible_connection: winrm ansible_user: Administrator ansible_password: password
But if i connect via WinRM from other windows host to the target 10.10.10.10:
Set-Item wsman:\localhost\Client\TrustedHosts -value 10.10.10.10 Enter-PSSession -ComputerName 10.10.10.10 -Credential (Get-Credential -UserName Administrator)
everything is ok!
What i do wrong in Ansible?
P.S. Target host is Windows Server 2012
-
mdaniel over 5 yearsHi user3265618, welcome to SO! It appears you have not set
ansible_winrm_transport:
. I agree the connection refused is a strange message, but start by setting the correct transport and see if that helps. Good luck!
-
-
FilBot3 over 4 yearsWhat if HTTP/S isn't working and HTTP is the only one that works?
-
user2964808 over 2 yearsHi @FilBot3 - If only HTTP is working, then set the port to HTTP in groups_vars file. <br /> Add
ansible_port: 5985