when git clone changed do docker rebuild

Hi All,

I’m trying to do the following:

    - name: Git checkout
      git:
        accept_hostkey: yes
        clone: yes
        dest: "/opt/docker-images/{{ item.path }}"
        force: yes
        key_file: /tmp/gitkey
        repo: "{{ item.repo }}"
        version: "{{ item.branch if item.branch is defined else 'HEAD' }}"
      with_items: dockers
      register: gitcloned

    - name: stop dockers
      docker:
        image: "{{ item.path }}-image"
        name: "{{ item.path }}-container"
        state: absent
      with_items: dockers
      when: gitcloned.changed

    - name: remove images
      docker_image:
        name: "{{ item.path }}-image"
        state: absent
      with_items: dockers
      when: gitcloned.changed

    - name: Creeer de docker images
      docker_image:
        name: "{{ item.path }}-image"
        path: "/opt/docker-images/{{ item.path }}"
      with_items: dockers

    - name: Start de docker images
      docker:
        image: "{{ item.path }}-image"
        name: "{{ item.path }}-container"
        env: "{{ item.env }}"
        ports: "{{ item.port }}:{{ item.docker_port }}"
        restart_policy: "{{item.restart}}"
      with_items: dockers

So basicly: when git is changed and a new clone is performed. remove de docker container, the image, and start to rebuild those things.

Works as advertised! Almost… you see, when only 1 of the git repo’s get’s updates, it still means that ALL docker instances are stopped and ALL images are removed, instead of just the one whose git repo got changed.

In other words, with_items is not logically linked with register: gitcloned

Am I goign the wrong way perhaps?

Thanks,
Mark