How to install an old version of PHP using geerlingguy.php on Ubuntu target

Your playbook should look like so:

---
- hosts: XYZ
  become: yes

  pre_tasks:
    - name: Add repository for old PHP
      apt_repository:
        repo: ppa:ondrej/php
        update_cache: yes
        state: present

  roles:
    - role: geerlingguy.apache
      ...

    - role: geerlingguy.php
      php_webserver_daemon: apache2
      php_default_version_debian: "7.1"
      php_version: "7.1"
      php_packages:
        - php7.1
        - php7.1-cli
        - etc...

How to loop over a role in Ansible?

Don’t use “roles:” but “tasks:” and use the include_role module.

For example:

---
# roles/myrole/tasks/main.yml
- debug: var=bla

---
# playbook
- hosts: localhost
  connection: local
  gather_facts: no
  tasks:
   - name: Loop over role
     include_role:
      name: myrole
     vars:
      bla: "{{ item }}"
     with_items:
      - hello world
      - hi