# local\_action tries to ssh to localhost

**URL:** <https://forum.ansible.com/t/local-action-tries-to-ssh-to-localhost/25834>\
**Category:** Ansible Project\
**Created:** [October 26, 2017, 8:49pm UTC](https://forum.ansible.com/t/local-action-tries-to-ssh-to-localhost/25834 "2017-10-26T20:49:38Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![raji\_sankaran](https://avatars.discourse-cdn.com/v4/letter/r/7cd45c/32.png) [@raji\_sankaran](https://forum.ansible.com/u/raji_sankaran)\
**Post date:** [October 26, 2017, 8:49pm UTC](https://forum.ansible.com/t/local-action-tries-to-ssh-to-localhost/25834/1 "2017-10-26T20:49:38Z")

</div>

I have the following task as part of a playbook which needs to be run on localhost. This tasks is for checking if the ansible host is able to ssh to remote server.

`

- name: Verify-User  
local\_action: shell ssh -o PreferredAuthentications=publickey -o StrictHostKeyChecking=no -i {{ role\_path }}/files/authorized\_keys.ansible -o ConnectTimeout=10 {{ createuser }}@{{ node }} “echo success”  
register: user\_enabled  
ignore\_errors: yes

`

This task is called from a playbook using the following command. I need the extra vars to connect to server if ssh fails and create a new ansible user.  
`

ansible-playbook -i “1.0.0.0,” setup-host.yml --extra-vars “node=1.0.0.0, ansible\_connection=ssh ansible\_ssh\_user=root ansible\_ssh\_pass=test”

`

Running the playbook gives,

`

`

`

hosts": {

“1.0.0.0”: {

“changed”: false,

“msg”: “Failed to connect to the host via ssh: ssh: connect to host localhost port 22: Connection refused\r\n”,

“unreachable”: true

}

}

`

`

`

If i remove ansible\_connection=ssh from the command, this gives a different error, but atleast it wasnt trying to ssh.

My question is

- why is local\_action trying to ssh? If its due to ansible\_connection=ssh, is there a way this can be overriden for a specific task? “connection: local” dint work.
- Shouldnt the hosts for this tasks say “localhost” ? Why is it showing the hosts as the ip of remote server. Does this mean local\_action did not take effect?

Thanks.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [October 27, 2017, 3:35pm UTC](https://forum.ansible.com/t/local-action-tries-to-ssh-to-localhost/25834/2 "2017-10-27T15:35:48Z")

</div>

This is precedence issue, caused by extra var ansible\_connection=ssh,  
'local\_action' is the same as 'delegate\_to: localhost', but the extra  
var setting is overriding localhosts normal 'connection=local'

---

<div class="post-metadata">

**Author:** ![raji\_sankaran](https://avatars.discourse-cdn.com/v4/letter/r/7cd45c/32.png) [@raji\_sankaran](https://forum.ansible.com/u/raji_sankaran)\
**Post date:** [October 27, 2017, 3:44pm UTC](https://forum.ansible.com/t/local-action-tries-to-ssh-to-localhost/25834/3 "2017-10-27T15:44:57Z")

</div>

Thanks. I was curious, Is there a way to override the extra vars on a specific task? I want just one task to have connection: local.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [October 27, 2017, 3:52pm UTC](https://forum.ansible.com/t/local-action-tries-to-ssh-to-localhost/25834/4 "2017-10-27T15:52:39Z")

</div>

no, extra\_vars have the highest precedence, they are really the 'big hammer'

---

<div class="post-metadata">

**Author:** ![raji\_sankaran](https://avatars.discourse-cdn.com/v4/letter/r/7cd45c/32.png) [@raji\_sankaran](https://forum.ansible.com/u/raji_sankaran)\
**Post date:** [October 27, 2017, 7:22pm UTC](https://forum.ansible.com/t/local-action-tries-to-ssh-to-localhost/25834/5 "2017-10-27T19:22:09Z")

</div>

Thanks, Brian
