mirror of
https://github.com/HanXHX/ansible-php.git
synced 2026-02-28 09:42:09 +07:00
Compare commits
16 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8e53b9cd80 | ||
|
|
cbceba6897 | ||
|
|
d836862837 | ||
|
|
df8b58b46a | ||
|
|
de41097cde | ||
|
|
71721d1afc | ||
|
|
3d7c68e700 | ||
|
|
6d4a7e1a08 | ||
|
|
f8ddae5064 | ||
|
|
f38aa400b3 | ||
|
|
8758a9b7dc | ||
|
|
2a6b921b5e | ||
|
|
1bce22acbd | ||
|
|
7f7087cdb2 | ||
|
|
2987051153 | ||
|
|
7727e19da9 |
39
.travis.yml
39
.travis.yml
@@ -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/2.0.1/vagrant_2.0.1_x86_64.deb
|
||||
- sudo dpkg -i vagrant_2.0.1_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/
|
||||
|
||||
29
README.md
29
README.md
@@ -3,15 +3,24 @@ Ansible PHP (+FPM) role for Debian
|
||||
|
||||
[](https://galaxy.ansible.com/HanXHX/php) [](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 | PHP 7.2 |
|
||||
|:-------------:|:---------:|:-------------------------:|:---------------------:|:------------:|
|
||||
| Debian Jessie | Yes | Yes (from Dotdeb or Sury) | Yes (Dotdeb or Sury) | Yes (Sury) |
|
||||
| Debian Strech | No | Yes | Yes (Sury) | Yes (Sury) |
|
||||
|
||||
Links:
|
||||
- [Dotdeb](https://www.dotdeb.org)
|
||||
- [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 +29,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).
|
||||
@@ -154,6 +163,18 @@ License
|
||||
|
||||
GPLv2
|
||||
|
||||
Donation
|
||||
--------
|
||||
|
||||
If this code helped you, or if you’ve used them for your projects, feel free to buy me some :beers:
|
||||
|
||||
- Bitcoin: `1BQwhBeszzWbUTyK4aUyq3SRg7rBSHcEQn`
|
||||
- Ethereum: `63abe6b2648fd892816d87a31e3d9d4365a737b5`
|
||||
- Litecoin: `LeNDw34zQLX84VvhCGADNvHMEgb5QyFXyD`
|
||||
- Monero: `45wbf7VdQAZS5EWUrPhen7Wo4hy7Pa7c7ZBdaWQSRowtd3CZ5vpVw5nTPphTuqVQrnYZC72FXDYyfP31uJmfSQ6qRXFy3bQ`
|
||||
|
||||
No crypto-currency? :star: the project is also a way of saying thank you! :sunglasses:
|
||||
|
||||
Author Information
|
||||
------------------
|
||||
|
||||
|
||||
56
Vagrantfile
vendored
56
Vagrantfile
vendored
@@ -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.become = 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.become = true
|
||||
ansible.extra_vars = opts[:vars]
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,20 +1,17 @@
|
||||
---
|
||||
|
||||
php_version: '5.6'
|
||||
php_version: '{{ php_default_version }}'
|
||||
php_install_fpm: true
|
||||
php_install_xdebug: false
|
||||
php_extra_packages: []
|
||||
|
||||
# php.ini config
|
||||
php_ini:
|
||||
- key: 'date.timezone'
|
||||
value: 'Europe/Paris'
|
||||
- key: 'expose_php'
|
||||
value: 'Off'
|
||||
- key: 'memory_limit'
|
||||
value: '256M'
|
||||
php_ini_fpm: []
|
||||
php_ini_cli: []
|
||||
'date.timezone': 'Europe/Paris'
|
||||
'expose_php': 'Off'
|
||||
'memory_limit': '256M'
|
||||
php_ini_fpm: {}
|
||||
php_ini_cli: {}
|
||||
|
||||
# OpCache settings
|
||||
php_opcache_enable: "1"
|
||||
@@ -100,3 +97,5 @@ php_fpm_poold:
|
||||
pm_min_spare_servers: 10
|
||||
pm_max_spare_servers: 20
|
||||
|
||||
# Hack
|
||||
php_default_version: 'NONE'
|
||||
|
||||
@@ -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,6 +13,8 @@ galaxy_info:
|
||||
- development
|
||||
- web
|
||||
- php
|
||||
- php5.6
|
||||
- php5
|
||||
- php7
|
||||
- debian
|
||||
dependencies: []
|
||||
|
||||
@@ -1,16 +1,14 @@
|
||||
---
|
||||
|
||||
- name: APT | Install PHP-FPM
|
||||
apt: pkg={{ php_fpm_service }} state=latest
|
||||
apt: pkg={{ php_fpm_service }} state=present
|
||||
|
||||
- name: LINEINFILE | PHP configuration
|
||||
lineinfile: >
|
||||
dest='{{ php_etc_dir }}/fpm/php.ini'
|
||||
regexp='^;?{{ item.key }}'
|
||||
line='{{ item.key }} = {{ item.value }}'
|
||||
with_flattened:
|
||||
- "{{ php_ini }}"
|
||||
- "{{ php_ini_fpm }}"
|
||||
lineinfile:
|
||||
dest: '{{ php_etc_dir }}/fpm/php.ini'
|
||||
regexp: '^;?{{ item.key }}'
|
||||
line: '{{ item.key }} = {{ item.value }}'
|
||||
with_dict: "{{ php_ini | combine(php_ini_fpm) }}"
|
||||
notify: restart php-fpm
|
||||
|
||||
- name: TEMPLATE | Deploy pool configuration
|
||||
|
||||
@@ -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"
|
||||
@@ -16,24 +19,21 @@
|
||||
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='{{ php_etc_dir }}/cli/php.ini'
|
||||
regexp='^;?{{ item.key }}'
|
||||
line='{{ item.key }} = {{ item.value }}'
|
||||
with_flattened:
|
||||
- "{{ php_ini }}"
|
||||
- "{{ php_ini_cli }}"
|
||||
lineinfile:
|
||||
dest: '{{ php_etc_dir }}/cli/php.ini'
|
||||
regexp: '^;?{{ item.key }}'
|
||||
line: '{{ item.key }} = {{ item.value }}'
|
||||
with_dict: "{{ php_ini_cli }}"
|
||||
|
||||
- name: INCLUDE | Xdebug
|
||||
include: xdebug.yml
|
||||
when: php_install_xdebug
|
||||
|
||||
- name: APT | Install and configure opcache
|
||||
include: opcache.yml
|
||||
|
||||
|
||||
@@ -1,21 +1,38 @@
|
||||
---
|
||||
|
||||
- name: APT | Install php-xdebug
|
||||
apt: >
|
||||
pkg="{{ php_apt_prefix }}xdebug"
|
||||
state=latest
|
||||
update_cache=yes
|
||||
cache_valid_time=3600
|
||||
- block:
|
||||
|
||||
- name: SHELL | Get Xdebug version
|
||||
shell: dpkg -l | awk '$2 ~ /xdebug$/ { print $3 }'
|
||||
changed_when: false
|
||||
register: xdebug_version
|
||||
- name: APT | Install php-xdebug
|
||||
apt:
|
||||
pkg: "{{ php_apt_prefix }}xdebug"
|
||||
state: present
|
||||
update_cache: yes
|
||||
cache_valid_time: 3600
|
||||
|
||||
- name: TEMPLATE | Deploy module configurations
|
||||
template: >
|
||||
src=etc/__php__/mods-available/xdebug.ini.j2
|
||||
dest={{ php_mods_dir }}/xdebug.ini
|
||||
owner=root
|
||||
mode=0644
|
||||
notify: restart php-fpm
|
||||
- name: SHELL | Get Xdebug version
|
||||
shell: dpkg -l | awk '$2 ~ /xdebug$/ { print $3 }'
|
||||
changed_when: false
|
||||
register: xdebug_version
|
||||
|
||||
- name: TEMPLATE | Deploy module configurations
|
||||
template:
|
||||
src: "etc/__php__/mods-available/xdebug.ini.j2"
|
||||
dest: "{{ php_mods_dir }}/xdebug.ini"
|
||||
owner: root
|
||||
mode: 0644
|
||||
notify: restart php-fpm
|
||||
|
||||
when: php_install_xdebug
|
||||
|
||||
- block:
|
||||
|
||||
# We can't uninstall as simple way. We can uninstall with php7.0-xdebug (virtual package), but removing virtual package doesn't affect real package.
|
||||
# On Jessie: php5-xdebug, php-xdebug (sury for PHP 5.6/7.0/7.1/7.2), php5-xdebug + php7.0-xdebug (dotdeb)
|
||||
# On Stretch: php-xdebug
|
||||
|
||||
- name: COMMAND | Disable xdebug package
|
||||
command: phpdismod -v {{ php_version }} xdebug
|
||||
args:
|
||||
removes: "{{ php_etc_dir }}/cli/conf.d/20-xdebug.ini"
|
||||
|
||||
when: not php_install_xdebug
|
||||
|
||||
@@ -231,7 +231,11 @@ pm.max_spare_servers = {{ item.pm_max_spare_servers }}
|
||||
; anything, but it may not be a good idea to use the .php extension or it
|
||||
; may conflict with a real PHP file.
|
||||
; Default Value: not set
|
||||
;pm.status_path = /status
|
||||
{% if item.status_path is defined %}
|
||||
pm.status_path = {{ item.status_path }}
|
||||
{% else %}
|
||||
;pm.status.path = /status
|
||||
{% endif %}
|
||||
|
||||
; The ping URI to call the monitoring page of FPM. If this value is not set, no
|
||||
; URI will be recognized as a ping page. This could be used to test from outside
|
||||
@@ -243,12 +247,20 @@ pm.max_spare_servers = {{ item.pm_max_spare_servers }}
|
||||
; anything, but it may not be a good idea to use the .php extension or it
|
||||
; may conflict with a real PHP file.
|
||||
; Default Value: not set
|
||||
{% if item.ping_path is defined %}
|
||||
ping.path = {{ item.ping_path }}
|
||||
{% else %}
|
||||
;ping.path = /ping
|
||||
{% endif %}
|
||||
|
||||
; This directive may be used to customize the response of a ping request. The
|
||||
; response is formatted as text/plain with a 200 response code.
|
||||
; Default Value: pong
|
||||
{% if item.ping_response is defined %}
|
||||
ping.response = {{ item.ping_response }}
|
||||
{% else %}
|
||||
;ping.response = pong
|
||||
{% endif %}
|
||||
|
||||
; The access log file
|
||||
; Default: not set
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
FROM williamyeh/ansible:debian8-onbuild
|
||||
|
||||
RUN apt-get update
|
||||
CMD ["sh", "tests/test.sh", "5.6"]
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
FROM williamyeh/ansible:debian8-onbuild
|
||||
|
||||
RUN apt-get update
|
||||
CMD ["sh", "tests/test.sh", "7.0"]
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
php_version: '5.6'
|
||||
@@ -1 +0,0 @@
|
||||
php_version: '7.0'
|
||||
7
tests/includes/dotdeb.yml
Normal file
7
tests/includes/dotdeb.yml
Normal 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
7
tests/includes/sury.yml
Normal 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
|
||||
@@ -1,7 +0,0 @@
|
||||
localhost
|
||||
|
||||
[php-5.6]
|
||||
localhost
|
||||
|
||||
[php-7.0]
|
||||
localhost
|
||||
23
tests/templates/site.j2
Normal file
23
tests/templates/site.j2
Normal file
@@ -0,0 +1,23 @@
|
||||
server {
|
||||
server_name {{ vhost }};
|
||||
|
||||
root /var/www;
|
||||
|
||||
{% if php_fpm_poold.0.status_path is defined %}
|
||||
location = {{ php_fpm_poold.0.status_path }} {
|
||||
include {{ nginx_include }};
|
||||
fastcgi_pass unix:{{ php_default_fpm_sock }};
|
||||
}
|
||||
{% endif %}
|
||||
{% if php_fpm_poold.0.ping_path is defined %}
|
||||
location = {{ php_fpm_poold.0.ping_path }} {
|
||||
include {{ nginx_include }};
|
||||
fastcgi_pass unix:{{ php_default_fpm_sock }};
|
||||
}
|
||||
{% endif %}
|
||||
|
||||
location ~ \.php$ {
|
||||
include {{ nginx_include }};
|
||||
fastcgi_pass unix:{{ php_default_fpm_sock }};
|
||||
}
|
||||
}
|
||||
@@ -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)
|
||||
@@ -6,50 +6,104 @@
|
||||
php_extra_packages:
|
||||
- '{{ php_apt_prefix }}recode'
|
||||
php_install_xdebug: true
|
||||
php_ini_fpm:
|
||||
display_errors: 'Off'
|
||||
php_ini_cli:
|
||||
error_reporting: 'E_ALL'
|
||||
php_fpm_poold:
|
||||
- pool_name: 'www'
|
||||
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
|
||||
status_path: '/status'
|
||||
ping_path: '/ping'
|
||||
ping_response: 'ok'
|
||||
|
||||
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 }}; } }'
|
||||
|
||||
- name: TEMPLATE | Nginx site config
|
||||
template:
|
||||
src: templates/site.j2
|
||||
dest: /etc/nginx/sites-enabled/{{ vhost }}
|
||||
notify: reload nginx
|
||||
|
||||
- name: FILE | Delete default site
|
||||
file:
|
||||
path: /etc/nginx/sites-enabled/default
|
||||
state: absent
|
||||
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 == ''
|
||||
|
||||
- name: URI | Check ping
|
||||
uri:
|
||||
url: "http://localhost{{ php_fpm_poold.0.ping_path }}"
|
||||
when: php_fpm_poold.0.ping_path is defined
|
||||
|
||||
- name: URI | Check status
|
||||
uri:
|
||||
url: "http://localhost{{ php_fpm_poold.0.status_path }}"
|
||||
when: php_fpm_poold.0.status_path is defined
|
||||
|
||||
6
vars/Debian-8.yml
Normal file
6
vars/Debian-8.yml
Normal file
@@ -0,0 +1,6 @@
|
||||
php_default_version: '5.6'
|
||||
php_managed_versions:
|
||||
- '5.6'
|
||||
- '7.0'
|
||||
- '7.1'
|
||||
- '7.2'
|
||||
5
vars/Debian-9.yml
Normal file
5
vars/Debian-9.yml
Normal file
@@ -0,0 +1,5 @@
|
||||
php_default_version: '7.0'
|
||||
php_managed_versions:
|
||||
- '7.0'
|
||||
- '7.1'
|
||||
- '7.2'
|
||||
@@ -7,7 +7,3 @@ php_packages:
|
||||
- '{{ php_apt_prefix }}mcrypt'
|
||||
- '{{ php_mysql_package }}'
|
||||
- '{{ php_apt_prefix }}intl'
|
||||
|
||||
php_managed_versions:
|
||||
- '5.6'
|
||||
- '7.0'
|
||||
|
||||
8
vars/php-7.1.yml
Normal file
8
vars/php-7.1.yml
Normal 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'
|
||||
Reference in New Issue
Block a user