---
- hosts: all

  vars:
    php_enable_webserver: false
    php_enable_php_fpm: true
    php_memory_limit: "192M"
    php_enablerepo: "remi,remi-php70"
    php_install_recommends: no

  pre_tasks:
    - name: Update apt cache.
      apt: update_cache=yes cache_valid_time=600
      when: ansible_os_family == 'Debian'
      changed_when: false

    # Ubuntu-specific tasks.
    - name: Add repository for PHP 7.
      apt_repository: repo='ppa:ondrej/php'
      when: ansible_distribution == 'Ubuntu'

    # Debian-specific tasks.
    - name: Add dependencies for PHP versions (Debian).
      apt:
        name: "{{ item }}"
      with_items:
        - apt-transport-https
        - ca-certificates
      when: ansible_distribution == "Debian"

    - name: Add Ondrej Sury's apt key (Debian).
      apt_key:
        url: https://packages.sury.org/php/apt.gpg
        state: present
      when: ansible_distribution == "Debian"

    - name: Add Ondrej Sury's repo (Debian).
      apt_repository:
        repo: "deb https://packages.sury.org/php/ {{ ansible_distribution_release }} main"
        state: present
      register: php_ondrej_debian_repo
      when: ansible_distribution == "Debian"

    - name: Update apt caches after repo is added (Debian).
      apt: update_cache=yes
      when: php_ondrej_debian_repo.changed and (ansible_distribution == "Debian")

  roles:
    - role: geerlingguy.repo-remi
      when: ansible_os_family == 'RedHat' and ansible_distribution != 'Fedora'
    - role_under_test