Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ansible delegate_to keyword - can I delegate a task to a group defined in an inventory rather than to a specific host?

Tags:

ansible

In my playbook I want to run a delegated task on 4 load balancers. Can I just simply use delegate_to: loadbalancers_group in my task? Will delegate_to accept a group rather than a single host? I am not sure as the Ansible docs say:

delegate_to - Host to execute task instead of the target (inventory_hostname)

like image 273
TomTom Avatar asked Nov 03 '25 16:11

TomTom


1 Answers

No. The delegate_to option needs to be a host, not a group.

What you can do is loop over the group, e.g.:

- file:
    path: touched_file
    state: touch
  delegate_to: "{{ item }}"
  loop: "{{ groups['loadbalancers_group'] }}"
like image 111
Jack Avatar answered Nov 06 '25 10:11

Jack



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!