Browse Source

php ansible role with the ability to select a specific php version

master
parent
commit
46875a8cc5
7 changed files with 97 additions and 0 deletions
  1. +2
    -0
      defaults/main.yaml
  2. +5
    -0
      handlers/main.yaml
  3. +20
    -0
      tasks/apache.yaml
  4. +5
    -0
      tasks/main.yaml
  5. +8
    -0
      tasks/opcache.yaml
  6. +50
    -0
      tasks/setup.yaml
  7. +7
    -0
      templates/php-opcache.conf.j2

+ 2
- 0
defaults/main.yaml View File

@@ -1 +1,3 @@
--- ---
php_sury_repo: false
php_configure_opcache: false

+ 5
- 0
handlers/main.yaml View File

@@ -1 +1,6 @@
--- ---

- name: restart apache
service:
name: apache2
state: restarted

+ 20
- 0
tasks/apache.yaml View File

@@ -0,0 +1,20 @@
---

- name: find apache php modules which are not of the selected version
find:
path: /etc/apache2/mods-enabled/
file_type: link
patterns: php*
excludes: "php{{php_version}}*"
register: _find_php_apache_mods

- name: disable apache php modules which are not of the selected version
file:
path: "{{item}}"
state: absent
with_items: "{{ _find_php_apache_mods | json_query('files[].path') }}"

- name: enable php apache module
apache2_module:
name: "php{{php_version}}"
state: present

+ 5
- 0
tasks/main.yaml View File

@@ -1 +1,6 @@
--- ---

- import_tasks: setup.yaml
- import_tasks: apache.yaml
- import_tasks: opcache.yaml
when: php_configure_opcache

+ 8
- 0
tasks/opcache.yaml View File

@@ -0,0 +1,8 @@

---

- name: enable php opcache
template:
src: php-opcache.conf.j2
dest: /etc/php/{{php_version}}/apache2/conf.d/opcache.ini
notify: restart apache

+ 50
- 0
tasks/setup.yaml View File

@@ -0,0 +1,50 @@
---

- when: php_sury_repo
block:
- name: sury.org repo requirements
apt:
pkg:
- apt-transport-https
- ca-certificates

- name: sury.org repo key
get_url:
url: https://packages.sury.org/php/apt.gpg
dest: /etc/apt/trusted.gpg.d/php.gpg
checksum: sha256:ace18406ecfe44292566bba8fc2d922370bc9531808a6319019bada3f7b3eab0

- name: sury.org repo
apt_repository:
repo: deb https://packages.sury.org/php/ {{ansible_distribution_release}} main
filename: php

- name: ensure sury.org repo is not present
file:
path: /etc/apt/sources.list.d/php.list
state: absent

- when: not php_version is defined
block:
- name: debian php-cli package
apt:
pkg: php-cli

- name: get installed php version
command: php
args:
stdin: '<?php echo phpversion(); ?>'
register: _get_installed_php_version
changed_when: false

- set_fact:
php_version: "{{ _get_installed_php_version.stdout.split('.')[0:2]|join('.') }}"

- name: debian packages
apt:
pkg:
- php{{php_version}}-cli
- libapache2-mod-php{{php_version}}
- php{{php_version}}-xml
- php{{php_version}}-json
- php{{php_version}}-mbstring

+ 7
- 0
templates/php-opcache.conf.j2 View File

@@ -0,0 +1,7 @@
opcache.enable=1
opcache.enable_cli=1
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=10000
opcache.memory_consumption=128
opcache.save_comments=1
opcache.revalidate_freq=1

Loading…
Cancel
Save