title: Register variables in with_items loop in Ansible playbook
body: <p>I've got a dictionary with different names like</p>
  
  <pre><code>vars:
      images:
        - foo
        - bar
  </code></pre>
  
  <p>Now, I want to checkout repositories and afterwards build docker images only when the source has changed.
  Since getting the source and building the image is the same for all items except the name I created the tasks with <code>with_items: images</code>
  and try to register the result with:</p>
  
  <pre><code>register: "{{ item }}"
  </code></pre>
  
  <p>and also tried</p>
  
  <pre><code>register: "src_{{ item }}"
  </code></pre>
  
  <p>Then I tried the following condition</p>
  
  <pre><code>when: "{{ item }}|changed"
  </code></pre>
  
  <p>and</p>
  
  <pre><code>when: "{{ src_item }}|changed"
  </code></pre>
  
  <p>This always results in <code>fatal: [piggy] =&gt; |changed expects a dictionary</code></p>
  
  <p>So how can I properly save the results of the operations in variable names based on the list I iterate over?</p>
  
  <p>Update: I would like to have something like that:</p>
  
  <pre><code>- hosts: all
    vars:
      images:
        - foo
        - bar
    tasks:
      - name: get src
        git:
          repo: git@foobar.com/repo.git
          dest: /tmp/repo
        register: "{{ item }}_src"
        with_items: images
  
      - name: build image
        shell: "docker build -t repo ."
        args:
          chdir: /tmp/repo
        when: "{{ item }}_src"|changed
        register: "{{ item }}_image"
        with_items: images
  
      - name: push image
        shell: "docker push repo"
        when: "{{ item }}_image"|changed
        with_items: images
  </code></pre>