I don't understand 100% what you want to do. But generally I have learned any TASK can be sent to localhost with a preceding delegate_to: localhost so you have a bunch of hosts your playbook runs against and some TASKs inside that playbok you want to run against your localhost (exclusively)

- name: TASKNAME
  copy:
    blablabla:

- name: TASK ON LOCALHOST
  delegate_to: localhost
  shell: <running script>


On 08.03.22 11:15, Netanel Peretz wrote:
Hey,
I want to be able to use a playbook to run a task on host1 then run a task on localhost(ansible host) and then run another task on host1


Is that supposed to be as simple as copying something like this and changing the hostname and the task that comes after that?
Is there a better way to do so?


- name: TASKNAME
  hosts: host1
  tasks:

  - name: TASK ON HOST1
    shell: <running script>

- name: TASKNAME
  hosts: localhost
  tasks:

  - name: TASK ON LOCALHOST
    shell: <running script>

- name: TASKNAME
  hosts: host1
  tasks:

  - name: ANTOHER TASK ON HOST1
    shell: <running script>
--
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 view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/c2236069-81c8-4cf9-a81f-242927b05455n%40googlegroups.com <https://groups.google.com/d/msgid/ansible-project/c2236069-81c8-4cf9-a81f-242927b05455n%40googlegroups.com?utm_medium=email&utm_source=footer>.

--
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/388b49bf-4035-28ba-b9f3-f1066ca40f71%40mailbox.org.

Reply via email to