---

- name: Deployment playbook
  hosts: localhost
  vars_files:
    - container_definition.yml

  tasks:
    - name: Pull the latest version of containers
      raw: docker pull {{item.image}}
      with_items: containers

    - name: Deploy docker containers
      docker: >
        state=running
        name={{item.app_name}}
        image={{item.image}}
        links={{item.links|default(omit)}}
        ports={{item.ports|default(omit)}}
        env="{{item.env_variables|default(omit)}}"
      with_items: containers

---

- name: Deployment playbook
  hosts: localhost
  vars_files:
    - container_definition.yml

  tasks:
    - name: Pull the latest version of containers
      raw: docker pull {{item.image}}
      with_items: containers

    - name: Check outdated containers
      docker_outdated: image_name={{item.image}} container_name={{item.app_name}}
      register: outdated_containers
      with_items: containers

    - name: Destroy outdated containers
      shell: echo "state=absent name={{item.stdout}}"
      when: item.changed
      with_items: outdated_containers.results

    - name: Deploy docker containers
      docker: >
        state=running
        name={{item.app_name}}
        image={{item.image}}
        links={{item.links|default(omit)}}
        ports={{item.ports|default(omit)}}
        env="{{item.env_variables|default(omit)}}"
      with_items: containers


Use docker_outdated to get a list of outdated containers
Use docker_outdated to get a list of outdated containers
