---
- name: "include tasks nginx-docker-proxy-domain.yml"
  include_tasks: nginx-docker-proxy-domain.yml

- name: register directory
  stat:
    path: "{{docker_compose_instance_directory}}"
  register: docker_compose_instance_directory_register

- name: checkout repository 
  ansible.builtin.shell: git checkout .
  become: true
  args:
    chdir: "{{docker_compose_instance_directory}}"
  when: docker_compose_instance_directory_register.stat.exists

- name: pull docker repository
  git:
    repo: "https://github.com/akaunting/docker.git"
    dest: "{{docker_compose_instance_directory}}"
    update: yes
  notify: setup akaunting
  become: true
  register: git_result
  ignore_errors: true

- name: Warn if repo is not reachable
  debug:
    msg: "Warning: Repository is not reachable."
  when: git_result.failed

- name: set akaunting version
  ansible.builtin.shell: find . -type f -exec sed -i 's/akaunting:latest/akaunting:{{version_akaunting}}/' {} + && find . -type f -exec sed -i 's/version=latest/version={{version_akaunting}}/' {} + 
  become: true
  args:
    chdir: "{{docker_compose_instance_directory}}"

- name: configure db.env
  template: src=db.env.j2 dest={{docker_compose_instance_directory}}/env/db.env
  notify: setup akaunting

- name: configure run.env
  template: src=run.env.j2 dest={{docker_compose_instance_directory}}/env/run.env
  notify: setup akaunting