40 Commits
1.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
E Mantel
115e5bb19c Update README.md 2016-03-15 19:51:11 +01:00
Emilien Mantel
428e1aa162 Don't need php-config to configure xdebug 2016-03-06 19:23:08 +01:00
Emilien Mantel
dea67d8aea Fix deprecation warnings 2016-03-06 15:36:50 +01:00
Emilien Mantel
8763e3b789 Remove phpX-dev (prevent install php5 with php7) 2016-03-06 15:32:31 +01:00
Emilien Mantel
8b1846d94a Add travis webhook to galaxy 2016-03-05 12:06:40 +01:00
Emilien Mantel
b294234dec Merge branch 'php7'
Conflicts:
	tests/inventory
	tests/test.sh
2016-03-04 17:34:46 +01:00
Emilien Mantel
87e7497b7f Force php variable 2016-03-04 08:07:57 +01:00
Emilien Mantel
70e2bf3b50 Add dotdeb gpg key in tests 2016-03-04 07:58:22 +01:00
Emilien Mantel
7829d09f4c Fix script called by docker/travis 2016-03-04 07:48:52 +01:00
Emilien Mantel
e257e8bde7 Simplify tests (don't need dotdeb role + force php_version) 2016-03-04 07:12:41 +01:00
Emilien Mantel
4721f8a4ec Don't need inventory file for localhost 2016-03-04 06:37:12 +01:00
Emilien Mantel
fd3d404c31 README : remove wheezy support, add PHP7 support 2016-02-27 13:19:28 +01:00
Emilien Mantel
675ef60b6d Galaxy 1.1 compat 2016-02-27 13:08:45 +01:00
Emilien Mantel
9ec6fbf952 Install Opcache only on PHP >= 7.0 2016-02-27 13:05:02 +01:00
Emilien Mantel
c092025337 PHP7 now supports APCu / Opcache 2016-02-27 12:51:30 +01:00
Emilien Mantel
5162d00f82 Ignore fails tries 2016-02-27 12:39:05 +01:00
Emilien Mantel
dfa55e3cb6 PHP7 now suports Xdebug 2016-02-27 12:38:34 +01:00
Emilien Mantel
089fd3bbb4 Use official debian jessie boxes 2016-02-27 12:14:34 +01:00
Emilien Mantel
53aae314b4 Dotdeb on php 5.6 2016-01-22 17:24:15 +01:00
Emilien Mantel
9b55e91711 Travis should load php version with group 2016-01-22 17:17:38 +01:00
Emilien Mantel
9711cd5d15 Fix travis with dotdeb (Jessie) 2016-01-22 16:57:32 +01:00
Emilien Mantel
d79928e41a Fix mysql package 2016-01-22 16:38:02 +01:00
Emilien Mantel
2fa6bc2846 Travis maanges now PHP version 2016-01-22 16:29:43 +01:00
Emilien Mantel
74732767a5 Travis badge on master branch 2016-01-22 16:07:56 +01:00
Emilien Mantel
862848c7f8 Travis support many PHP version 2016-01-22 16:04:26 +01:00
Emilien Mantel
ee228b05b6 PHP7 Implementation 2016-01-22 15:57:29 +01:00
Emilien Mantel
d1d258a809 vagrant boxes many php and debian versions 2016-01-22 12:10:48 +01:00
Emilien Mantel
94c708863d Add Ansible Galaxy badge 2015-10-07 19:47:26 +02:00
Emilien Mantel
460caeedc6 Fix travis with Docker 2015-10-07 19:38:24 +02:00
30 changed files with 293 additions and 152 deletions

1
.gitignore vendored
View File

@@ -1,2 +1,3 @@
.vagrant*
*.swp
*.retry

View File

@@ -1,11 +1,49 @@
env:
- PLATFORM=debian-wheezy
- PLATFORM=debian-jessie
- 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: true
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:
- curl -sLo - http://j.mp/install-travis-docker | sh -xe
- pip install "$ANSIBLE_VERSION"
script:
- ./run '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

@@ -1,15 +1,22 @@
Ansible PHP (+FPM) role for Debian
==================================
[![Build Status](https://travis-ci.org/HanXHX/ansible-php.svg)](https://travis-ci.org/HanXHX/ansible-php)
[![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 Wheezy/Jessie. Depending of your PHP version: manage APC(u) / Opcache.
Install PHP (php-fpm optional) on Debian. Manage APCu, Opcache, Xdebug.
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 Wheezy, you can use many PHP version: 5.4 from Debian repository and 5.5/5.6 from [Dotdeb](https://www.dotdeb.org). With my [dotdeb role](https://github.com/HanXHX/ansible-debian-dotdeb), you can choose which version you want.
Role Variables
--------------
@@ -18,6 +25,7 @@ You should look at [default vars](defaults/main.yml).
### Writable vars
- `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).
@@ -35,7 +43,7 @@ Note:
- You can override with `php_ini_fpm`/`php_ini_cli`, but it breaks idempotence.
#### OpCache settings (PHP >= 5.5)
#### OpCache settings
See [Opcache doc](https://secure.php.net/manual/en/opcache.configuration.php)
@@ -119,7 +127,6 @@ See [Xdebug doc](http://xdebug.org/docs/all_settings)
- `php_xdebug_var_display_max_data`
- `php_xdebug_var_display_max_depth`
### Read only vars
- `php_packages`: minimal package list to install
@@ -140,12 +147,12 @@ Example Playbook
roles:
- { role: HanXHX.php }
### Debian Wheezy with PHP 5.5 CLI (no FPM)
### Debian Jessie with PHP 7.0 CLI (no FPM)
- hosts: wheezy-servers
- hosts: jessie-servers
roles:
- { role: HanXHX.dotdeb, dotdeb_php_version: "5.5" }
- { role: HanXHX.php, php_install_fpm: false }
- { role: HanXHX.dotdeb }
- { role: HanXHX.php, php_version: '7.0', php_install_fpm: false }
License
-------
@@ -155,6 +162,5 @@ GPLv2
Author Information
------------------
- You can find many other roles in my GitHub "lab": https://github.com/HanXHX/my-ansible-playbooks
- All issues, pull-request are welcome :)
- Twitter: [@hanxhx_](https://twitter.com/hanxhx_)
- All issues, pull-requests are welcome :)

52
Vagrantfile vendored
View File

@@ -5,27 +5,53 @@
Vagrant.configure("2") do |config|
vms = [
[ "debian-wheezy", "deb/wheezy-amd64" , "192.168.33.87" ],
[ "debian-jessie", "deb/jessie-amd64", "192.168.33.88" ]
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.groups = { "test" => [ vm[0] ] }
ansible.verbose = 'vv'
ansible.sudo = true
ansible.sudo = true
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,5 +1,6 @@
---
php_version: '{{ php_default_version }}'
php_install_fpm: true
php_install_xdebug: false
php_extra_packages: []
@@ -15,7 +16,7 @@ php_ini:
php_ini_fpm: []
php_ini_cli: []
# OpCache settings (PHP >= 5.5)
# OpCache settings
php_opcache_enable: "1"
php_opcache_enable_cli: "0"
php_opcache_memory_consumption: "96"
@@ -92,10 +93,12 @@ php_xdebug_var_display_max_depth: '3'
# PHP-FPM
php_fpm_poold:
- pool_name: 'www'
listen: '/var/run/php5-fpm.sock'
listen: '{{ php_default_fpm_sock }}'
pm: 'dynamic'
pm_max_children: 250
pm_start_servers: 10
pm_min_spare_servers: 10
pm_max_spare_servers: 20
# Hack
php_default_version: 'NONE'

View File

@@ -1,5 +1,5 @@
---
- name: restart php-fpm
action: service name=php5-fpm state=restarted
service: name='{{ php_fpm_service }}' state=restarted
when: php_install_fpm

View File

@@ -1,17 +1,23 @@
---
galaxy_info:
author: Emilien Mantel
description: Install and configure PHP (+ FPM is wanted)
description: Install and configure PHP 5.6/7.0/7.1 (+ FPM is wanted)
company:
license: GPLv2
min_ansible_version: 1.8
min_ansible_version: 2.0
platforms:
- name: Debian
versions:
- wheezy
- jessie
categories:
galaxy_tags:
- development
- web
- php
- php5.6
- php5
- php7
- php7.0
- php7.1
- debian
dependencies: []

View File

@@ -1,16 +1,21 @@
---
- name: APT | Install PHP-FPM
apt: pkg=php5-fpm state=latest
apt: pkg={{ php_fpm_service }} state=present
- name: LINEINFILE | PHP configuration
lineinfile: dest=/etc/php5/fpm/php.ini regexp='^;?{{ item.key }}' line='{{ item.key }} = {{ item.value }}'
lineinfile: >
dest='{{ php_etc_dir }}/fpm/php.ini'
regexp='^;?{{ item.key }}'
line='{{ item.key }} = {{ item.value }}'
with_flattened:
- php_ini
- php_ini_fpm
- "{{ php_ini }}"
- "{{ php_ini_fpm }}"
notify: restart php-fpm
- name: TEMPLATE | Deploy pool configuration
template: src=etc/php5/fpm/pool.d/pool.conf.j2 dest=/etc/php5/fpm/pool.d/{{ item.pool_name }}.conf
with_items: php_fpm_poold
template: >
src=etc/__php__/fpm/pool.d/pool.conf.j2
dest='{{ php_etc_dir }}/fpm/pool.d/{{ item.pool_name }}.conf'
with_items: "{{ php_fpm_poold }}"
notify: restart php-fpm

View File

@@ -1,40 +1,43 @@
---
- name: APT | Install PHP packages
apt: pkg={{ item }} state=latest update_cache=yes cache_valid_time=3600
with_flattened:
- php_packages
- php_extra_packages
- name: INCLUDE_VARS | Related to OS
include_vars: "{{ ansible_distribution }}-{{ ansible_distribution_major_version }}.yml"
- name: COMMAND | Get PHP extension dir
command: php-config --extension-dir
- name: ASSERT | Check variables
assert:
that: "php_version in php_managed_versions"
- 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
register: php_extension_dir
- name: APT | Install PHP packages
apt: pkg={{ item }} state=present
with_flattened:
- "{{ php_packages }}"
- "{{ php_extra_packages }}"
notify: restart php-fpm
- name: INCLUDE | PHP-FPM
include: fpm.yml
when: php_install_fpm
- name: LINEINFILE | PHP configuration
lineinfile: dest=/etc/php5/cli/php.ini regexp='^;?{{ item.key }}' line='{{ item.key }} = {{ item.value }}'
lineinfile: >
dest='{{ php_etc_dir }}/cli/php.ini'
regexp='^;?{{ item.key }}'
line='{{ item.key }} = {{ item.value }}'
with_flattened:
- php_ini
- php_ini_cli
- "{{ php_ini }}"
- "{{ php_ini_cli }}"
- name: INCLUDE | Xdebug
include: xdebug.yml
when: php_install_xdebug
- name: SHELL | Get PHP version on apt
shell: php -v | head -n 1 | awk '{ print $2 }'
register: php_apt_version
changed_when: false
- name: APT | Install and configure php-apcu / opcache (PHP 5.5+ only)
include: php55min.yml
when: php_apt_version.stdout|version_compare('5.5', 'ge', False)
- name: APT | Install and configure php-apc (PHP 5.4 max only)
include: php54max.yml
when: php_apt_version.stdout|version_compare('5.5', 'lt', False)
- name: APT | Install and configure opcache
include: opcache.yml

20
tasks/opcache.yml Normal file
View File

@@ -0,0 +1,20 @@
---
- name: APT | Install APCu
apt: pkg="{{ php_apt_prefix }}apcu" state=present
- name: APT | Install Opcache
apt: pkg="{{ php_apt_prefix }}opcache" state=present
when: php_version | version_compare('7.0', 'ge')
- name: TEMPLATE | Configure APCu
template: >
src=etc/__php__/mods-available/opcache.ini.j2
dest="{{ php_mods_dir }}/opcache.ini"
notify: restart php-fpm
- name: TEMPLATE | Configure APCu
template: >
src=etc/__php__/mods-available/apcu.ini.j2
dest={{ php_mods_dir }}/apcu.ini
notify: restart php-fpm

View File

@@ -1,11 +0,0 @@
---
- name: APT | Install php-apcu
apt: pkg=php-apc state=latest
- name: SET_FACT | Set APC
set_fact: php_apc_package="apc"
- name: TEMPLATE | Configure APC
template: src=etc/php5/mods-available/apcu.ini.j2 dest=/etc/php5/mods-available/apc.ini
notify: restart php-fpm

View File

@@ -1,14 +0,0 @@
---
- name: APT | Install php-apcu
apt: pkg=php5-apcu state=latest
- name: SET_FACT | Set APCu
set_fact: php_apc_package="apcu"
- name: TEMPLATE | Configure Opcache / APCu
template: src=etc/php5/mods-available/{{ item }}.ini.j2 dest=/etc/php5/mods-available/{{ item }}.ini
with_items:
- apcu
- opcache
notify: restart php-fpm

View File

@@ -1,13 +1,21 @@
---
- name: APT | Install php-xdebug
apt: pkg=php5-xdebug state=latest update_cache=yes cache_valid_time=3600
apt: >
pkg="{{ php_apt_prefix }}xdebug"
state=present
update_cache=yes
cache_valid_time=3600
- name: SHELL | Get Xdebug version
shell: dpkg -l | awk '$2 ~ /^php5-xdebug$/ { print $3 }'
shell: dpkg -l | awk '$2 ~ /xdebug$/ { print $3 }'
changed_when: false
register: xdebug_version
- name: TEMPLATE | Deploy module configurations
template: src=etc/php5/mods-available/xdebug.ini.j2 dest=/etc/php5/mods-available/xdebug.ini owner=root mode=0644
template: >
src=etc/__php__/mods-available/xdebug.ini.j2
dest={{ php_mods_dir }}/xdebug.ini
owner=root
mode=0644
notify: restart php-fpm

View File

@@ -1,8 +1,4 @@
;
; {{ ansible_managed }}
;
extension={{ php_apc_package }}.so
extension=apcu.so
; apc.enabled can be set to 0 to disable APC
apc.enable={{ php_apc_enable }}
@@ -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,10 +1,6 @@
; --------------------------------------
; {{ ansible_managed }}
; --------------------------------------
; configuration for php xdebug module
; priority=20
zend_extension={{ php_extension_dir.stdout }}/xdebug.so
zend_extension=xdebug.so
{% if xdebug_version.stdout|version_compare('2.3', 'gt') %}
{% endif %}
@@ -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"]

View File

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

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 +0,0 @@
localhost

View File

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

View File

@@ -4,37 +4,75 @@
vars:
vhost: 'test.local'
php_extra_packages:
- 'php5-memcached'
- '{{ php_apt_prefix }}recode'
php_install_xdebug: true
pre_tasks:
- 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', 'eq')
- name: INCLUDE | Sury
include: includes/sury.yml
when: >
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:/var/run/php5-fpm.sock; } }'
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 5.*<' | 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

@@ -1,11 +1,9 @@
---
php_packages:
- php5-cli
- php5-curl
- php5-gd
- php5-mcrypt
- php5-mysqlnd
- php5-intl
- php5-dev
- '{{ php_apt_prefix }}cli'
- '{{ php_apt_prefix }}curl'
- '{{ php_apt_prefix }}gd'
- '{{ php_apt_prefix }}mcrypt'
- '{{ php_mysql_package }}'
- '{{ php_apt_prefix }}intl'

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

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

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

@@ -0,0 +1,8 @@
---
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/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'