---
- name: Websites (Static Files) Playbook (K8s)
  hosts: web
  gather_facts: true

# Specific tasks for this playbook
  tasks:
    - name: Set required facts
      ansible.builtin.set_fact:
        web_home: "{{ persistent_data | default('/var/lib') }}/web"
        web_user_id: 1000
        web_group_id: 1000
      tags: always

    - name: Create required web data folder
      become: true
      ansible.builtin.file:
        state: directory
        path: "{{ web_home }}"
        mode: "0750"
        owner: "{{ web_user_id }}"
        group: "{{ web_group_id }}"
      tags:
        - tasks
        - tasks::folders

    - name: Create required web data folder
      become: true
      ansible.builtin.file:
        state: directory
        path: "{{ web_home }}/{{ item }}"
        mode: "0750"
        owner: "{{ web_user_id }}"
        group: "{{ web_group_id }}"
      with_items:
        - "{{ websites | default([]) }}"
      tags:
        - tasks
        - tasks::folders

    - name: Synchronize websites
      become: true
      ansible.posix.synchronize:
        mode: push
        src: "{{ lookup('env', 'GITHUB_WORKSPACE') + '/websites/releases/' + item }}/"
        dest: "{{ web_home }}/{{ item }}"
        delete: true
        recursive: true
      with_items:
        - "{{ websites | default([]) }}"
