---
- name: Running context
  debug:
    msg: >-
      Running Ansible on {{ inventory_hostname }} with OS {{ ansible_distribution }}
      {{ ansible_distribution_release }} {{ ansible_distribution_version }} {{ ansible_architecture }} ({{ app_env }})"

- name: Ubuntu OS Check
  fail:
    msg: "The AzuraCast Ansible installation can only be installed onto computers running Ubuntu."
  when: ansible_distribution != 'Ubuntu'

- name: Ubuntu Version Check
  fail:
    msg: "The AzuraCast Ansible installation can only be installed onto computers running Ubuntu 20.04 LTS."
  when:
    - ansible_distribution_release != 'focal'

- name: Add multiverse repository
  apt_repository:
    repo: "{{ init_repo_to_add }}"
    update_cache: false
  when:
    - ansible_architecture == 'x86_64' or ansible_architecture == 'i386'
  loop:
    - "deb http://archive.ubuntu.com/ubuntu {{ ansible_distribution_release }} multiverse"
    - "deb-src http://archive.ubuntu.com/ubuntu/ {{ ansible_distribution_release }} multiverse"
    - "deb http://archive.ubuntu.com/ubuntu {{ ansible_distribution_release }}-updates multiverse"
    - "deb-src http://archive.ubuntu.com/ubuntu/ {{ ansible_distribution_release }}-updates multiverse"
  loop_control:
    loop_var: init_repo_to_add

- name: Update apt
  apt:
    update_cache: true

- name: Install system packages
  apt:
    name: "{{ packages }}"
  vars:
    packages:
      - apt-transport-https
      - curl
      - wget
      - tar
      - build-essential
      - pwgen
      - whois
      - gzip
      - zip
      - unzip
      - zstd

- name: Install Focal Packages (20.04)
  apt:
    name:
      - software-properties-common
      - python3-pip
  when: ansible_distribution_release == 'focal'

- name: Update pip components
  pip:
    name: pip
