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

  - name: Shut down all services
    service:
      name: "{{ item }}"
      state: stopped
    with_items:
     - influxdb
     - mysql
     - php7.2-fpm
     - nginx
     - redis-server
     - supervisor
    ignore_errors: True

  - name: Kill all processes owned by AzuraCast user
    command: pkill -9 -u azuracast
    ignore_errors: true

  - name: Update apt
    apt:
      update_cache: yes

  - name: Remove AzuraCast User
    user:
      name: azuracast
      state: absent

  - name: Remove AzuraCast folders
    file: path="{{ item }}" state=absent
    with_items:
     - "{{ tmp_base }}"
     - "{{ app_base }}/servers"

  - name: Remove PPAs
    apt_repository: repo="{{ item }}" state=absent
    with_items:
      - ppa:avsm/ppa

  - name: UFW - Turn off Firewall
    ufw:
      state: disabled
    ignore_errors: True

  - name: Remove software
    apt: pkg="{{ item }}" state=absent force=yes purge=yes
    with_items:
      # Radio software
      - icecast2
      - liquidsoap
      - liquidsoap-plugin-*
      - libxml2
      - libxslt1-dev
      - libvorbis-dev
      - libssl-dev
      - libcurl4-openssl-dev
      - opam
      - libpcre3-dev
      - libfdk-aac-dev
      - libmad0-dev
      - libmp3lame-dev
      - libtag1-dev
      - libfaad-dev
      - libflac-dev
      - libogg-dev
      - libopus-dev
      - m4
      - aspcud
      - camlp4

      # Supervisord
      - supervisor

      # InfluxDB
      - influxdb

      # Nginx
      - nginx
      - nginx-*

      # PHP 7.2
      - php7.2-*

      # MariaDB
      - mariadb-*

      # Redis
      - redis-server

      # UFW Firewall
      - ufw

      # Ansible itself
      - python2.7
      - python-pip
      - python-mysqldb
      - ansible

      # System packages
      - pwgen
      - lnav