14 Commits

Author SHA1 Message Date
Emilien M
75f09eaf59 Delete default pool if necessary (#10)
(when default pool 'www' not in pool list)
2019-04-19 14:36:35 +02:00
Emilien M
5abe99568a Support Debian Buster (#11) 2019-04-19 14:36:20 +02:00
Emilien Mantel
8b2c92a047 Force python 2.7 on travis 2019-04-19 11:28:50 +02:00
Emilien Mantel
0171ae8e20 Quick changes 2019-04-19 11:18:46 +02:00
Emilien Mantel
95892782ea Fix version compare 2019-04-19 10:59:00 +02:00
Emilien Mantel
f5b9eb78b7 Remove legacy 'include' module 2019-04-19 10:28:00 +02:00
Emilien Mantel
5ef6d09ac6 Min ansible version: 2.6 2019-02-20 16:40:02 +01:00
Emilien Mantel
e45df940cd Compat Ansible 2.5+ 2019-01-28 14:46:58 +01:00
Emilien Mantel
6c3aa5443a Remove legacy and useless file 2019-01-28 10:35:42 +01:00
Emilien Mantel
847941ebc6 Update README.md 2018-10-29 14:27:38 +01:00
Emilien Mantel
feff5576d2 Travis: test with ansible 2.4 to 2.6 2018-10-29 14:18:37 +01:00
Emilien Mantel
04547b496f Force install python-apt on Vagrant+Docker 2018-10-29 14:15:02 +01:00
Emilien Mantel
9f048ae918 Support PHP 7.3 on Debian/FreeBSD
- Fixes some issues on FreeBSD (Vagrant problems, loading vars files...)
- Add some platforms on Travis
2018-10-29 12:30:14 +01:00
Emilien Mantel
6a85f02fc1 Fix apcu package for Debian based systems 2018-03-19 08:51:58 +01:00
16 changed files with 148 additions and 75 deletions

View File

@@ -1,26 +1,27 @@
env: env:
- PLATFORM='docker-debian-stretch-php70' ANSIBLE_VERSION='ansible>=2.0,<2.1' - PLATFORM='docker-debian-stretch-php70' ANSIBLE_VERSION='ansible>=2.6,<2.7'
- PLATFORM='docker-debian-stretch-php71' ANSIBLE_VERSION='ansible>=2.0,<2.1' - PLATFORM='docker-debian-stretch-php71' ANSIBLE_VERSION='ansible>=2.6,<2.7'
- PLATFORM='docker-debian-stretch-php70' ANSIBLE_VERSION='ansible>=2.1,<2.2' - PLATFORM='docker-debian-stretch-php72' ANSIBLE_VERSION='ansible>=2.6,<2.7'
- PLATFORM='docker-debian-stretch-php71' ANSIBLE_VERSION='ansible>=2.1,<2.2' - PLATFORM='docker-debian-stretch-php73' ANSIBLE_VERSION='ansible>=2.6,<2.7'
- PLATFORM='docker-debian-stretch-php70' ANSIBLE_VERSION='ansible>=2.2,<2.3' - PLATFORM='docker-debian-buster-php73' ANSIBLE_VERSION='ansible>=2.6,<2.7'
- PLATFORM='docker-debian-stretch-php71' ANSIBLE_VERSION='ansible>=2.2,<2.3' - PLATFORM='docker-ubuntu-xenial-php70' ANSIBLE_VERSION='ansible>=2.6,<2.7'
- PLATFORM='docker-debian-stretch-php70' ANSIBLE_VERSION='ansible>=2.3,<2.4' - PLATFORM='docker-ubuntu-bionic-php72' ANSIBLE_VERSION='ansible>=2.6,<2.7'
- PLATFORM='docker-debian-stretch-php71' ANSIBLE_VERSION='ansible>=2.3,<2.4' - PLATFORM='docker-ubuntu-bionic-php72' ANSIBLE_VERSION='ansible>=2.6,<2.7'
- PLATFORM='docker-ubuntu-xenial-php70' ANSIBLE_VERSION='ansible>=2.0,<2.1' - PLATFORM='docker-debian-stretch-php70' ANSIBLE_VERSION='ansible>=2.7,<2.8'
- PLATFORM='docker-ubuntu-xenial-php70' ANSIBLE_VERSION='ansible>=2.1,<2.2' - PLATFORM='docker-debian-stretch-php71' ANSIBLE_VERSION='ansible>=2.7,<2.8'
- PLATFORM='docker-ubuntu-xenial-php70' ANSIBLE_VERSION='ansible>=2.2,<2.3' - PLATFORM='docker-debian-stretch-php72' ANSIBLE_VERSION='ansible>=2.7,<2.8'
- PLATFORM='docker-ubuntu-xenial-php70' ANSIBLE_VERSION='ansible>=2.3,<2.4' - PLATFORM='docker-debian-stretch-php73' ANSIBLE_VERSION='ansible>=2.7,<2.8'
- PLATFORM='docker-ubuntu-bionic-php72' ANSIBLE_VERSION='ansible>=2.0,<2.1' - PLATFORM='docker-debian-buster-php73' ANSIBLE_VERSION='ansible>=2.7,<2.8'
- PLATFORM='docker-ubuntu-bionic-php72' ANSIBLE_VERSION='ansible>=2.1,<2.2' - PLATFORM='docker-ubuntu-xenial-php70' ANSIBLE_VERSION='ansible>=2.7,<2.8'
- PLATFORM='docker-ubuntu-bionic-php72' ANSIBLE_VERSION='ansible>=2.2,<2.3' - PLATFORM='docker-ubuntu-bionic-php72' ANSIBLE_VERSION='ansible>=2.7,<2.8'
- PLATFORM='docker-ubuntu-bionic-php72' ANSIBLE_VERSION='ansible>=2.3,<2.4' - PLATFORM='docker-ubuntu-bionic-php72' ANSIBLE_VERSION='ansible>=2.7,<2.8'
sudo: required sudo: required
dist: trusty dist: trusty
language: python language: python
python: 2.7
services: services:
- docker - docker

View File

@@ -3,21 +3,21 @@ Ansible PHP (+FPM) role for Debian / Ubuntu / FreeBSD
[![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) [![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 / Ubuntu. Manage APCu, Opcache, Xdebug. Install PHP on Debian / Ubuntu / FreeBSD. Manage PHP-FPM, APCu, Opcache and Xdebug.
Managed OS / Versions Managed OS / Versions
--------------------- ---------------------
| OS | PHP 7.0 | PHP 7.1 | PHP 7.2 | | OS | PHP 7.0 | PHP 7.1 | PHP 7.2 | PHP 7.3 |
|:---------------------:|:------------:|:-------------:|:------------:| |:---------------------:|:-------------------:|:--------------------------:|:--------------------------:|:-------------------------:|
| Debian Strech (9) | Yes | Yes (Sury) | Yes (Sury) | | Debian Stretch (9) | :heavy_check_mark: | :heavy_check_mark: (Sury) | :heavy_check_mark: (Sury) | :heavy_check_mark: (Sury) |
| Ubuntu Xenial (16.04) | Yes | No | No | | Debian Buster (10) | :x: | :x: | :x: | :heavy_check_mark: |
| Ubuntu Bionic (18.04) | No | No | Yes | | Ubuntu Xenial (16.04) | :heavy_check_mark: | :x: | :x: | :x: |
| FreeBSD 11 | Yes | Yes | Yes | | Ubuntu Bionic (18.04) | :x: | :x: | :heavy_check_mark: | :x: |
| FreeBSD 12 | Yes | Yes | Yes | | FreeBSD 11 | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
| FreeBSD 12 | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
Links: Links:
- [Dotdeb](https://www.dotdeb.org)
- [Sury](https://deb.sury.org/) - [Sury](https://deb.sury.org/)
Requirements Requirements
@@ -25,7 +25,6 @@ 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). 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).
FreeBSD limitations FreeBSD limitations
------------------- -------------------
@@ -40,7 +39,7 @@ You should look at [default vars](defaults/main.yml).
### Writable vars ### Writable vars
- `php_version`: 7.0, 7.1, 7.2 - `php_version`: 7.0, 7.1, 7.2, 7.3
- `php_install_fpm`: boolean, install and manage php-fpm (default is true) - `php_install_fpm`: boolean, install and manage php-fpm (default is true)
- `php_install_xdebug`: boolean, install [Xdebug](http://xdebug.org) - `php_install_xdebug`: boolean, install [Xdebug](http://xdebug.org)
- `php_extra_packages`: additional php packages to install (default is an empty list). - `php_extra_packages`: additional php packages to install (default is an empty list).

6
Vagrantfile vendored
View File

@@ -9,6 +9,8 @@ Vagrant.configure("2") do |config|
{ :name => "debian-stretch-php70", :box => "debian/stretch64", :vars => { }}, { :name => "debian-stretch-php70", :box => "debian/stretch64", :vars => { }},
{ :name => "debian-stretch-php71", :box => "debian/stretch64", :vars => { "php_version": '7.1' }}, { :name => "debian-stretch-php71", :box => "debian/stretch64", :vars => { "php_version": '7.1' }},
{ :name => "debian-stretch-php72", :box => "debian/stretch64", :vars => { "php_version": '7.2' }}, { :name => "debian-stretch-php72", :box => "debian/stretch64", :vars => { "php_version": '7.2' }},
{ :name => "debian-stretch-php73", :box => "debian/stretch64", :vars => { "php_version": '7.3' }},
{ :name => "debian-buster-php73", :box => "debian/buster64", :vars => { }},
{ :name => "ubuntu-xenial-php70", :box => "ubuntu/xenial64", :vars => { }}, { :name => "ubuntu-xenial-php70", :box => "ubuntu/xenial64", :vars => { }},
{ :name => "ubuntu-bionic-php72", :box => "ubuntu/bionic64", :vars => { }}, { :name => "ubuntu-bionic-php72", :box => "ubuntu/bionic64", :vars => { }},
] ]
@@ -22,6 +24,8 @@ Vagrant.configure("2") do |config|
{ :name => "docker-debian-stretch-php70", :docker => "hanxhx/vagrant-ansible:debian9", :vars => { }}, { :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' }}, { :name => "docker-debian-stretch-php71", :docker => "hanxhx/vagrant-ansible:debian9", :vars => { "php_version": '7.1' }},
{ :name => "docker-debian-stretch-php72", :docker => "hanxhx/vagrant-ansible:debian9", :vars => { "php_version": '7.2' }}, { :name => "docker-debian-stretch-php72", :docker => "hanxhx/vagrant-ansible:debian9", :vars => { "php_version": '7.2' }},
{ :name => "docker-debian-stretch-php73", :docker => "hanxhx/vagrant-ansible:debian9", :vars => { "php_version": '7.3' }},
{ :name => "docker-debian-buster-php73", :docker => "hanxhx/vagrant-ansible:debian10", :vars => { }},
{ :name => "docker-ubuntu-xenial-php70", :docker => "hanxhx/vagrant-ansible:ubuntu16.04", :vars => { }}, { :name => "docker-ubuntu-xenial-php70", :docker => "hanxhx/vagrant-ansible:ubuntu16.04", :vars => { }},
{ :name => "docker-ubuntu-bionic-php72", :docker => "hanxhx/vagrant-ansible:ubuntu18.04", :vars => { }}, { :name => "docker-ubuntu-bionic-php72", :docker => "hanxhx/vagrant-ansible:ubuntu18.04", :vars => { }},
] ]
@@ -35,6 +39,7 @@ Vagrant.configure("2") do |config|
d.remains_running = true d.remains_running = true
d.has_ssh = true d.has_ssh = true
end end
m.vm.provision "shell", inline: "apt-get update && apt-get install -y python python-apt"
m.vm.provision "ansible" do |ansible| m.vm.provision "ansible" do |ansible|
ansible.playbook = "tests/test.yml" ansible.playbook = "tests/test.yml"
ansible.verbose = 'vv' ansible.verbose = 'vv'
@@ -62,6 +67,7 @@ Vagrant.configure("2") do |config|
end end
vms_freebsd.each do |opts| vms_freebsd.each do |opts|
config.vm.synced_folder ".", "/vagrant", disabled: true
config.vm.base_mac = "080027D14C66" config.vm.base_mac = "080027D14C66"
config.vm.define opts[:name] do |m| config.vm.define opts[:name] do |m|
m.vm.box = opts[:box] m.vm.box = opts[:box]

View File

@@ -5,3 +5,10 @@
name: '{{ php_fpm_service }}' name: '{{ php_fpm_service }}'
state: restarted state: restarted
when: php_install_fpm when: php_install_fpm
notify: docker restart php-fpm
- name: docker restart php-fpm
command: 'service {{ php_fpm_service }} restart'
args:
warn: false
when: ansible_virtualization_type == 'docker'

View File

@@ -1,14 +1,15 @@
--- ---
galaxy_info: galaxy_info:
author: Emilien Mantel author: Emilien Mantel
description: Install and configure PHP 7.0/7.1/7.2 (+ FPM is wanted) description: Install and configure PHP 7.0/7.1/7.2/7.3
company: company:
license: GPLv2 license: GPLv2
min_ansible_version: 2.0 min_ansible_version: 2.6
platforms: platforms:
- name: Debian - name: Debian
versions: versions:
- stretch - stretch
- buster
- name: Ubuntu - name: Ubuntu
versions: versions:
- xenial - xenial

View File

@@ -18,12 +18,19 @@
regexp: '^;?{{ item.key }}' regexp: '^;?{{ item.key }}'
line: '{{ item.key }} = {{ item.value }}' line: '{{ item.key }} = {{ item.value }}'
create: yes create: yes
with_dict: "{{ php_ini | combine(php_ini_fpm) }}" loop: "{{ php_ini | combine(php_ini_fpm) | dict2items }}"
notify: restart php-fpm notify: restart php-fpm
- name: TEMPLATE | Deploy pool configuration - name: TEMPLATE | Deploy pool configuration
template: template:
src: etc/__php__/fpm/pool.d/pool.conf.j2 src: etc/__php__/fpm/pool.d/pool.conf.j2
dest: '{{ php_fpm_pool_dir }}/{{ item.pool_name }}.conf' dest: '{{ php_fpm_pool_dir }}/{{ item.pool_name }}.conf'
with_items: "{{ php_fpm_poold }}" loop: "{{ php_fpm_poold }}"
notify: restart php-fpm
- name: FILE | Delete default pool if necessary
file:
path: "{{ php_fpm_pool_dir }}/www.conf"
state: absent
when: '"www" not in (php_fpm_poold | map(attribute="pool_name") | list)'
notify: restart php-fpm notify: restart php-fpm

View File

@@ -1,10 +1,19 @@
--- ---
- name: SET_FACT | Bypass https://github.com/ansible/ansible/issues/19874
set_fact:
ansible_distribution_release: 'buster'
when: ansible_facts.distribution_major_version == "buster/sid"
- name: INCLUDE_VARS | Related to OS family - name: INCLUDE_VARS | Related to OS family
include_vars: "OS_Family_{{ ansible_os_family }}.yml" include_vars: "OS_Family_{{ ansible_os_family }}.yml"
- name: INCLUDE_VARS | Related to OS version - name: INCLUDE_VARS | Related to OS version
include_vars: "{{ ansible_distribution }}-{{ ansible_distribution_release }}.yml" include_vars: "{{ item }}"
with_first_found:
- "{{ ansible_distribution }}-{{ ansible_distribution_release }}.yml"
- "{{ ansible_distribution }}-{{ ansible_distribution_version }}.yml"
- "{{ ansible_distribution }}-{{ ansible_distribution_major_version }}.yml"
- name: APT | Install PHP packages - name: APT | Install PHP packages
apt: apt:
@@ -12,33 +21,53 @@
state: present state: present
update_cache: yes update_cache: yes
cache_valid_time: 3600 cache_valid_time: 3600
with_flattened: loop: "{{ php_packages + php_extra_packages | flatten }}"
- "{{ php_packages }}"
- "{{ php_extra_packages }}"
notify: restart php-fpm notify: restart php-fpm
when: ansible_os_family == 'Debian' when: ansible_os_family == 'Debian'
- name: PKGNG | Install PHP packages - name: PKGNG | Install PHP packages
pkgng: pkgng:
name: "{{ item }}" name: "{{ item }}"
with_flattened: loop: "{{ php_packages + php_extra_packages | flatten }}"
- "{{ php_packages }}"
- "{{ php_extra_packages }}"
notify: restart php-fpm notify: restart php-fpm
when: ansible_os_family == 'FreeBSD' when: ansible_os_family == 'FreeBSD'
- name: INCLUDE | PHP-FPM - name: IMPORT_TASKS | PHP-FPM
include: fpm.yml import_tasks: fpm.yml
- name: LINEINFILE | PHP CLI configuration - name: LINEINFILE | PHP CLI configuration
lineinfile: lineinfile:
dest: '{{ php_cli_ini }}' dest: '{{ php_cli_ini }}'
regexp: '^;?{{ item.key }}' regexp: '^;?{{ item.key }}'
line: '{{ item.key }} = {{ item.value }}' line: '{{ item.key }} = {{ item.value }}'
with_dict: "{{ php_ini | combine(php_ini_cli) }}" loop: "{{ php_ini | combine(php_ini_cli) | dict2items }}"
- name: INCLUDE | Xdebug - name: IMPORT_TASKS | Xdebug
include: xdebug.yml import_tasks: xdebug.yml
- name: APT | Install and configure opcache - name: APT | Install and configure opcache
include: opcache.yml import_tasks: opcache.yml
- name: SERVICE | Ensure PHP-FPM is started
service:
name: '{{ php_fpm_service }}'
state: started
when: php_install_fpm and ansible_virtualization_type != 'docker'
- block:
- name: COMMAND | Check if PHP-FPM is started (Docker)
command: 'service {{ php_fpm_service }} status'
args:
warn: false
register: dps
changed_when: false
failed_when: false
- name: COMMAND | Ensure PHP-FPM is started (Docker)
command: 'service {{ php_fpm_service }} start'
args:
warn: false
when: dps.stdout.find('is not running') != -1
when: php_install_fpm and ansible_virtualization_type == 'docker'

View File

@@ -4,7 +4,7 @@
- name: APT | Install APCu - name: APT | Install APCu
apt: apt:
pkg: "{{ php_package_prefix }}apcu" pkg: "php-apcu"
- name: APT | Install Opcache - name: APT | Install Opcache
apt: apt:

View File

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

View File

@@ -4,6 +4,6 @@
apt_key: apt_key:
url: 'https://packages.sury.org/php/apt.gpg' url: 'https://packages.sury.org/php/apt.gpg'
- name: APT | Add Sury repository - name: APT_REPOSITORY | Add Sury repository
apt_repository: apt_repository:
repo: 'deb https://packages.sury.org/php/ {{ ansible_distribution_release }} main' repo: 'deb https://packages.sury.org/php/ {{ ansible_distribution_release }} main'

View File

@@ -6,18 +6,19 @@
- name: APT | Install packages - name: APT | Install packages
apt: apt:
pkg: "{{ item }}" pkg: "{{ p }}"
update_cache: yes update_cache: yes
cache_valid_time: 3600 cache_valid_time: 3600
with_items: vars:
p:
- apt-transport-https - apt-transport-https
- ca-certificates - ca-certificates
- curl - curl
- lsb-release - lsb-release
- nginx - nginx
- name: INCLUDE | Sury - name: INCLUDE_TASKS | Sury
include: Debian/sury.yml include_tasks: Debian/sury.yml
when: > when:
ansible_distribution_major_version | version_compare(9, 'eq') and (ansible_distribution_major_version is version('9', 'eq')) and
php_version | version_compare('7.1', 'ge') (php_version is version('7.1', 'ge'))

View File

@@ -3,11 +3,8 @@
- name: SET_FACT | Prepare test vars - name: SET_FACT | Prepare test vars
set_fact: set_fact:
__nginx_conf: /usr/local/etc/nginx/nginx.conf __nginx_conf: /usr/local/etc/nginx/nginx.conf
php_xdebug_package: 'php72-pecl-xdebug26' php_xdebug_package: 'php72-pecl-xdebug-2.6.1'
- name: PKGNG | Install packages - name: PKGNG | Install packages
pkgng: pkgng:
name: "{{ item }}" name: ['curl', 'nginx']
with_items:
- curl
- nginx

View File

@@ -11,7 +11,7 @@
php_ini_cli: php_ini_cli:
error_reporting: 'E_ALL' error_reporting: 'E_ALL'
php_fpm_poold: php_fpm_poold:
- pool_name: 'www' - pool_name: 'test_ansible'
listen: '{{ php_default_fpm_sock }}' listen: '{{ php_default_fpm_sock }}'
pm: 'dynamic' pm: 'dynamic'
pm_max_children: 250 pm_max_children: 250
@@ -24,8 +24,8 @@
pre_tasks: pre_tasks:
- name: INCLUDE | Pre tasks related to OS - name: INCLUDE_TASKS | Pre tasks related to OS
include: "includes/pre_{{ ansible_os_family }}.yml" include_tasks: "includes/pre_{{ ansible_os_family }}.yml"
tasks: tasks:
@@ -48,12 +48,44 @@
dest: "{{ __nginx_conf | dirname }}/fastcgi.conf" dest: "{{ __nginx_conf | dirname }}/fastcgi.conf"
notify: reload nginx notify: reload nginx
- name: SERVICE | Ensure nginx is started
service:
name: nginx
state: started
when: ansible_virtualization_type != 'docker'
- block:
- name: COMMAND | Docker nginx status
command: service nginx status
args:
warn: false
changed_when: false
failed_when: false
register: ngs
- name: COMMAND | Docker start nginx
command: service nginx start
args:
warn: false
when: ngs.stdout.find('nginx is not running') != -1
when: ansible_virtualization_type == 'docker'
handlers: handlers:
- name: reload nginx - name: reload nginx
service: service:
name: nginx name: nginx
state: reloaded state: reloaded
notify: docker reload nginx
- name: docker reload nginx
command: service nginx reload
args:
warn: false
notify: docker reload nginx
when: ansible_virtualization_type == 'docker'
roles: roles:
- ../../ - ../../

1
vars/Debian-buster.yml Normal file
View File

@@ -0,0 +1 @@
php_default_version: '7.3'

1
vars/FreeBSD-12.yml Normal file
View File

@@ -0,0 +1 @@
php_default_version: '7.2'