11 Commits
2.0 ... 2.1

Author SHA1 Message Date
Emilien Mantel
f8ddae5064 Check managed php version by OS - Fixes #9 2017-06-14 17:35:51 +02:00
Emilien Mantel
f38aa400b3 Load default PHP version per OS release 2017-06-13 11:51:51 +02:00
Emilien Mantel
8758a9b7dc Fix long term idempotence: fpm pkg present state 2017-06-09 09:28:16 +02:00
E Mantel
2a6b921b5e Update README
Add doc/links about extra PHP version
2017-06-06 16:31:19 +02:00
Emilien Mantel
1bce22acbd Travis CI with vagrant + docker 2017-06-06 16:27:11 +02:00
Emilien Mantel
7f7087cdb2 Ignore warning on test.yml 2017-03-16 18:31:16 +01:00
Emilien Mantel
2987051153 Manages PHP 7.1 2017-03-16 18:23:39 +01:00
Emilien Mantel
7727e19da9 Restart PHP-FPM when new packages are installed 2017-03-16 16:10:18 +01:00
Emilien Mantel
bc501c9e25 ansible_managed breaks priority on phpdismod 2016-12-12 12:17:47 +01:00
Emilien Mantel
9111165a7c APT change status update:
- updating cache is not a change
- packages are 'present' (was latest) state
2016-12-08 17:38:10 +01:00
Emilien Mantel
ef9242f2fb Fix mods-available directory for PHP7 2016-08-25 18:09:33 +02:00
25 changed files with 178 additions and 97 deletions

View File

@@ -1,16 +1,49 @@
env:
- PLATFORM=debian-jessie-php-5.6
- PLATFORM=debian-jessie-php-7.0
- PLATFORM='docker-debian-jessie-php56' ANSIBLE_VERSION='ansible>=2.0,<2.1'
- PLATFORM='docker-debian-jessie-php70' ANSIBLE_VERSION='ansible>=2.0,<2.1'
- PLATFORM='docker-debian-jessie-php71' ANSIBLE_VERSION='ansible>=2.0,<2.1'
- PLATFORM='docker-debian-stretch-php70' ANSIBLE_VERSION='ansible>=2.0,<2.1'
- PLATFORM='docker-debian-stretch-php71' ANSIBLE_VERSION='ansible>=2.0,<2.1'
- PLATFORM='docker-debian-jessie-php56' ANSIBLE_VERSION='ansible>=2.1,<2.2'
- PLATFORM='docker-debian-jessie-php70' ANSIBLE_VERSION='ansible>=2.1,<2.2'
- PLATFORM='docker-debian-jessie-php71' ANSIBLE_VERSION='ansible>=2.1,<2.2'
- PLATFORM='docker-debian-stretch-php70' ANSIBLE_VERSION='ansible>=2.1,<2.2'
- PLATFORM='docker-debian-stretch-php71' ANSIBLE_VERSION='ansible>=2.1,<2.2'
- PLATFORM='docker-debian-jessie-php56' ANSIBLE_VERSION='ansible>=2.2,<2.3'
- PLATFORM='docker-debian-jessie-php70' ANSIBLE_VERSION='ansible>=2.2,<2.3'
- PLATFORM='docker-debian-jessie-php71' ANSIBLE_VERSION='ansible>=2.2,<2.3'
- PLATFORM='docker-debian-stretch-php70' ANSIBLE_VERSION='ansible>=2.2,<2.3'
- PLATFORM='docker-debian-stretch-php71' ANSIBLE_VERSION='ansible>=2.2,<2.3'
- PLATFORM='docker-debian-jessie-php56' ANSIBLE_VERSION='ansible>=2.3,<2.4'
- PLATFORM='docker-debian-jessie-php70' ANSIBLE_VERSION='ansible>=2.3,<2.4'
- PLATFORM='docker-debian-jessie-php71' ANSIBLE_VERSION='ansible>=2.3,<2.4'
- PLATFORM='docker-debian-stretch-php70' ANSIBLE_VERSION='ansible>=2.3,<2.4'
- PLATFORM='docker-debian-stretch-php71' ANSIBLE_VERSION='ansible>=2.3,<2.4'
sudo: required
dist: trusty
language: python
services:
- docker
before_install:
- wget https://releases.hashicorp.com/vagrant/1.9.5/vagrant_1.9.5_x86_64.deb
- sudo dpkg -i vagrant_1.9.5_x86_64.deb
install:
- pip install "$ANSIBLE_VERSION"
script:
- docker build -f tests/$PLATFORM.Dockerfile -t test-$PLATFORM . && docker run --name $PLATFORM test-$PLATFORM
- VAGRANT_DEFAULT_PROVIDER=docker vagrant up $PLATFORM
- >
VAGRANT_DEFAULT_PROVIDER=docker vagrant provision $PLATFORM
| grep -q 'changed=0.*failed=0'
&& (echo 'Idempotence test: pass' && exit 0)
|| (echo 'Idempotence test: fail' && exit 1)
- VAGRANT_DEFAULT_PROVIDER=docker vagrant status
notifications:
webhooks: https://galaxy.ansible.com/api/v1/notifications/

View File

@@ -3,15 +3,20 @@ Ansible PHP (+FPM) role for Debian
[![Ansible Galaxy](http://img.shields.io/badge/ansible--galaxy-HanXHX.php-blue.svg)](https://galaxy.ansible.com/HanXHX/php) [![Build Status](https://travis-ci.org/HanXHX/ansible-php.svg?branch=master)](https://travis-ci.org/HanXHX/ansible-php)
Install PHP (php-fpm optional) on Debian Jessie/Stretch. Manage APCu, Opcache, Xdebug.
Install PHP (php-fpm optional) on Debian. Manage APCu, Opcache, Xdebug.
Managed versions: 5.6 and 7.0
Managed OS / Versions
---------------------
| OS | PHP 5.6 | PHP 7.0 | PHP 7.1 |
|:-------------: |:-----------------: |:-------------------------: |:-------------------------: |
| Debian Jessie | Yes (from Debian) | Yes (from [Dotdeb](https://www.dotdeb.org) or [Sury](https://deb.sury.org/)) | Yes (from [Dotdeb](https://www.dotdeb.org) or [Sury](https://deb.sury.org/)) |
| Debian Strech | No | Yes (from Debian) | Yes (from [Sury](https://deb.sury.org/)) |
Requirements
------------
If you need PHP-FPM, you must install a webserver with FastCGI support. You can use my [nginx role](https://github.com/HanXHX/ansible-nginx).
On Debian Jessie, if you want PHP7.0, you must use [Dotdeb](https://www.dotdeb.org). You can use my [dotdeb role](https://github.com/HanXHX/ansible-debian-dotdeb).
Role Variables
--------------
@@ -20,7 +25,7 @@ You should look at [default vars](defaults/main.yml).
### Writable vars
- `php_version`: 5.6 (default) or 7.0
- `php_version`: 5.6 (default), 7.0, 7.1
- `php_install_fpm`: boolean, install and manage php-fpm (default is true)
- `php_install_xdebug`: boolean, install [Xdebug](http://xdebug.org)
- `php_extra_packages`: additional php packages to install (default is an empty list).

54
Vagrantfile vendored
View File

@@ -5,31 +5,53 @@
Vagrant.configure("2") do |config|
vms = [
[ "jessie-php-5.6", "debian/contrib-jessie64", "192.168.33.88", "5.6" ],
[ "jessie-php-7.0", "debian/contrib-jessie64", "192.168.33.89", "7.0" ],
[ "stretch-php-5.6", "sharlak/debian_stretch_64", "192.168.33.90", "5.6" ],
[ "stretch-php-7.0", "sharlak/debian_stretch_64", "192.168.33.91", "7.0" ]
vms_debian = [
{ :name => "debian-jessie-php56", :box => "debian/jessie64", :vars => { }},
{ :name => "debian-jessie-php70", :box => "debian/jessie64", :vars => { "php_version": '7.0' }},
{ :name => "debian-jessie-php71", :box => "debian/jessie64", :vars => { "php_version": '7.1' }},
{ :name => "debian-stretch-php70", :box => "debian/stretch64", :vars => { }},
{ :name => "debian-stretch-php71", :box => "debian/stretch64", :vars => { "php_version": '7.1' }}
]
config.vm.provider "virtualbox" do |v|
v.cpus = 1
v.memory = 256
end
conts = [
{ :name => "docker-debian-jessie-php56", :docker => "hanxhx/vagrant-ansible:debian8", :vars => { }},
{ :name => "docker-debian-jessie-php70", :docker => "hanxhx/vagrant-ansible:debian8", :vars => { "php_version": '7.0' }},
{ :name => "docker-debian-jessie-php71", :docker => "hanxhx/vagrant-ansible:debian8", :vars => { "php_version": '7.1' }},
{ :name => "docker-debian-stretch-php70", :docker => "hanxhx/vagrant-ansible:debian9", :vars => { }},
{ :name => "docker-debian-stretch-php71", :docker => "hanxhx/vagrant-ansible:debian9", :vars => { "php_version": '7.1' }}
]
vms.each do |vm|
config.vm.define vm[0] do |m|
m.vm.box = vm[1]
m.vm.network "private_network", ip: vm[2]
config.vm.network "private_network", type: "dhcp"
conts.each do |opts|
config.vm.define opts[:name] do |m|
m.vm.provider "docker" do |d|
d.image = opts[:docker]
d.remains_running = true
d.has_ssh = true
end
m.vm.provision "ansible" do |ansible|
ansible.playbook = "tests/test.yml"
ansible.verbose = 'vv'
ansible.sudo = true
ansible.extra_vars = {
php_version: vm[3]
}
ansible.extra_vars = opts[:vars]
end
end
end
vms_debian.each do |opts|
config.vm.define opts[:name] do |m|
m.vm.box = opts[:box]
m.vm.provider "virtualbox" do |v|
v.cpus = 1
v.memory = 256
end
m.vm.provision "ansible" do |ansible|
ansible.playbook = "tests/test.yml"
ansible.verbose = 'vv'
ansible.sudo = true
ansible.extra_vars = opts[:vars]
end
end
end
end

View File

@@ -1,6 +1,6 @@
---
php_version: '5.6'
php_version: '{{ php_default_version }}'
php_install_fpm: true
php_install_xdebug: false
php_extra_packages: []
@@ -100,3 +100,5 @@ php_fpm_poold:
pm_min_spare_servers: 10
pm_max_spare_servers: 20
# Hack
php_default_version: 'NONE'

View File

@@ -1,10 +1,10 @@
---
galaxy_info:
author: Emilien Mantel
description: Install and configure PHP 5.6/7.0 (+ FPM is wanted)
description: Install and configure PHP 5.6/7.0/7.1 (+ FPM is wanted)
company:
license: GPLv2
min_ansible_version: 1.9
min_ansible_version: 2.0
platforms:
- name: Debian
versions:
@@ -13,7 +13,11 @@ galaxy_info:
- development
- web
- php
- php5.6
- php5
- php7
- php7.0
- php7.1
- debian
dependencies: []

View File

@@ -1,7 +1,7 @@
---
- name: APT | Install PHP-FPM
apt: pkg={{ php_fpm_service }} state=latest
apt: pkg={{ php_fpm_service }} state=present
- name: LINEINFILE | PHP configuration
lineinfile: >

View File

@@ -1,5 +1,8 @@
---
- name: INCLUDE_VARS | Related to OS
include_vars: "{{ ansible_distribution }}-{{ ansible_distribution_major_version }}.yml"
- name: ASSERT | Check variables
assert:
that: "php_version in php_managed_versions"
@@ -7,11 +10,16 @@
- name: INCLUDE_VARS | Related to PHP version
include_vars: "php-{{ php_version }}.yml"
- name: APT | Update cache
apt: update_cache=yes cache_valid_time=3600
changed_when: false
- name: APT | Install PHP packages
apt: pkg={{ item }} state=latest update_cache=yes cache_valid_time=3600
apt: pkg={{ item }} state=present
with_flattened:
- "{{ php_packages }}"
- "{{ php_extra_packages }}"
notify: restart php-fpm
- name: INCLUDE | PHP-FPM
include: fpm.yml

View File

@@ -3,7 +3,7 @@
- name: APT | Install php-xdebug
apt: >
pkg="{{ php_apt_prefix }}xdebug"
state=latest
state=present
update_cache=yes
cache_valid_time=3600

View File

@@ -1,7 +1,3 @@
;
; {{ ansible_managed }}
;
extension=apcu.so
; apc.enabled can be set to 0 to disable APC
@@ -23,3 +19,7 @@ apc.file_update_protection={{ php_apc_file_update_protection }}
apc.slam_defense={{ php_apc_slam_defense }}
; Verification with ctime will avoid problems caused by programs such as svn or rsync by making sure inodes haven't changed since the last stat
apc.stat_ctime={{ php_apc_stat_ctime }}
;
; {{ ansible_managed }}
;

View File

@@ -1,7 +1,3 @@
;
; {{ ansible_managed }}
;
; configuration for php ZendOpcache module
; priority=05
zend_extension=opcache.so
@@ -15,3 +11,7 @@ opcache.max_wasted_percentage={{ php_opcache_max_wasted_percentage }}
opcache.validate_timestamps={{ php_opcache_validate_timestamps }}
opcache.revalidate_freq={{ php_opcache_revalidate_freq }}
opcache.max_file_size={{ php_opcache_max_file_size }}
;
; {{ ansible_managed }}
;

View File

@@ -1,7 +1,3 @@
; --------------------------------------
; {{ ansible_managed }}
; --------------------------------------
; configuration for php xdebug module
; priority=20
zend_extension=xdebug.so
@@ -63,3 +59,6 @@ xdebug_var_display_max_children={{ php_xdebug_var_display_max_children }}
xdebug_var_display_max_data={{ php_xdebug_var_display_max_data }}
xdebug_var_display_max_depth={{ php_xdebug_var_display_max_depth }}
; --------------------------------------
; {{ ansible_managed }}
; --------------------------------------

View File

@@ -1,5 +0,0 @@
FROM williamyeh/ansible:debian8-onbuild
RUN apt-get update
CMD ["sh", "tests/test.sh", "5.6"]

View File

@@ -1,5 +0,0 @@
FROM williamyeh/ansible:debian8-onbuild
RUN apt-get update
CMD ["sh", "tests/test.sh", "7.0"]

View File

@@ -1 +0,0 @@
php_version: '5.6'

View File

@@ -1 +0,0 @@
php_version: '7.0'

View File

@@ -0,0 +1,7 @@
---
- name: APT | Install DotDeb key
apt_key: url='http://www.dotdeb.org/dotdeb.gpg' state=present
- name: APT | Add Dotdeb repository
apt_repository: repo='deb http://packages.dotdeb.org {{ ansible_distribution_release }} all' state=present

7
tests/includes/sury.yml Normal file
View File

@@ -0,0 +1,7 @@
---
- name: APT | Install Sury key
apt_key: url='https://packages.sury.org/php/apt.gpg' state=present
- name: APT | Add Sury repository
apt_repository: repo='deb https://packages.sury.org/php/ {{ ansible_distribution_release }} main' state=present

View File

@@ -1,7 +0,0 @@
localhost
[php-5.6]
localhost
[php-7.0]
localhost

View File

@@ -1,23 +0,0 @@
#!/bin/sh
# Thanks to https://servercheck.in/blog/testing-ansible-roles-travis-ci-github
DIR=$( dirname $0 )
PLAYBOOK="$DIR/test.yml"
ANSIBLE_ARG="localhost"
set -ev
ansible --version
# Check syntax
ansible-playbook -i localhost, -c local --syntax-check -vv $PLAYBOOK
# Check role
ansible-playbook -i localhost, -c local -e "php_version=$1" --become -vv $PLAYBOOK
# Check indempotence
ansible-playbook -i localhost, -c local -e "php_version=$1" --become -vv $PLAYBOOK \
| grep -q 'changed=0.*failed=0' \
&& (echo 'Idempotence test: pass' && exit 0) \
|| (echo 'Idempotence test: fail' && exit 1)

View File

@@ -6,50 +6,73 @@
php_extra_packages:
- '{{ php_apt_prefix }}recode'
php_install_xdebug: true
pre_tasks:
- name: APT | Install DotDeb key
apt_key: url='http://www.dotdeb.org/dotdeb.gpg' state=present
- name: APT | Install packages
apt: pkg={{ item }} update_cache=yes cache_valid_time=3600
with_items: ['apt-transport-https', 'curl', 'lsb-release', 'ca-certificates']
- name: INCLUDE | Dotdeb
include: includes/dotdeb.yml
when: >
ansible_distribution_major_version | version_compare(8, 'eq') and
php_version | version_compare('7.0', 'ge')
- name: APT | Add Dotdeb repository for Jessie + PHP7
apt_repository: repo='deb http://packages.dotdeb.org jessie all' state=present
php_version | version_compare('7.0', 'eq')
- name: INCLUDE | Sury
include: includes/sury.yml
when: >
ansible_distribution_major_version | version_compare(8, 'eq') and
php_version | version_compare('7.0', 'ge')
ansible_distribution_major_version | version_compare(9, 'le') and
php_version | version_compare('7.1', 'eq')
- name: APT | Install nginx
apt: pkg=nginx state=present update_cache=yes cache_valid_time=3600
- name: SHELL | Get nginx version
shell: nginx -V 2>&1 | awk -F '/' '/nginx version/ { print $2 }'
register: nginx_version
changed_when: false
- set_fact: nginx_include="fastcgi_params"
when: nginx_version.stdout | version_compare('1.6', '<', true)
- set_fact: nginx_include="fastcgi.conf"
when: nginx_version.stdout | version_compare('1.6', '>=', true)
tasks:
- name: COPY | Vhost
copy: >
dest=/etc/nginx/sites-enabled/{{ vhost }}
content='server { server_name {{ vhost }}; root /var/www; location ~ \.php$ { include {{ nginx_include }}; fastcgi_pass unix:{{ php_default_fpm_sock }}; } }'
notify: reload nginx
handlers:
- name: reload nginx
service: name=nginx state=reloaded
roles:
- ../../
post_tasks:
- name: SHELL | Test php-cli
shell: php -i | grep '^PHP Version' | head -n 1
shell: php -i | grep '^PHP Version => {{ php_version }}' | head -n 1
changed_when: false
register: p
failed_when: p.stdout == ''
- name: FILE | Create /var/www
file: dest=/var/www state=directory
- name: COPY | Add phpinfo
copy: dest=/var/www/phpinfo.php content='<?php phpinfo();'
- name: SHELL | Check vhost
shell: "curl -v -H 'Host: {{ vhost }}' http://127.0.0.1/phpinfo.php 2> /dev/null | grep h1 | grep -o 'PHP Version [57].*<' | sed -r 's/<//g'"
shell: "curl -v -H 'Host: {{ vhost }}' http://127.0.0.1/phpinfo.php 2> /dev/null | grep h1 | grep -o 'PHP Version {{ php_version }}' | sed -r 's/<//g'"
args:
warn: false
changed_when: false
register: c
failed_when: c.stdout == ''

5
vars/Debian-8.yml Normal file
View File

@@ -0,0 +1,5 @@
php_default_version: '5.6'
php_managed_versions:
- '5.6'
- '7.0'
- '7.1'

4
vars/Debian-9.yml Normal file
View File

@@ -0,0 +1,4 @@
php_default_version: '7.0'
php_managed_versions:
- '7.0'
- '7.1'

View File

@@ -7,7 +7,3 @@ php_packages:
- '{{ php_apt_prefix }}mcrypt'
- '{{ php_mysql_package }}'
- '{{ php_apt_prefix }}intl'
php_managed_versions:
- '5.6'
- '7.0'

View File

@@ -4,5 +4,5 @@ php_apt_prefix: 'php7.0-'
php_etc_dir: '/etc/php/7.0'
php_fpm_service: 'php7.0-fpm'
php_default_fpm_sock: '/var/run/php/php7.0-fpm.sock'
php_mods_dir: '/etc/php/mods-available'
php_mods_dir: '/etc/php/7.0/mods-available'
php_mysql_package: 'php7.0-mysql'

8
vars/php-7.1.yml Normal file
View File

@@ -0,0 +1,8 @@
---
php_apt_prefix: 'php7.1-'
php_etc_dir: '/etc/php/7.1'
php_fpm_service: 'php7.1-fpm'
php_default_fpm_sock: '/var/run/php/php7.1-fpm.sock'
php_mods_dir: '/etc/php/7.1/mods-available'
php_mysql_package: 'php7.1-mysql'