diff --git a/tasks/configure-apcu.yml b/tasks/configure-apcu.yml new file mode 100644 index 0000000..5a3badb --- /dev/null +++ b/tasks/configure-apcu.yml @@ -0,0 +1,37 @@ +--- +- name: Check for existing APCu config files. + find: + paths: "{{ item }}" + contains: 'extension(\s+)?=(\s+)?apc[u]?\.so' + register: php_installed_apc_confs + with_items: "{{ php_extension_conf_paths }}" + +- name: Remove any non-role-supplied APCu config files. + file: + path: "{{ item.1.path }}" + state: absent + when: php_apc_conf_filename != (item.1.path.split('/') | last) + with_subelements: + - "{{ php_installed_apc_confs.results }}" + - files + notify: restart webserver + +- name: Ensure APCu config file is present. + template: + src: apc.ini.j2 + dest: "{{ item }}/{{ php_apc_conf_filename }}" + owner: root + group: root + force: yes + mode: 0644 + with_items: "{{ php_extension_conf_paths }}" + when: php_enable_apc + notify: restart webserver + +- name: Remove APCu config file if APC is disabled. + file: + path: "{{ item }}/{{ php_apc_conf_filename }}" + state: absent + with_items: "{{ php_extension_conf_paths }}" + when: not php_enable_apc + notify: restart webserver diff --git a/tasks/configure-opcache.yml b/tasks/configure-opcache.yml new file mode 100644 index 0000000..cd02e3f --- /dev/null +++ b/tasks/configure-opcache.yml @@ -0,0 +1,37 @@ +--- +- name: Check for existing OpCache config files. + find: + paths: "{{ item }}" + contains: 'zend_extension(\s+)?=(\s+)?opcache\.so' + register: php_installed_opcache_confs + with_items: "{{ php_extension_conf_paths }}" + +- name: Remove any non-role-supplied OpCache config files. + file: + path: "{{ item.1.path }}" + state: absent + when: php_opcache_conf_filename != (item.1.path.split('/') | last) + with_subelements: + - "{{ php_installed_opcache_confs.results }}" + - files + notify: restart webserver + +- name: Ensure OpCache config file is present. + template: + src: opcache.ini.j2 + dest: "{{ item }}/{{ php_opcache_conf_filename }}" + owner: root + group: root + force: yes + mode: 0644 + with_items: "{{ php_extension_conf_paths }}" + when: php_opcache_enable + notify: restart webserver + +- name: Remove OpCache config file if OpCache is disabled. + file: + path: "{{ item }}/{{ php_opcache_conf_filename }}" + state: absent + with_items: "{{ php_extension_conf_paths }}" + when: not php_opcache_enable + notify: restart webserver diff --git a/tasks/configure.yml b/tasks/configure.yml index 5a55702..f4fa94c 100644 --- a/tasks/configure.yml +++ b/tasks/configure.yml @@ -18,77 +18,3 @@ with_items: "{{ php_conf_paths }}" notify: restart webserver when: php_use_managed_ini - -- name: Check for PHP-installed APCu configuration file(s) - find: - paths: "{{ item }}" - contains: 'extension(\s+)?=(\s+)?apc[u]?\.so' - register: php_installed_apc_confs - with_items: "{{ php_extension_conf_paths }}" - -- name: Remove any PHP-installed APCu configuration files in favor of role configuration - file: - path: "{{ item.1.path }}" - state: absent - when: php_apc_conf_filename != (item.1.path.split('/') | last) - with_subelements: - - "{{ php_installed_apc_confs.results }}" - - files - notify: restart webserver - -- name: Place APCu configuration file in place. - template: - src: apc.ini.j2 - dest: "{{ item }}/{{ php_apc_conf_filename }}" - owner: root - group: root - force: yes - mode: 0644 - with_items: "{{ php_extension_conf_paths }}" - when: php_enable_apc - notify: restart webserver - -- name: Remove APCu configuration file if disabled - file: - path: "{{ item }}/{{ php_apc_conf_filename }}" - state: absent - with_items: "{{ php_extension_conf_paths }}" - when: not php_enable_apc - notify: restart webserver - -- name: Check for PHP-installed OpCache configuration file(s) - find: - paths: "{{ item }}" - contains: 'zend_extension(\s+)?=(\s+)?opcache\.so' - register: php_installed_opcache_confs - with_items: "{{ php_extension_conf_paths }}" - -- name: Remove any PHP-installed OpCache configuration files in favor of role configuration - file: - path: "{{ item.1.path }}" - state: absent - when: php_opcache_conf_filename != (item.1.path.split('/') | last) - with_subelements: - - "{{ php_installed_opcache_confs.results }}" - - files - notify: restart webserver - -- name: Place OpCache configuration file in place. - template: - src: opcache.ini.j2 - dest: "{{ item }}/{{ php_opcache_conf_filename }}" - owner: root - group: root - force: yes - mode: 0644 - with_items: "{{ php_extension_conf_paths }}" - when: php_opcache_enable - notify: restart webserver - -- name: Remove OpCache configuration file if disabled - file: - path: "{{ item }}/{{ php_opcache_conf_filename }}" - state: absent - with_items: "{{ php_extension_conf_paths }}" - when: not php_opcache_enable - notify: restart webserver diff --git a/tasks/main.yml b/tasks/main.yml index 1e736bf..1e82cee 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -56,6 +56,6 @@ # Configure PHP. - include: configure.yml - -# Configure PHP-FPM. +- include: configure-apcu.yml +- include: configure-opcache.yml - include: configure-fpm.yml