# Delegate to a group with\_items or another way?

**URL:** <https://forum.ansible.com/t/delegate-to-a-group-with-items-or-another-way/25939>\
**Category:** Ansible Project\
**Created:** [November 6, 2017, 7:00pm UTC](https://forum.ansible.com/t/delegate-to-a-group-with-items-or-another-way/25939 "2017-11-06T19:00:43Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![mark.haney](https://avatars.discourse-cdn.com/v4/letter/m/b9e5f3/32.png) [@mark.haney](https://forum.ansible.com/u/mark.haney)\
**Post date:** [November 6, 2017, 7:00pm UTC](https://forum.ansible.com/t/delegate-to-a-group-with-items-or-another-way/25939/1 "2017-11-06T19:00:43Z")

</div>

I’ve got a case where I need to run a command on a specific group of hosts when a certain file exists. The playbook is being run on two host groups (a and b). I’m trying to figure out the best way to create the logic to make this work.

Currently I’ve got this:

- name: Run A on each group if file exists  
shell: script.sh  
when: file.stat.exists == true

delegate\_to: “{{ item }}”  
with\_items: groups.a

What I’m not sure of is if this would work. Basically, I was script.sh to run on every host in group A when a certain file exists. Will this task work? If not, is there a correct way of doing this? One example has the delegate\_to with items moved off into a handler, which is fine as long as I get the syntax right on the with\_items.

Any ideas?
