From 90de9d586161880b079445dc836d7b7f69811139 Mon Sep 17 00:00:00 2001 From: phil Date: Mon, 16 Oct 2023 12:50:11 +0200 Subject: [PATCH] Enable configuration via variables --- defaults/main.yml | 14 ++++++++++++++ tasks/php.yml | 42 +++++++++++----------------------------- templates/php-cli.ini.j2 | 7 +++++++ templates/php-fpm.ini | 20 ------------------- templates/php-fpm.ini.j2 | 7 +++++++ templates/php.ini | 20 ------------------- 6 files changed, 39 insertions(+), 71 deletions(-) create mode 100644 templates/php-cli.ini.j2 delete mode 100644 templates/php-fpm.ini create mode 100644 templates/php-fpm.ini.j2 delete mode 100644 templates/php.ini diff --git a/defaults/main.yml b/defaults/main.yml index 162f1d4..76700ac 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -8,3 +8,17 @@ php_fpm_memory_high: "25%" php_fpm_memory_max: "35%" apache_php_module_name: "libapache2-mod-php{{ php_version.stdout }}" + +php_fpm_config: + upload_max_filesize: 15M + post_max_size: "{{ upload_max_filesize }}" + memory_limit: 256M + max_execution_time: 300 + date.timezone: Europe/Berlin + default_charset: UTF-8 + apc.rfc1867: 1 + display_errors: "Off" + allow_url_fopen: "Off" + assert.active: "Off" + mail.add_x_header: "Off" + session.use_strict_mode: 1 diff --git a/tasks/php.yml b/tasks/php.yml index b5f0a71..5217f8b 100644 --- a/tasks/php.yml +++ b/tasks/php.yml @@ -1,29 +1,17 @@ --- -- name: "PHP | Copy custom PHP configuration" - ansible.builtin.template: - src: php.ini - dest: "/etc/php/{{ php_version.stdout }}/mods-available/{{ inventory_hostname }}.ini" - mode: "0644" - -- name: "PHP | Copy custom PHP-FPM configuration" - ansible.builtin.template: - src: php-fpm.ini - dest: "/etc/php/{{ php_version.stdout }}/mods-available/{{ inventory_hostname }}-fpm.ini" - mode: "0644" - -- name: "PHP | Enable PHP configuration for mod_php" - ansible.builtin.file: - src: "/etc/php/{{ php_version.stdout }}/mods-available/{{ inventory_hostname }}.ini" - dest: "/etc/php/{{ php_version.stdout }}/apache2/conf.d/30-{{ inventory_hostname }}.ini" - state: link - when: "'apache_php_module_name' in ansible_facts.packages" - notify: reload apache2 - - name: "PHP | Enable PHP cli configuration" - ansible.builtin.file: - src: "/etc/php/{{ php_version.stdout }}/mods-available/{{ inventory_hostname }}.ini" + ansible.builtin.template: + src: php-cli.ini.j2 dest: "/etc/php/{{ php_version.stdout }}/cli/conf.d/30-{{ inventory_hostname }}.ini" - state: link + mode: "0644" + +- name: "PHP | Enable PHP FPM configuration" + ansible.builtin.template: + src: php-fpm.ini.j2 + dest: "/etc/php/{{ php_version.stdout }}/fpm/conf.d/30-{{ inventory_hostname }}.ini" + mode: "0644" + when: "'php-fpm' in ansible_facts.packages" + notify: reload php-fpm - name: "PHP | Create log directory" ansible.builtin.file: @@ -31,14 +19,6 @@ state: directory mode: "0755" -- name: "PHP | Enable PHP FPM configuration" - ansible.builtin.file: - src: "/etc/php/{{ php_version.stdout }}/mods-available/{{ inventory_hostname }}-fpm.ini" - dest: "/etc/php/{{ php_version.stdout }}/fpm/conf.d/30-{{ inventory_hostname }}-fpm.ini" - state: link - when: "'php-fpm' in ansible_facts.packages" - notify: reload php-fpm - - name: "PHP | Copy template for PHP-FPM systemd service and socket" ansible.builtin.template: src: "systemd/{{ item }}" diff --git a/templates/php-cli.ini.j2 b/templates/php-cli.ini.j2 new file mode 100644 index 0000000..7204264 --- /dev/null +++ b/templates/php-cli.ini.j2 @@ -0,0 +1,7 @@ +; Ansible managed + +{% if php_cli_config is defined %} +{% for key, value in php_cli_config.items() %} +{{ key }} = {{ value }} +{% endfor %} +{% endif %} diff --git a/templates/php-fpm.ini b/templates/php-fpm.ini deleted file mode 100644 index ef5007d..0000000 --- a/templates/php-fpm.ini +++ /dev/null @@ -1,20 +0,0 @@ -; Ansible managed - -upload_max_filesize = {{ php.upload_max_filesize | default ('15M') }} -post_max_size = {{ php.post_max_size | default ('15M') }} -memory_limit = {{ php.memory_limit | default ('192M') }} -max_execution_time = {{ php.max_execution_time | default ('300') }} - -date.timezone = {{ php.date_timezone | default ('Europe/Berlin') }} -default_charset = "{{ php.default_charset | default ('UTF-8') }}" - -;Upload-Fortschritt -apc.rfc1867 = 1 - -display_errors = Off - -;Empfohlene Einstellungen (pcc) -allow_url_fopen = Off -assert.active = Off -mail.add_x_header = Off -session.use_strict_mode = 1 diff --git a/templates/php-fpm.ini.j2 b/templates/php-fpm.ini.j2 new file mode 100644 index 0000000..ef24452 --- /dev/null +++ b/templates/php-fpm.ini.j2 @@ -0,0 +1,7 @@ +; Ansible managed + +{% if php_fpm_config is defined %} +{% for key, value in php_fpm_config.items() %} +{{ key }} = {{ value }} +{% endfor %} +{% endif %} diff --git a/templates/php.ini b/templates/php.ini deleted file mode 100644 index ef5007d..0000000 --- a/templates/php.ini +++ /dev/null @@ -1,20 +0,0 @@ -; Ansible managed - -upload_max_filesize = {{ php.upload_max_filesize | default ('15M') }} -post_max_size = {{ php.post_max_size | default ('15M') }} -memory_limit = {{ php.memory_limit | default ('192M') }} -max_execution_time = {{ php.max_execution_time | default ('300') }} - -date.timezone = {{ php.date_timezone | default ('Europe/Berlin') }} -default_charset = "{{ php.default_charset | default ('UTF-8') }}" - -;Upload-Fortschritt -apc.rfc1867 = 1 - -display_errors = Off - -;Empfohlene Einstellungen (pcc) -allow_url_fopen = Off -assert.active = Off -mail.add_x_header = Off -session.use_strict_mode = 1