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

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

- fail:
    msg: "The AzuraCast Ansible installation can only be installed onto computers running Ubuntu 16.04, 18.04 or 20.04 LTS."
  when: 
    - ansible_distribution_release != 'bionic'
    - ansible_distribution_release != 'xenial'
    - ansible_distribution_release != 'focal'

- name: Add multiverse repository
  apt_repository:
    repo: "{{item}}"
    update_cache: no
  when:
    - ansible_architecture == 'x86_64' or ansible_architecture == 'i386'
  with_items:
    - "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"

- name: Update apt
  apt:
    update_cache: yes

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

- name: Install Focal Packages (20.04)
  apt:
    name: "{{ packages }}"
    state: latest
  vars:
    packages:
      - software-properties-common
      - python3-pip
  when: ansible_distribution_release == 'focal'

- name: Install Bionic Packages (18.04 only)
  apt:
    name: "{{ packages }}"
    state: latest
  vars:
    packages:
      - software-properties-common
      - python-pip
  when: ansible_distribution_release == 'bionic'

- name: Install Xenial Packages (16.04 only)
  apt:
    name: "{{ packages }}"
    state: latest
  vars:
    packages:
      - python-software-properties
      - python-pip
  when: ansible_distribution_release == 'xenial'

- name: Update pip components
  pip:
    name: pip
    state: latest
