---
- name: Deploy deploy script
  ansible.builtin.copy:
    src: "{{ playbook_dir }}/../../scripts/deploy.sh"
    dest: "{{ scripts_dir }}/deploy.sh"
    mode: "0755"

- name: Deploy .env files
  ansible.builtin.template:
    src: env.j2
    dest: "{{ envs_dir }}/{{ item.name }}/.env"
    mode: "0640"
  loop: "{{ app_environments }}"
  loop_control:
    label: "{{ item.name }}"

- name: Clone or update repository
  ansible.builtin.git:
    repo: "{{ repo_url }}"
    dest: "{{ repo_dir }}"
    version: "{{ repo_branch }}"
    force: true
    accept_hostkey: true

- name: Build and deploy
  ansible.builtin.include_tasks: deploy.yml