# ansible delegation to other hosts with\_items

**URL:** <https://forum.ansible.com/t/ansible-delegation-to-other-hosts-with-items/21525>\
**Category:** Ansible Project\
**Created:** [May 23, 2016, 4:32pm UTC](https://forum.ansible.com/t/ansible-delegation-to-other-hosts-with-items/21525 "2016-05-23T16:32:06Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![christos.flevotomos](https://avatars.discourse-cdn.com/v4/letter/c/90ced4/32.png) [@christos.flevotomos](https://forum.ansible.com/u/christos.flevotomos)\
**Post date:** [May 23, 2016, 4:32pm UTC](https://forum.ansible.com/t/ansible-delegation-to-other-hosts-with-items/21525/1 "2016-05-23T16:32:06Z")

</div>

I use ansible 2.1 and I want to run a command to a group of hosts, using delegate\_to. I use localhost (ansible) as the hosts param and I want to delegate a “touch” command to both of cls hosts.

I have the following yml (for test purposes):

```auto
---
- hosts: ansible
# gather_facts: yes

  tasks:
  - debug: var=groups.cls

  - name: touch a file to running host
    shell: echo {{ item }} >> /tmp/{{ inventory_hostname }}
    delegate_to: "{{ item }}"
    with_items: "{{ groups.cls }}"

```

with output:

```auto
[root@ansible control]# ansible-playbook -i inventory test.yml

PLAY ***************************************************************************

TASK [setup] *******************************************************************
ok: [ansible]

TASK [debug] *******************************************************************
ok: [ansible] => {
    "groups.cls": [
        "cls-host-1",
        "cls-host-2"
    ]
}

TASK [touch a file to running host] ********************************************
changed: [ansible -> cls-host-1] => (item=cls-host-1)
changed: [ansible -> cls-host-2] => (item=cls-host-2)

PLAY RECAP *********************************************************************
ansible : ok=3 changed=1 unreachable=0 failed=0

```

but the touch is done only on the first host with both entries:

```auto
[root@cls-host-1 ~]# more /tmp/ansible
cls-host-1
cls-host-2

```

Is anything wrong? Can I delegate the command with any other way?
