geerlingguy / ansible-role-php

Ansible Role - PHP
https://galaxy.ansible.com/geerlingguy/php/
MIT License
492 stars 442 forks source link

Select PHP version on RedHat #414

Open benoistlaurent opened 5 months ago

benoistlaurent commented 5 months ago

Description

If I'm not mistaken, one cannot select the PHP version to install on RedHat.

Why is it important?

This is critically important to me because I am developing this role that installs a website that requires PHP >= 7.4 (namely dokuwiki).

Now, in my opinion, my ansible-role-dokuwiki is totally responsible for installing the PHP version it requires.

Right now, this is done by selecting the appropriate module before running the php role:

ansible-role-dokuwiki/tasks/main.yml:

- name: Selects PHP:7.4 (RedHat)
  command: "dnf module enable -y php:7.4"
  when: ansible_os_family == "RedHat"

- name: Install php
  include_role: 
    name: geerlingguy.php

Also, my role defines geerlingguy.php as a dependency in meta/main.yml.

Problem

As ansible runs the dependencies before the current role tasks, it results in a bug due to RedHat's (rightful) refusal to select a different PHP version after installing certain packages.

Proposed solution

  1. Defining php_default_version_redhat in defaults/main.yml
  2. Include this in tasks/main.yml
- name: Set the default PHP version for RedHat-based OSes.
  command: "dnf module enable -y php:{{ php_default_version_redhat }}"  
  when: php_default_version_redhat is defined and ansible_os_family == 'RedHat'

Workaround

The workaround would be to select the appropriate PHP module in the playbook that runs ansible-role-dokuwiki:

server-setup.yml:

---
- hosts: all
  pre_tasks:
   - name: Selects PHP:7.4 (RedHat)
     command: "dnf module enable -y php:7.4"
     when: ansible_os_family == "RedHat"

  roles:
    - ansible-role-dokuwiki

This is not acceptable for me, as, again, to me, ansible-role-dokuwiki is suppose to install the adequate version of PHP, depending on the dokuwiki version the user is ultimately installing.

brendon-stephens commented 4 months ago

+1 this would be a good addition to the role.

In my circumstance I needed to install php8.1 which required an extra step to add in the remi repo

        - name: Install remi repository
          ansible.builtin.include_role:
            name: geerlingguy.repo-remi

        - name: Enable php:remi-8.1
           command: "dnf module enable -y php:remi-8.1"
github-actions[bot] commented 2 days ago

This issue has been marked 'stale' due to lack of recent activity. If there is no further activity, the issue will be closed in another 30 days. Thank you for your contribution!

Please read this blog post to see the reasons why I mark issues as stale.