ansible delegation to other hosts
<p>I use ansible 2.1 and I want to run a command to a group of hosts, using delegate_to. I use localhost as the host param and I want to delegate a “touch” command to both of cls hosts
I have the following</p>

<pre><code>---
- hosts: ansible
#  gather_facts: yes

  tasks:
  - debug: var=groups.cls

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

<p>with output:</p>

<pre><code>[root@ansible control]# ansible-playbook -i inventory test.yml

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

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

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

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

PLAY RECAP *********************************************************************
ansible                    : ok=3    changed=1    unreachable=0    failed=0
</code></pre>

<p>but the touch is done only on the first host:</p>

<pre><code>[root@cls-host-1 ~]# more /tmp/ansible
cls-host-1
cls-host-2
</code></pre>

<p>Is anything wrong? Can I delegate the command with any other way?</p>