Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can select PHP version on RedHat. #415

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ The default values for the HTTP server deamon are `httpd` (used by Apache) for R

(Debian/Ubuntu only) The default version of PHP in the given OS version repositories. The specific version is set per distro and per version, but you can override it by providing a value here, like `"7.4"`.

php_default_version_redhat: ""

(RedHat/CentOS only) The default version of PHP in the given OS version repositories. The specific version is set per distro and per version, but you can override it by providing a value here, like `"7.4"`.

**If you'd like to be able to switch PHP versions easily, or use a version that's not available in system packages**: You can use the [`geerlingguy.php-versions`](https://galaxy.ansible.com/geerlingguy/php-versions/) role to more easily switch between major PHP versions (e.g. 5.6, 7.1, 7.2).

php_packages_state: "present"
Expand Down
3 changes: 3 additions & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ php_packages_extra: []
# Default PHP version to install on Debian-based OSes (OS-specific).
# php_default_version_debian: ""

# Default PHP version to install on RedHat-based OSes (OS-specific).
# php_default_version_redhat: ""

# PHP package state; use 'present' to make sure it's installed, or 'latest' if
# you want to upgrade or switch versions using a new repo.
php_packages_state: present
Expand Down
5 changes: 5 additions & 0 deletions tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@
php_default_version_debian: "{{ __php_default_version_debian }}"
when: php_default_version_debian is not defined and ansible_os_family == 'Debian'

- name: Set the default PHP version for RedHat-based OSes.
set_fact:
php_default_version_redhat: "{{ __php_default_version_redhat }}"
when: php_default_version_redhat is not defined and ansible_os_family == 'RedHat'

- name: Define the name of the JSON extension package on Debian for PHP <8.
set_fact:
__php_json_package_debian: "{{ 'php' + php_default_version_debian + '-json' }}"
Expand Down
3 changes: 3 additions & 0 deletions tasks/setup-RedHat.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
---
- name: Set the default PHP version for RedHat-based OSes.
command: "dnf module enable -y php:{{ php_default_version_redhat }}"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is not idempotent. try

package:
  name: "@php:{{ php_default_version_redhat }}/common"

if you want to install from appstreams.


- name: Ensure PHP packages are installed.
package:
name: "{{ php_packages + php_packages_extra }}"
Expand Down
2 changes: 2 additions & 0 deletions vars/RedHat.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
---
__php_default_version_redhat: "7.2"

__php_packages:
- php
- php-cli
Expand Down