From e9e74e2db69a9389d9b39429539c8c4edd10a5c9 Mon Sep 17 00:00:00 2001 From: Emilien M Date: Thu, 6 Oct 2022 14:47:06 +0200 Subject: [PATCH] Modernize * Fix lint errors due to ansible-lint latest version * Drop debian stretch support --- .travis.yml | 2 -- README.md | 8 ++++---- Vagrantfile | 4 ---- handlers/main.yml | 6 +++--- meta/argument_specs.yml | 6 ++++++ meta/main.yml | 16 +++++++++------- tasks/fpm.yml | 6 +++--- tasks/main.yml | 12 +++++++----- tasks/opcache.yml | 15 ++++++++------- tasks/xdebug.yml | 13 +++++++------ tests/test.yml | 29 +++++++++++++++-------------- vars/Debian-stretch.yml | 3 --- 12 files changed, 62 insertions(+), 58 deletions(-) create mode 100644 meta/argument_specs.yml delete mode 100644 vars/Debian-stretch.yml diff --git a/.travis.yml b/.travis.yml index 1fa6342..ee837f0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,8 +4,6 @@ env: global: - VAGRANT_VERSION='2.2.18' jobs: - - PLATFORM='docker-debian-stretch-php70' ANSIBLE_VERSION='>=2.11,<2.12' - - PLATFORM='docker-debian-stretch-php74' ANSIBLE_VERSION='>=2.11,<2.12' - PLATFORM='docker-debian-buster-php73' ANSIBLE_VERSION='>=2.11,<2.12' - PLATFORM='docker-debian-bullseye-php74' ANSIBLE_VERSION='>=2.11,<2.12' - PLATFORM='docker-debian-bullseye-php80' ANSIBLE_VERSION='>=2.11,<2.12' diff --git a/README.md b/README.md index 78ab819..f0c4342 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,14 @@ 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://app.travis-ci.com/HanXHX/ansible-php.svg?branch=master)](https://app.travis-ci.com/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://app.travis-ci.com/HanXHX/ansible-php.svg?branch=master)](https://app.travis-ci.com/HanXHX/ansible-php) Install PHP on Debian / Ubuntu / FreeBSD. Manage PHP-FPM, APCu, Opcache and Xdebug. Managed OS / Versions --------------------- -On all Debian versions, you can install all PHP versions (from PHP 5.6 to 8.1 beta) by using [Sury's APT repository](https://deb.sury.org/). +On all Debian versions, you can install all PHP versions by using [Sury's APT repository](https://deb.sury.org/). Other cases: @@ -161,14 +161,14 @@ Example Playbook - hosts: servers roles: - - { role: HanXHX.php } + - { role: hanxhx.php } ### Debian Bullseye with PHP 8.0 CLI (no FPM) - hosts: servers roles: - { role: HanXHX.sury } - - { role: HanXHX.php, php_version: '8.0', php_install_fpm: false } + - { role: hanxhx.php, php_version: '8.0', php_install_fpm: false } License ------- diff --git a/Vagrantfile b/Vagrantfile index 9a75806..547c338 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -6,8 +6,6 @@ Vagrant.configure("2") do |config| vms_debian = [ - { :name => "debian-stretch-php70", :box => "debian/stretch64", :vars => { }}, - { :name => "debian-stretch-php74", :box => "debian/stretch64", :vars => { "php_version": '7.4' }}, { :name => "debian-buster-php73", :box => "debian/buster64", :vars => { }}, { :name => "debian-buster-php74", :box => "debian/buster64", :vars => { "php_version": '7.4' }}, { :name => "debian-bullseye-php74", :box => "debian/bullseye64", :vars => { }}, @@ -21,8 +19,6 @@ Vagrant.configure("2") do |config| ] conts = [ - { :name => "docker-debian-stretch-php70", :docker => "hanxhx/vagrant-ansible:debian9", :vars => { }}, - { :name => "docker-debian-stretch-php74", :docker => "hanxhx/vagrant-ansible:debian9", :vars => { "php_version": '7.4' }}, { :name => "docker-debian-buster-php73", :docker => "hanxhx/vagrant-ansible:debian10", :vars => { }}, { :name => "docker-debian-buster-php74", :docker => "hanxhx/vagrant-ansible:debian10", :vars => { "php_version": '7.4' }}, { :name => "docker-debian-bullseye-php74", :docker => "hanxhx/vagrant-ansible:debian11", :vars => { }}, diff --git a/handlers/main.yml b/handlers/main.yml index f15ce53..87cb18f 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -1,13 +1,13 @@ --- -- name: restart php-fpm +- name: Restart php-fpm ansible.builtin.service: name: '{{ php_fpm_service }}' state: restarted when: php_install_fpm - notify: docker restart php-fpm + notify: Docker restart php-fpm -- name: docker restart php-fpm +- name: Docker restart php-fpm ansible.builtin.command: 'service {{ php_fpm_service }} restart' args: warn: false diff --git a/meta/argument_specs.yml b/meta/argument_specs.yml new file mode 100644 index 0000000..2687667 --- /dev/null +++ b/meta/argument_specs.yml @@ -0,0 +1,6 @@ +--- + +argument_specs: + main: + short_description: Main entry point + options: {} diff --git a/meta/main.yml b/meta/main.yml index 3fde8d4..5323dda 100644 --- a/meta/main.yml +++ b/meta/main.yml @@ -1,14 +1,15 @@ --- galaxy_info: author: Emilien Mantel - description: Install and configure PHP 7.0/7.1/7.2/7.3/7.4/8.0 - company: + role_name: php + namespace: hanxhx + description: Install and configure PHP 7.x/8.x + company: TripleStack license: GPLv2 - min_ansible_version: 2.11 + min_ansible_version: '2.11' platforms: - name: Debian versions: - - stretch - buster - bullseye - name: Ubuntu @@ -16,9 +17,9 @@ galaxy_info: - bionic - name: FreeBSD versions: - - 11.0 - - 11.1 - - 12.0 + - '11.0' + - '11.1' + - '12.0' galaxy_tags: - development - web @@ -29,4 +30,5 @@ galaxy_info: - debian - ubuntu - freebsd + dependencies: [] diff --git a/tasks/fpm.yml b/tasks/fpm.yml index c66a9a4..6d4af4b 100644 --- a/tasks/fpm.yml +++ b/tasks/fpm.yml @@ -22,7 +22,7 @@ group: root mode: 0644 loop: "{{ php_ini | combine(php_ini_fpm) | dict2items }}" - notify: restart php-fpm + notify: Restart php-fpm - name: TEMPLATE | Deploy pool configuration ansible.builtin.template: @@ -32,11 +32,11 @@ group: root mode: 0644 loop: "{{ ansible_local.hanxhx_php.fpm_pool }}" - notify: restart php-fpm + notify: Restart php-fpm - name: FILE | Delete default pool if necessary ansible.builtin.file: path: "{{ php_fpm_pool_dir }}/www.conf" state: absent when: '"www" not in (ansible_local.hanxhx_php.fpm_pool | map(attribute="name") | list) and php_autoremove_default_pool' - notify: restart php-fpm + notify: Restart php-fpm diff --git a/tasks/main.yml b/tasks/main.yml index 52444ed..0a3a71d 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -60,6 +60,8 @@ group: root mode: 0644 register: f + tags: + - skip_ansible_lint - name: SETUP | Gathers new facts ansible.builtin.setup: @@ -76,13 +78,13 @@ install_recommends: false vars: pkgs: "{{ php_packages + php_extra_packages | flatten }}" - notify: restart php-fpm + notify: Restart php-fpm when: ansible_os_family == 'Debian' - name: PKGNG | Install PHP packages community.general.pkgng: name: "{{ php_packages + php_extra_packages | flatten | join(',') }}" - notify: restart php-fpm + notify: Restart php-fpm when: ansible_os_family == 'FreeBSD' - name: IMPORT_TASKS | PHP-FPM @@ -107,7 +109,9 @@ state: started when: php_install_fpm and ansible_virtualization_type != 'docker' -- block: +- name: BLOCK | Ensure PHP-FPM is started if running on Docker + when: php_install_fpm and ansible_virtualization_type == 'docker' + block: - name: COMMAND | Check if PHP-FPM is started (Docker) ansible.builtin.command: 'service {{ php_fpm_service }} status' @@ -122,5 +126,3 @@ args: warn: false when: dps.stdout.find('is not running') != -1 - - when: php_install_fpm and ansible_virtualization_type == 'docker' diff --git a/tasks/opcache.yml b/tasks/opcache.yml index ce3dac9..26ccf51 100644 --- a/tasks/opcache.yml +++ b/tasks/opcache.yml @@ -1,6 +1,8 @@ --- -- block: +- name: Install opcache/apcu on Debian + when: ansible_os_family == 'Debian' + block: - name: APT | Install APCu ansible.builtin.apt: @@ -12,9 +14,10 @@ pkg: "{{ php_package_prefix }}opcache" install_recommends: false - when: ansible_os_family == 'Debian' -- block: +- name: Install opcache/apcu on FreeBSD + when: ansible_os_family == 'FreeBSD' + block: - name: PKGNG | Install APCu community.general.pkgng: @@ -24,8 +27,6 @@ community.general.pkgng: name: "{{ php_package_prefix }}opcache" - when: ansible_os_family == 'FreeBSD' - - name: TEMPLATE | Configure Opcache ansible.builtin.template: src: "etc/__php__/mods-available/opcache.ini.j2" @@ -33,7 +34,7 @@ owner: root group: root mode: 0644 - notify: restart php-fpm + notify: Restart php-fpm - name: TEMPLATE | Configure APCu ansible.builtin.template: @@ -42,4 +43,4 @@ owner: root group: root mode: 0644 - notify: restart php-fpm + notify: Restart php-fpm diff --git a/tasks/xdebug.yml b/tasks/xdebug.yml index 11ef482..b7dd363 100644 --- a/tasks/xdebug.yml +++ b/tasks/xdebug.yml @@ -1,6 +1,8 @@ --- -- block: +- name: BLOCK | Uninstall xdebug + when: php_install_xdebug + block: - name: APT | Install xdebug ansible.builtin.apt: @@ -22,11 +24,12 @@ dest: "{{ php_mods_dir }}/xdebug.ini" owner: root mode: 0644 - notify: restart php-fpm + notify: Restart php-fpm - when: php_install_xdebug -- block: +- name: BLOCK | Uninstall xdebug + when: not php_install_xdebug + block: - name: APT | Uninstall xdebug ansible.builtin.apt: @@ -39,5 +42,3 @@ name: "{{ php_xdebug_package }}" state: absent when: ansible_os_family == 'FreeBSD' - - when: not php_install_xdebug diff --git a/tests/test.yml b/tests/test.yml index 5e722df..8918a1c 100644 --- a/tests/test.yml +++ b/tests/test.yml @@ -1,6 +1,7 @@ --- - hosts: all + name: Test all vars: vhost: 'test.local' php_extra_packages: @@ -46,24 +47,24 @@ - name: TEMPLATE | Nginx site config ansible.builtin.template: src: "templates/nginx.conf.j2" - dest: "{{ __nginx_conf }}" + dest: "{{ __nginx_conf }}" mode: 0644 owner: root group: root - notify: reload nginx + notify: Reload nginx - name: COMMAND | Fix nginx config ansible.builtin.command: "cp {{ __nginx_conf | dirname }}/fastcgi_params {{ __nginx_conf | dirname }}/fastcgi.conf" args: creates: "{{ __nginx_conf | dirname }}/fastcgi.conf" - notify: reload nginx + notify: Reload nginx - name: LINEINFILE | Fix nginx config (second step) ansible.builtin.lineinfile: regexp: '^fastcgi_param\s+SCRIPT_FILENAME' line: "fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;" dest: "{{ __nginx_conf | dirname }}/fastcgi.conf" - notify: reload nginx + notify: Reload nginx - name: SERVICE | Ensure nginx is started ansible.builtin.service: @@ -71,7 +72,9 @@ state: started when: ansible_virtualization_type != 'docker' - - block: + - name: Start nginx if testing with Docker + when: ansible_virtualization_type == 'docker' + block: - name: COMMAND | Docker nginx status ansible.builtin.command: service nginx status @@ -87,21 +90,19 @@ warn: false when: ngs.stdout.find('nginx is not running') != -1 - when: ansible_virtualization_type == 'docker' - handlers: - - name: reload nginx + - name: Reload nginx ansible.builtin.service: name: nginx state: reloaded - notify: docker reload nginx + notify: Docker reload nginx - - name: docker reload nginx + - name: Docker reload nginx ansible.builtin.command: service nginx reload args: warn: false - notify: docker reload nginx + notify: Docker reload nginx when: ansible_virtualization_type == 'docker' roles: @@ -168,7 +169,9 @@ url: "http://localhost{{ php_fpm_poold.0.status_path }}" when: php_fpm_poold.0.status_path is defined - - block: + - name: Debian extra checks + when: ansible_os_family == 'Debian' + block: - name: SHELL | Check if we installed multiple PHP versions ansible.builtin.shell: set -o pipefail && (dpkg -l | grep 'php[[:digit:]].*common' | wc -l) @@ -183,5 +186,3 @@ ansible.builtin.fail: msg: "Multiple PHP versions detected" when: check_multiple_php.stdout != '1' - - when: ansible_os_family == 'Debian' diff --git a/vars/Debian-stretch.yml b/vars/Debian-stretch.yml deleted file mode 100644 index 7712f6a..0000000 --- a/vars/Debian-stretch.yml +++ /dev/null @@ -1,3 +0,0 @@ ---- - -php_default_version: '7.0'