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

  - name: Add multiverse repository
    apt_repository:
      repo: "{{item}}"
      update_cache: no
    when:
      - ansible_distribution == 'Ubuntu'
      - 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:  pkg="{{ item }}" state=latest
    with_items:
      - apt-transport-https
      - curl
      - wget
      - tar
      - build-essential
      - pwgen
      - whois
      - python-pip

  - name: Install software-properties (18.04 only)
    apt:  pkg="{{ item }}" state=latest
    with_items:
      - software-properties-common
    when: ansible_distribution == 'Ubuntu' and ansible_distribution_release == 'bionic'

  - name: Install python-software-properties (16.04 only)
    apt:  pkg="{{ item }}" state=latest
    with_items:
      - python-software-properties
    when: ansible_distribution == 'Ubuntu' and ansible_distribution_release != 'bionic'

  - name: Update pip components
    pip: name="{{ item }}" state=latest
    with_items:
     - pip