- name: Matrix
  hosts: beepi
  become: true

  tasks:
    - name: Install podman
      ansible.builtin.apt:
        name: podman
        state: present

    - name: Install podman-compose
      ansible.builtin.apt:
        name: podman-compose
        state: present

    - name: Create matrix directories
      ansible.builtin.file:
        path: "{{ item }}"
        state: directory
        mode: '0755'
      loop:
        - /opt/beeserver/matrix

    - name: Compose down
      changed_when: true
      failed_when: false
      ansible.builtin.command:
        cmd: podman-compose down
        chdir: /opt/beeserver/matrix

    - name: Copy resolv.conf
      ansible.builtin.template:
        src: resolv.conf.j2
        dest: /opt/beeserver/matrix/resolv.conf
        mode: '0644'

    - name: Copy compose
      ansible.builtin.template:
        src: docker-compose.yml.j2
        dest: /opt/beeserver/matrix/docker-compose.yml
        mode: '0644'

    - name: Compose up
      changed_when: true
      ansible.builtin.command:
        cmd: podman-compose up -d
        chdir: /opt/beeserver/matrix
