diff --git a/.travis.yml b/.travis.yml index 2de218f..7cbdecf 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,22 +1,10 @@ env: - - 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' diff --git a/README.md b/README.md index 593b2c1..03a2e77 100644 --- a/README.md +++ b/README.md @@ -8,10 +8,9 @@ Install PHP (php-fpm optional) on Debian. Manage APCu, Opcache, Xdebug. 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) | +| OS | PHP 7.0 | PHP 7.1 | PHP 7.2 | +|:-------------:|:------------:|:-------------:|:------------:| +| Debian Strech | Yes | Yes (Sury) | Yes (Sury) | Links: - [Dotdeb](https://www.dotdeb.org) @@ -29,7 +28,7 @@ You should look at [default vars](defaults/main.yml). ### Writable vars -- `php_version`: 5.6 (default), 7.0, 7.1 +- `php_version`: 7.0 (default on Stretch), 7.1, 7.2 - `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). @@ -151,12 +150,12 @@ Example Playbook roles: - { role: HanXHX.php } -### Debian Jessie with PHP 7.0 CLI (no FPM) +### Debian Jessie with PHP 7.2 CLI (no FPM) - - hosts: jessie-servers + - hosts: servers roles: - - { role: HanXHX.dotdeb } - - { role: HanXHX.php, php_version: '7.0', php_install_fpm: false } + - { role: HanXHX.sury } + - { role: HanXHX.php, php_version: '7.2', php_install_fpm: false } License ------- @@ -169,7 +168,7 @@ 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` +- Ethereum: `0x63abe6b2648fd892816d87a31e3d9d4365a737b5` - Litecoin: `LeNDw34zQLX84VvhCGADNvHMEgb5QyFXyD` - Monero: `45wbf7VdQAZS5EWUrPhen7Wo4hy7Pa7c7ZBdaWQSRowtd3CZ5vpVw5nTPphTuqVQrnYZC72FXDYyfP31uJmfSQ6qRXFy3bQ` @@ -179,4 +178,3 @@ Author Information ------------------ - Twitter: [@hanxhx_](https://twitter.com/hanxhx_) -- All issues, pull-requests are welcome :) diff --git a/Vagrantfile b/Vagrantfile index 2c9d3f4..0042d3d 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -6,19 +6,15 @@ Vagrant.configure("2") do |config| 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' }} + { :name => "debian-stretch-php71", :box => "debian/stretch64", :vars => { "php_version": '7.1' }}, + { :name => "debian-stretch-php72", :box => "debian/stretch64", :vars => { "php_version": '7.2' }} ] 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' }} + { :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' }} ] config.vm.network "private_network", type: "dhcp" diff --git a/handlers/main.yml b/handlers/main.yml index 2f8d6d2..4fed4a9 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -1,5 +1,7 @@ --- - name: restart php-fpm - service: name='{{ php_fpm_service }}' state=restarted + service: + name: '{{ php_fpm_service }}' + state: restarted when: php_install_fpm diff --git a/meta/main.yml b/meta/main.yml index 3d06ec3..24afd92 100644 --- a/meta/main.yml +++ b/meta/main.yml @@ -1,20 +1,19 @@ --- galaxy_info: author: Emilien Mantel - description: Install and configure PHP 5.6/7.0/7.1 (+ FPM is wanted) + description: Install and configure PHP 7.0/7.1/7.2 (+ FPM is wanted) company: license: GPLv2 min_ansible_version: 2.0 platforms: - name: Debian versions: - - jessie + - stretch galaxy_tags: - development - web - php - - php5.6 - - php5 + - php-fpm - php7 - debian dependencies: [] diff --git a/tasks/fpm.yml b/tasks/fpm.yml index 4d818b5..bd088e3 100644 --- a/tasks/fpm.yml +++ b/tasks/fpm.yml @@ -1,19 +1,20 @@ --- - name: APT | Install PHP-FPM - apt: pkg={{ php_fpm_service }} state=present + apt: + pkg: "{{ php_fpm_service }}" - name: LINEINFILE | PHP configuration lineinfile: - dest: '{{ php_etc_dir }}/fpm/php.ini' + dest: '{{ php_cli_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 - template: > - src=etc/__php__/fpm/pool.d/pool.conf.j2 - dest='{{ php_etc_dir }}/fpm/pool.d/{{ item.pool_name }}.conf' + template: + src: etc/__php__/fpm/pool.d/pool.conf.j2 + dest: '{{ php_fpm_pool_dir }}/{{ item.pool_name }}.conf' with_items: "{{ php_fpm_poold }}" notify: restart php-fpm diff --git a/tasks/main.yml b/tasks/main.yml index 1b9352c..576c195 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -1,21 +1,17 @@ --- -- name: INCLUDE_VARS | Related to OS +- name: INCLUDE_VARS | Related to OS family + include_vars: "OS_Family_{{ ansible_os_family }}.yml" + +- name: INCLUDE_VARS | Related to OS version include_vars: "{{ ansible_distribution }}-{{ ansible_distribution_major_version }}.yml" -- 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 - - name: APT | Install PHP packages - apt: pkg={{ item }} state=present + apt: + pkg: "{{ item }}" + state: present + update_cache: yes + cache_valid_time: 3600 with_flattened: - "{{ php_packages }}" - "{{ php_extra_packages }}" @@ -27,7 +23,7 @@ - name: LINEINFILE | PHP configuration lineinfile: - dest: '{{ php_etc_dir }}/cli/php.ini' + dest: '{{ php_cli_ini }}' regexp: '^;?{{ item.key }}' line: '{{ item.key }} = {{ item.value }}' with_dict: "{{ php_ini_cli }}" diff --git a/tasks/opcache.yml b/tasks/opcache.yml index ef5e657..bc8e6d1 100644 --- a/tasks/opcache.yml +++ b/tasks/opcache.yml @@ -1,20 +1,21 @@ --- - name: APT | Install APCu - apt: pkg="{{ php_apt_prefix }}apcu" state=present + apt: + pkg: "{{ php_package_prefix }}apcu" - name: APT | Install Opcache - apt: pkg="{{ php_apt_prefix }}opcache" state=present - when: php_version | version_compare('7.0', 'ge') + apt: + pkg: "{{ php_package_prefix }}opcache" -- name: TEMPLATE | Configure APCu - template: > - src=etc/__php__/mods-available/opcache.ini.j2 - dest="{{ php_mods_dir }}/opcache.ini" +- name: TEMPLATE | Configure Opcache + 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 + template: + src: "etc/__php__/mods-available/apcu.ini.j2" + dest: "{{ php_mods_dir }}/apcu.ini" notify: restart php-fpm diff --git a/tasks/xdebug.yml b/tasks/xdebug.yml index 1e7bcc2..cfc1fc2 100644 --- a/tasks/xdebug.yml +++ b/tasks/xdebug.yml @@ -4,16 +4,11 @@ - name: APT | Install php-xdebug apt: - pkg: "{{ php_apt_prefix }}xdebug" + pkg: "{{ php_package_prefix }}xdebug" state: present update_cache: yes cache_valid_time: 3600 - - 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" @@ -24,15 +19,8 @@ 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" - +- name: APT | Uninstall php-xdebug + apt: + pkg: "{{ php_package_prefix }}xdebug" + state: absent when: not php_install_xdebug diff --git a/templates/etc/__php__/mods-available/xdebug.ini.j2 b/templates/etc/__php__/mods-available/xdebug.ini.j2 index ef76561..145cc09 100644 --- a/templates/etc/__php__/mods-available/xdebug.ini.j2 +++ b/templates/etc/__php__/mods-available/xdebug.ini.j2 @@ -2,9 +2,6 @@ ; priority=20 zend_extension=xdebug.so -{% if xdebug_version.stdout|version_compare('2.3', 'gt') %} -{% endif %} - xdebug_auto_trace={{ php_xdebug_auto_trace }} xdebug_cli_color={{ php_xdebug_cli_color }} xdebug_collect_assignments={{ php_xdebug_collect_assignments }} @@ -29,9 +26,7 @@ xdebug_overload_var_dump={{ php_xdebug_overload_var_dump }} xdebug_profiler_append={{ php_xdebug_profiler_append }} xdebug_profiler_enable={{ php_xdebug_profiler_enable }} xdebug_profiler_enable_trigger={{ php_xdebug_profiler_enable_trigger }} -{% if xdebug_version.stdout|version_compare('2.3', 'gt') %} xdebug_profiler_enable_trigger_value={{ php_xdebug_profiler_enable_trigger_value }} -{% endif %} xdebug_profiler_output_dir={{ php_xdebug_profiler_output_dir }} xdebug_profiler_output_name={{ php_xdebug_profiler_output_name }} xdebug_remote_autostart={{ php_xdebug_remote_autostart }} @@ -48,9 +43,7 @@ xdebug_show_exception_trace={{ php_xdebug_show_exception_trace }} xdebug_show_local_vars={{ php_xdebug_show_local_vars }} xdebug_show_mem_delta={{ php_xdebug_show_mem_delta }} xdebug_trace_enable_trigger={{ php_xdebug_trace_enable_trigger }} -{% if xdebug_version.stdout|version_compare('2.3', 'gt') %} xdebug_trace_enable_trigger_value={{ php_xdebug_trace_enable_trigger_value }} -{% endif %} xdebug_trace_format={{ php_xdebug_trace_format }} xdebug_trace_options={{ php_xdebug_trace_options }} xdebug_trace_output_dir={{ php_xdebug_trace_output_dir }} diff --git a/tests/includes/Debian/dotdeb.yml b/tests/includes/Debian/dotdeb.yml new file mode 100644 index 0000000..0d222c2 --- /dev/null +++ b/tests/includes/Debian/dotdeb.yml @@ -0,0 +1,9 @@ +--- + +- 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' diff --git a/tests/includes/Debian/sury.yml b/tests/includes/Debian/sury.yml new file mode 100644 index 0000000..2fc2b60 --- /dev/null +++ b/tests/includes/Debian/sury.yml @@ -0,0 +1,9 @@ +--- + +- name: APT | Install Sury key + apt_key: + url: 'https://packages.sury.org/php/apt.gpg' + +- name: APT | Add Sury repository + apt_repository: + repo: 'deb https://packages.sury.org/php/ {{ ansible_distribution_release }} main' diff --git a/tests/includes/dotdeb.yml b/tests/includes/dotdeb.yml deleted file mode 100644 index 5179b08..0000000 --- a/tests/includes/dotdeb.yml +++ /dev/null @@ -1,7 +0,0 @@ ---- - -- 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 diff --git a/tests/includes/pre_Debian.yml b/tests/includes/pre_Debian.yml new file mode 100644 index 0000000..d8e32d4 --- /dev/null +++ b/tests/includes/pre_Debian.yml @@ -0,0 +1,23 @@ +--- + +- name: SET_FACT | Prepare test vars + set_fact: + __nginx_site_dir: /etc/nginx/sites-enabled + +- name: APT | Install packages + apt: + pkg: "{{ item }}" + update_cache: yes + cache_valid_time: 3600 + with_items: + - apt-transport-https + - ca-certificates + - curl + - lsb-release + - nginx + +- name: INCLUDE | Sury + include: Debian/sury.yml + when: > + ansible_distribution_major_version | version_compare(9, 'eq') and + php_version | version_compare('7.1', 'ge') diff --git a/tests/includes/sury.yml b/tests/includes/sury.yml deleted file mode 100644 index a298abc..0000000 --- a/tests/includes/sury.yml +++ /dev/null @@ -1,7 +0,0 @@ ---- - -- 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 diff --git a/tests/templates/site.j2 b/tests/templates/site.j2 index 84203c3..6ea739e 100644 --- a/tests/templates/site.j2 +++ b/tests/templates/site.j2 @@ -5,19 +5,19 @@ server { {% if php_fpm_poold.0.status_path is defined %} location = {{ php_fpm_poold.0.status_path }} { - include {{ nginx_include }}; + include fastcgi.conf; 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 }}; + include fastcgi.conf; fastcgi_pass unix:{{ php_default_fpm_sock }}; } {% endif %} location ~ \.php$ { - include {{ nginx_include }}; + include fastcgi.conf; fastcgi_pass unix:{{ php_default_fpm_sock }}; } } diff --git a/tests/test.yml b/tests/test.yml index 81a7034..2764439 100644 --- a/tests/test.yml +++ b/tests/test.yml @@ -4,7 +4,7 @@ vars: vhost: 'test.local' php_extra_packages: - - '{{ php_apt_prefix }}recode' + - '{{ php_package_prefix }}recode' php_install_xdebug: true php_ini_fpm: display_errors: 'Off' @@ -24,54 +24,29 @@ 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) + - name: INCLUDE | Pre tasks related to OS + include: "includes/pre_{{ ansible_os_family }}.yml" tasks: - name: TEMPLATE | Nginx site config template: - src: templates/site.j2 - dest: /etc/nginx/sites-enabled/{{ vhost }} + src: "templates/site.j2" + dest: "{{ __nginx_site_dir }}/{{ vhost }}" notify: reload nginx - name: FILE | Delete default site file: - path: /etc/nginx/sites-enabled/default + path: "{{ __nginx_site_dir }}/default" state: absent notify: reload nginx handlers: - name: reload nginx - service: name=nginx state=reloaded + service: + name: nginx + state: reloaded roles: - ../../ @@ -85,10 +60,14 @@ failed_when: p.stdout == '' - name: FILE | Create /var/www - file: dest=/var/www state=directory + file: + dest: /var/www + state: directory - name: COPY | Add phpinfo - copy: dest=/var/www/phpinfo.php content=' /dev/null | grep h1 | grep -o 'PHP Version {{ php_version }}' | sed -r 's/