Ansible: 'item' is undefined
<p>I'm trying to use <code>with_items</code> with <code>delegate_to</code> to run a Docker container in several hosts. I have a group <code>test</code> in <code>/etc/ansible/hosts</code>:</p>

<pre><code>[test]
my_machine1
my_machine2
</code></pre>

<p>And this task:</p>

<pre><code> - name: Run app container
    docker:
      name: "{{artifact_id}}"
      insecure_registry: true
      image: "{{image}}:{{version}}"
      pull: always
      state: reloaded
      ports:
      - "{{port_mapping}}"
      delegate_to: '{{item}}'
      with_items:
      - "{{groups['test']}}"
</code></pre>

<p>But when I run it, I get this error:</p>

<blockquote>
  <p>{"failed": true, "msg": "ERROR! 'item' is undefined"}</p>
</blockquote>

<p>What am I doing wrong?</p>

<p>Thanks in advance</p>