0Pricing
Ansible Academy · Lesson

delegate_to & run_once for Orchestration

Run a task on one host for many.

Tasks Do Not Always Run Where You Think

By default each task runs on its target host. For orchestration you sometimes need a task to run somewhere else entirely. 🎯

Meet delegate_to

The delegate_to keyword runs a task on a different host than the current one, while still using that host's variables.

- name: Add web node to load balancer
  community.general.haproxy:
    host: "{{ inventory_hostname }}"
    state: enabled
  delegate_to: lb01

All lessons in this course

  1. Automating Network Devices with cli_command
  2. delegate_to & run_once for Orchestration
  3. Coordinate Web, App & DB Tiers
  4. Load Balancer Drain & Re-Enable
← Back to Ansible Academy