I could be wrong here but I believe this is related to variable precedence. Ansible thinks that it has to use winrm to connect to the localhost since extra vars always wins. Try moving all of the connection details to either host_vars/10.x.x.x or group_vars/windows.yml.
http://docs.ansible.com/ansible/latest/playbooks_variables.html#variable-precedence-where-should-i-put-a-variable http://docs.ansible.com/ansible/latest/intro_windows.html#inventory On Thursday, August 17, 2017 at 11:01:47 PM UTC-5, Sandeep MS wrote: > > I need a role with some tasks for remote windows server and some tasks for > localhost. > > A sample like this fails with > > 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 0x335e5d0>: Failed to establish a new connection: [Errno 111] > Connection refused',))", "unreachable": true} > > The command I use is as below and Ansible version is 2.3.1.0. > > /usr/bin/ansible-playbook temp.yml > --extra-vars="ansible_user=Administrator" > --extra-vars="ansible_password=xxxxxx" --extra-vars="ansible_port=5985" > --extra-vars="ansible_connection=winrm" -i /home/ansible_hosts -v > > > temp.yml > ------------- > > - name: Test remote and local ping > hosts: "10.x.x.x" > gather_facts: no > tasks: > - name: Remote ping > win_ping: > - name: Local ping > delegate_to: localhost > ping: > > > /home/ansible_hosts > -------------------- > > 10.x.x.x > > > How do we make sure that connection for localhost is not attempted thru > WinRM? > > -- 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-project+unsubscr...@googlegroups.com. To post to this group, send email to ansible-project@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/32dba22b-585c-4aed-b45e-05324ef95893%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.