Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run a task on localhost only once

Tags:

ansible

I have a playbook which will be run on many servers (say ten). The first three tasks will be run on the remote servers. The last task of merging is done on localhost (Ansible controller).

When I run this playbook, the merging is happening each time (i.e.: ten times).
I want to do the merging task only one time, once all the above tasks are completed on all servers.

---
- name: Find the location 
  debug: 
 
- name: Extract details
  debug: 

- name: Create csv file
  debug:

- name: Merge files
  debug:
  delegate_to: localhost 
like image 707
Smily Avatar asked Jun 10 '26 23:06

Smily


1 Answers

Use run_once to achieve this:

- hosts: all

  tasks:
  - name: do this on every host
    debug:

  - name: do this once on localhost
    debug:
    delegate_to: localhost
    run_once: true
like image 52
hymie Avatar answered Jun 14 '26 16:06

hymie