---

- file:
    dest: /etc/docker-compose/{{ docker_image }}
    state: directory
  name: create directory /etc/docker-compose/{{ docker_image }}
  become: yes

- template:
    src=templates/docker-compose.yml
    dest=/etc/docker-compose/{{ docker_image }}/docker-compose.yml
  name: templatize {{ docker_image }} docker-compose.yml
  become: yes

# Ansible 2.2 pull flag in docker_service still doesn't work as expected if
# any version of the image isn't present on the host
# https://github.com/ansible/ansible/issues/20458
- command: docker-compose pull chdir=/etc/docker-compose/{{ docker_image }}
  name: pull {{ docker_image }} image
  register: pull_result
  changed_when: "'Downloaded newer image' in pull_result.stdout"

- docker_service:
    project_src: /etc/docker-compose/{{ docker_image }}
    state: present
  name: run {{ docker_image }}
