---
# tasks file for php7
- name: Assertions
  assert:
    that:
        - ansible_os_family in ['Debian', 'OpenBSD']

- name: APT install
  when: ansible_pkg_mgr == 'apt'
  apt:
      name: ['php-pear', 'php7.0-dev', 'php7.0-cli', 'cron']
      state: present
      update_cache: yes
      cache_valid_time: 3600

- name: pkg install
  when: ansible_pkg_mgr == 'openbsd_pkg'
  openbsd_pkg:
      name: php%7.0
      state: present

- name: Create php7 symlink
  when: ansible_pkg_mgr == 'openbsd_pkg'
  with_items: ['php', 'php7']
  file:
      src: /usr/local/bin/php-7.0
      dest: '/usr/local/bin/{{ item }}'
      owner: root
      group: 0
      mode: 0o0755
      state: link

- name: Allow Composer install
  when: ansible_pkg_mgr == 'openbsd_pkg'
  with_dict:
      'allow_url_fopen': 'On'
      'suhosin.executor.include.whitelist': 'phar'
  ini_file:
      dest: /etc/php-7.0.ini
      section: PHP
      option: '{{ item.key }}'
      value: '{{ item.value }}'

- name: Download Composer's installer
  get_url:
      url: https://getcomposer.org/installer
      dest: /root/composer-install

- name: Install Composer
  command: php7 -f /root/composer-install -- --install-dir=/usr/local/bin --filename=composer
  args:
      creates: /usr/local/bin/composer

- name: Add Cron job for Composer self-update
  cron:
      special_time: weekly
      user: root
      name: Composer self-update
      job: /usr/local/bin/composer self-update 2>&1 | logger