- name: "Create (optional) Dockerfile for {{ application_id }}"
  template:
    src: "{{ item }}"
    dest: "{{ docker_compose.files.dockerfile }}"
  loop:
    - "{{ application_id | abs_role_path_by_application_id }}/templates/Dockerfile.j2"
    - "{{ application_id | abs_role_path_by_application_id }}/files/Dockerfile"
  notify: docker compose up
  register: create_dockerfile_result
  failed_when:
    - create_dockerfile_result is failed
    - "'Could not find or access' not in create_dockerfile_result.msg"

- name:           "Create (optional) '{{ docker_compose.files.env }}'"
  template:
    src:          "{{ item }}"
    dest:         "{{ docker_compose.files.env }}"
    mode:         '770'
    force:        yes
  notify:         docker compose up
  register:       env_template
  loop:
    - "{{ application_id | abs_role_path_by_application_id }}/templates/env.j2"
    - "{{ application_id | abs_role_path_by_application_id }}/files/env"
  failed_when:
    - env_template is failed
    - "'Could not find or access' not in env_template.msg"

- name:           "Create (obligatoric) '{{ docker_compose.files.docker_compose }}'"
  template:
    src:          "docker-compose.yml.j2"
    dest:         "{{ docker_compose.files.docker_compose }}"
  notify:         docker compose up
  register:       docker_compose_template