Re: Want to run ansible tasks on remote host

57 views
Skip to first unread message

deepak dimri

unread,
Oct 21, 2016, 10:08:33 AM10/21/16
to ansible...@googlegroups.com
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

On Fri, Oct 21, 2016 at 10:20 AM, deepak dimri <deepak.d...@gmail.com> wrote:

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:

 - 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


deepak.d...@gmail.com

unread,
Oct 21, 2016, 10:08:34 AM10/21/16
to Ansible Project

In my scenario i have inventory of three machines localhost, host2 and host3. i am using localhost as ansible machine to run my playbooks. 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?  Below might explain what i am trying to achieve:

 - 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>

I tried using delegate_to: host3 but then i am getting Failed to connect to the host via ssh


 -name: Playing host2

  hosts
: host2

  become
:yes

  tasks
:

   
- name: run following commands on host3

      shell
: <command1>

      shell
: <command2>

      shell
: <command3>

      delegate_to
: host2

      remote_user
: centos

deepak dimri

unread,
Oct 21, 2016, 10:09:22 AM10/21/16
to ansible...@googlegroups.com

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:

 - 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>

Brian Coca

unread,
Oct 21, 2016, 7:27:35 PM10/21/16
to ansible...@googlegroups.com


----------
Brian Coca

deepak dimri

unread,
Oct 24, 2016, 9:27:55 AM10/24/16
to ansible...@googlegroups.com
Thanks Brian, delegate_to: <host3 hostname> did work for me

--
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+unsubscribe@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/CACVha7cRAYVJReo4yO5fN-USvLM%2BLgRwjqo_u2K-5KMA53yEiA%40mail.gmail.com.

For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages