---
- name: add php{{ php_version | replace(".","") }} repo
  dnf:
    name: https://rpms.remirepo.net/enterprise/remi-release-{{ ansible_distribution_major_version|int }}.rpm
    state: latest

- name: update os
  dnf:
    name: '*'
    update_cache: true
    state: latest

- name: install needed packages
  dnf:
    name:
      - php{{ php_version | replace(".","") }}-php 
      - php{{ php_version | replace(".","") }}-php-pecl-apcu 
      - php{{ php_version | replace(".","") }}-php-bcmath 
      - php{{ php_version | replace(".","") }}-php-dom 
      - php{{ php_version | replace(".","") }}-php-gmp 
      - php{{ php_version | replace(".","") }}-php-pecl-imagick 
      - php{{ php_version | replace(".","") }}-php-ldap 
      - php{{ php_version | replace(".","") }}-php-openssl 
      - php{{ php_version | replace(".","") }}-php-gd 
      - php{{ php_version | replace(".","") }}-php-json 
      - php{{ php_version | replace(".","") }}-php-mysql 
      - php{{ php_version | replace(".","") }}-php-curl 
      - php{{ php_version | replace(".","") }}-php-mbstring 
      - php{{ php_version | replace(".","") }}-php-intl 
      - php{{ php_version | replace(".","") }}-php-exif 
      - php{{ php_version | replace(".","") }}-php-zip 
      - php{{ php_version | replace(".","") }}-php-zlib 
      - php{{ php_version | replace(".","") }}-php-fileinfo 
      - php{{ php_version | replace(".","") }}-php-pcntl 
      - php{{ php_version | replace(".","") }}-php-posix 
      - php{{ php_version | replace(".","") }}-php-xmlreader 
      - php{{ php_version | replace(".","") }}-php-xmlwriter 
      - php{{ php_version | replace(".","") }}-php-ctype 
      - php{{ php_version | replace(".","") }}-php-bz2 
      - php{{ php_version | replace(".","") }}-php-ftp
      - php{{ php_version | replace(".","") }}-php-smbclient 
      - php{{ php_version | replace(".","") }}-php-memcached 
      - php{{ php_version | replace(".","") }}-php-redis 
      - php{{ php_version | replace(".","") }}-php-phar 
      - php{{ php_version | replace(".","") }}-php-opcache
    state: latest

- name: Set php env for {{ ansible_facts['distribution'] }}
  set_fact: 
    php_bin: "php{{ php_version | replace('.','') }}"
    php_dir: "/etc/opt/remi/php{{ php_version | replace('.','') }}/php.d/nextcloud.ini"
    #php_pkg_apcu: "{{ php_config_ref[php_ver|replace('.','_')].php_pkg_apcu | d(php_config_ref.defaults.php_pkg_apcu) }}"
    #php_pkg_spe: "{{ php_config_ref[php_ver|replace('.','_')].php_pkg_spe | d(php_config_ref.defaults.php_pkg_spe) }}"
    #php_socket: "{{ php_config_ref[php_ver|replace('.','_')].php_socket | d(php_config_ref.defaults.php_socket) }}"

- name: Add Nextcloud configuration for PHP
  template:
    dest: /etc/opt/remi/php{{ php_version | replace(".","") }}/php.d/nextcloud.ini
    src: php_nc_ini.j2
    mode: '0640'
  notify: restart http

- name: Generate Nextcloud configuration for APCU
  lineinfile:
    path: /etc/opt/remi/php{{ php_version | replace(".","") }}/php.d/40-apcu.ini
    regexp: '^apc.shm_size(.*)'
    line:   'apc.shm_size = {{ APC_SHM_SIZE }}'
    backup: true
  notify: restart http

- name: Generate Nextcloud configuration for OPCACHE
  ansible.builtin.template:
    dest: /etc/opt/remi/php{{ php_version | replace(".","") }}/php.d/10-opcache.ini
    src: opcache_nc_ini.j2
    mode: 0640
  notify: restart http
