---

- name: create directory /etc/docker-compose/cadvisor
  file:
    dest: /etc/docker-compose/cadvisor
    state: directory
  become: yes

- name: templatize cadvisor docker-compose.yml
  template:
    src=docker-compose.yml.j2
    dest=/etc/docker-compose/cadvisor/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/cadvisor
  name: pull cadvisor image

- name: run cadvisor
  docker_service:
    project_src: /etc/docker-compose/cadvisor
    pull: yes
    restarted: "{{ cadvisor_restart }}"
    state: "{{ cadvisor_state }}"
