diff --git a/docs/roles/cache_clear/cache_clear-opcache.md b/docs/roles/cache_clear/cache_clear-opcache.md index 267485f4..0dd8cfaf 100644 --- a/docs/roles/cache_clear/cache_clear-opcache.md +++ b/docs/roles/cache_clear/cache_clear-opcache.md @@ -1,6 +1,6 @@ # Opcache -Clear opcache. +Clear opcache. You must have run the `cli/cachetool` role to install `cachetool` first. @@ -10,16 +10,11 @@ Clear opcache. ```yaml --- cache_clear_opcache: - # Adapter string to use as argument. - # eg. - # --fcgi=127.0.0.1:9000 - # Leave blank to use /etc/cachetool.yml - # adapter: "--fcgi=127.0.0.1:9081" # Leave commented to automatically detect the adapter based on PHP version. # Bins to clear. clear_opcache: true clear_apcu: false clear_stat: true - # cachetool_bin: "/path/to/cachetool.phar" # see _init for paths if undefined + # cachetool_bin: "/path/to/cachetool.phar" # see _init for default paths if undefined ``` diff --git a/docs/roles/cli/cachetool.md b/docs/roles/cli/cachetool.md index 36d0a014..d3c5af0b 100644 --- a/docs/roles/cli/cachetool.md +++ b/docs/roles/cli/cachetool.md @@ -6,6 +6,13 @@ Installs the `drush` command-line tool for the deploy user. --- cachetool: version: "" # enter three-digit version number, e.g. "7.0.0", to install a specific version. If not specified, will be installed depending on the php version. + unix_socket: false # Set to true to use automatic detection of Unix socket as set by ce-provision + # Adapter string to use as argument. + # e.g. + # --fcgi=127.0.0.1:9000 + # --fcgi=/var/run/php-fpm.sock + # Provide an empty string to use /etc/cachetool.yml + # adapter: "--fcgi=127.0.0.1:9081" # Leave commented to automatically detect the adapter based on PHP version. ``` diff --git a/roles/cache_clear/cache_clear-opcache/README.md b/roles/cache_clear/cache_clear-opcache/README.md index 267485f4..0dd8cfaf 100644 --- a/roles/cache_clear/cache_clear-opcache/README.md +++ b/roles/cache_clear/cache_clear-opcache/README.md @@ -1,6 +1,6 @@ # Opcache -Clear opcache. +Clear opcache. You must have run the `cli/cachetool` role to install `cachetool` first. @@ -10,16 +10,11 @@ Clear opcache. ```yaml --- cache_clear_opcache: - # Adapter string to use as argument. - # eg. - # --fcgi=127.0.0.1:9000 - # Leave blank to use /etc/cachetool.yml - # adapter: "--fcgi=127.0.0.1:9081" # Leave commented to automatically detect the adapter based on PHP version. # Bins to clear. clear_opcache: true clear_apcu: false clear_stat: true - # cachetool_bin: "/path/to/cachetool.phar" # see _init for paths if undefined + # cachetool_bin: "/path/to/cachetool.phar" # see _init for default paths if undefined ``` diff --git a/roles/cache_clear/cache_clear-opcache/defaults/main.yml b/roles/cache_clear/cache_clear-opcache/defaults/main.yml index bf28c5b0..a9b9e92d 100644 --- a/roles/cache_clear/cache_clear-opcache/defaults/main.yml +++ b/roles/cache_clear/cache_clear-opcache/defaults/main.yml @@ -1,12 +1,5 @@ --- cache_clear_opcache: - # Adapter string to use as argument. - # e.g. - # --fcgi=127.0.0.1:9000 - # --fcgi=/var/run/php-fpm.sock - # Provide an empty string to use /etc/cachetool.yml - # adapter: "--fcgi=127.0.0.1:9081" # Leave commented to automatically detect the adapter based on PHP version. - unix_socket: false # Set to true to use automatic detection of Unix socket as set by ce-provision # Bins to clear. clear_opcache: true clear_apcu: false diff --git a/roles/cache_clear/cache_clear-opcache/tasks/main.yml b/roles/cache_clear/cache_clear-opcache/tasks/main.yml index 56507c4a..ddf9fd07 100644 --- a/roles/cache_clear/cache_clear-opcache/tasks/main.yml +++ b/roles/cache_clear/cache_clear-opcache/tasks/main.yml @@ -1,22 +1,4 @@ --- -- name: Get latest php installed - ansible.builtin.shell: - cmd: 'set -o pipefail && ls -1 /etc/php/ | while read ver; do if [ -d "/etc/php/$ver/fpm" ]; then echo "$ver"; fi; done | tail -1' - args: - executable: /bin/bash - register: _php_version - -- name: Set cachetool adapter specified or default to a TCP/IP port. - ansible.builtin.set_fact: - _cachetool_adapter: "{{ cache_clear_opcache.adapter | default('--fcgi=127.0.0.1:90' + _php_version.stdout | replace('.','')) }}" - -- name: Override cachetool adapter to be a Unix socket if requested. - ansible.builtin.set_fact: - _cachetool_adapter: "--fcgi=/var/run/php{{ _php_version.stdout | replace('.','') }}-fpm.sock" - when: - - cache_clear_opcache.unix_socket - - cache_clear_opcache.adapter is not defined - # cachetool_bin is set in the _init role. - name: Clear opcache. ansible.builtin.command: diff --git a/roles/cli/cachetool/README.md b/roles/cli/cachetool/README.md index 36d0a014..d3c5af0b 100644 --- a/roles/cli/cachetool/README.md +++ b/roles/cli/cachetool/README.md @@ -6,6 +6,13 @@ Installs the `drush` command-line tool for the deploy user. --- cachetool: version: "" # enter three-digit version number, e.g. "7.0.0", to install a specific version. If not specified, will be installed depending on the php version. + unix_socket: false # Set to true to use automatic detection of Unix socket as set by ce-provision + # Adapter string to use as argument. + # e.g. + # --fcgi=127.0.0.1:9000 + # --fcgi=/var/run/php-fpm.sock + # Provide an empty string to use /etc/cachetool.yml + # adapter: "--fcgi=127.0.0.1:9081" # Leave commented to automatically detect the adapter based on PHP version. ``` diff --git a/roles/cli/cachetool/defaults/main.yml b/roles/cli/cachetool/defaults/main.yml index 8b98934d..77c338ce 100644 --- a/roles/cli/cachetool/defaults/main.yml +++ b/roles/cli/cachetool/defaults/main.yml @@ -1,3 +1,10 @@ --- cachetool: version: "" # enter three-digit version number, e.g. "7.0.0", to install a specific version. If not specified, will be installed depending on the php version. + unix_socket: false # Set to true to use automatic detection of Unix socket as set by ce-provision + # Adapter string to use as argument. + # e.g. + # --fcgi=127.0.0.1:9000 + # --fcgi=/var/run/php-fpm.sock + # Provide an empty string to use /etc/cachetool.yml + # adapter: "--fcgi=127.0.0.1:9081" # Leave commented to automatically detect the adapter based on PHP version. diff --git a/roles/cli/cachetool/tasks/main.yml b/roles/cli/cachetool/tasks/main.yml index c9855743..e7035c7c 100644 --- a/roles/cli/cachetool/tasks/main.yml +++ b/roles/cli/cachetool/tasks/main.yml @@ -83,3 +83,27 @@ - deploy_operation == 'deploy' - cachetool.version is defined - cachetool.version | length > 0 + +# Set up cachetool adapter +- name: Get latest PHP version installed. + ansible.builtin.shell: + cmd: 'set -o pipefail && ls -1 /etc/php/ | while read ver; do if [ -d "/etc/php/$ver/fpm" ]; then echo "$ver"; fi; done | tail -1' + args: + executable: /bin/bash + register: _php_version + +- name: Set cachetool adapter specified or default to a TCP/IP port. + ansible.builtin.set_fact: + _cachetool_adapter: "{{ cachetool.adapter | default('--fcgi=127.0.0.1:90' + _php_version.stdout | replace('.','')) }}" + +- name: Override cachetool adapter to be a Unix socket if requested. + ansible.builtin.set_fact: + _cachetool_adapter: "--fcgi=/var/run/php{{ _php_version.stdout | replace('.','') }}-fpm.sock" + when: + - cachetool.unix_socket + - cachetool.adapter is not defined + +# We want to fail early if cachetool is broken. +- name: Ensure cachetool is working. + ansible.builtin.command: + cmd: "{{ cachetool_bin }} {{ _cachetool_adapter }} -n opcache:status"