- name: Angie web server
  hosts: servers
  tasks:
    - name: Install packages
      ansible.builtin.package:
        name:
          - ca-certificates
          - curl
          - gnupg

    - name: Add apt repo key
      ansible.builtin.apt_key:
        url: https://angie.software/keys/angie-signing.gpg
        state: present

    - name: Add apt repo
      ansible.builtin.apt_repository:
        repo: "deb https://download.angie.software/angie/\
          {{ ansible_facts['distribution'] | lower }}/{{ ansible_facts['distribution_major_version'] }} \
          {{ ansible_facts['distribution_release'] }} main"
        filename: angie
        update_cache: true

    - name: Install Angie
      ansible.builtin.package:
        name: angie

    - name: Configure virtual host
      ansible.builtin.template:
        src: angie/{{ app }}.conf
        dest: "/etc/angie/http.d/{{ app }}.conf"
        mode: "0644"
      notify: Restart angie

    - name: Remove default virtual host
      ansible.builtin.file:
        path: /etc/angie/http.d/default.conf
        state: absent

  handlers:
    - name: Restart angie
      ansible.builtin.service:
        name: angie
        state: restarted
