# Want to run ansible tasks on remote host

**URL:** <https://forum.ansible.com/t/want-to-run-ansible-tasks-on-remote-host/22849>\
**Category:** Ansible Project\
**Created:** [October 21, 2016, 4:50am UTC](https://forum.ansible.com/t/want-to-run-ansible-tasks-on-remote-host/22849 "2016-10-21T04:50:40Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![deepak.dimri2016](https://avatars.discourse-cdn.com/v4/letter/d/8dc957/32.png) [@deepak.dimri2016](https://forum.ansible.com/u/deepak.dimri2016)\
**Post date:** [October 21, 2016, 4:50am UTC](https://forum.ansible.com/t/want-to-run-ansible-tasks-on-remote-host/22849/1 "2016-10-21T04:50:40Z")

</div>

In my scenario i have inventory of three machines localhost, host2 and host3. I want to run some tasks/commands on host3 while my ansible playbook is still playing on host2 without switching from host2 to host3 - is that possible? I can use local\_action module but that runs the tasks on localhost but i want command to execute on host3 while i am on host2. Would be great if some one can give pointers. Below might explain what i am trying to achieve:

```auto
 - name: Playing host2
   hosts: host2
   become: yes
   tasks:
    - name: run following commands on host3
      local_action: command <command1 for host3>
      local_action: command <command2 for host3>
    - name: continue to run host2
      command: <command for host2>

```

Is there any substitute for local\_action such that i can run the commands on host3 and not on 127.0.0.1?

Many Thanks, Deepak

---

<div class="post-metadata">

**Author:** ![deepak.dimri2016](https://avatars.discourse-cdn.com/v4/letter/d/8dc957/32.png) [@deepak.dimri2016](https://forum.ansible.com/u/deepak.dimri2016)\
**Post date:** [October 21, 2016, 7:16am UTC](https://forum.ansible.com/t/want-to-run-ansible-tasks-on-remote-host/22849/2 "2016-10-21T07:16:57Z")

</div>

My ansible is deployed on localhost - from local host i am runnning the playbboks and i want run commands on host3 and then come back to host2. I tried using delegate\_to: host3 but then i am getting **Failed to connect to the host via ssh**

Can anyone please suggest?  
Thanks,  
Deepak

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [October 21, 2016, 11:27pm UTC](https://forum.ansible.com/t/want-to-run-ansible-tasks-on-remote-host/22849/3 "2016-10-21T23:27:27Z")

</div>

You want `delegate_to: host3`, docs at [http://docs.ansible.com/ansible/playbooks\_delegation.html#delegation](http://docs.ansible.com/ansible/playbooks_delegation.html#delegation)

---

<div class="post-metadata">

**Author:** ![deepak.dimri2016](https://avatars.discourse-cdn.com/v4/letter/d/8dc957/32.png) [@deepak.dimri2016](https://forum.ansible.com/u/deepak.dimri2016)\
**Post date:** [October 24, 2016, 1:27pm UTC](https://forum.ansible.com/t/want-to-run-ansible-tasks-on-remote-host/22849/4 "2016-10-24T13:27:46Z")

</div>

Thanks Brian, delegate\_to: did work for me
