From 02a23062b2e600fe41cfa424be79ecfba11c271a Mon Sep 17 00:00:00 2001 From: Chris Croome <chris@webarchitects.co.uk> Date: Mon, 20 Feb 2023 10:52:23 +0000 Subject: [PATCH] PHP ini template fixed --- README.md | 9 +++++ defaults/main.yml | 74 ++++++++++++++++++++-------------------- tasks/file_templated.yml | 6 +++- tasks/pkg.yml | 7 ++-- templates/php.j2 | 6 ++-- 5 files changed, 58 insertions(+), 44 deletions(-) diff --git a/README.md b/README.md index 08fd3aa..1a740fa 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,15 @@ This role isn't setup to generate multiple `pool.d` config files, but the [users <!-- END_ANSIBLE_DOCS --> +## Help + +Reinstall a package and the configuration files when they have been deleted (see [serverfault comment](https://serverfault.com/a/670776)): + +```bash +UCF_FORCE_CONFFMISS=1 apt-get -o Dpkg::Options::="–force-confmiss" install "php8.1-fpm" +``` + + ## Repo History In June 2021 this role was renamed from `phpfpm` to `php` and the URL of the git repo and all the variable names and tags have been updated to match. diff --git a/defaults/main.yml b/defaults/main.yml index 5c8ad27..99f3001 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -13,12 +13,12 @@ php: true # cat /etc/php/8.1/fpm/php.ini | jc --ini -yp php_check_legacy_variables: true php_config: - - name: PHP 8.2 configuration - version: "8.2" - state: absent + # - name: PHP 8.2 configuration + # version: "8.2" + # state: absent - name: PHP 8.1 configuration version: "8.1" - state: absent + state: present files: - path: /etc/php/8.1/apache2/php.ini state: absent @@ -81,41 +81,41 @@ php_config: state: present php_sury: true php_versions: - - name: PHP 8.2 packages - version: "8.2" - state: absent - pkg_absent: - - libapache2-mod-php8.2 - - php8.2-phpdbg - pkg_present: - - php8.2-apcu - - php8.2-bcmath - - php8.2-bz2 - - php8.2-cli - - php8.2-common - - php8.2-curl - - php8.2-gd - - php8.2-gmp - - php8.2-fpm - - php8.2-imagick - - php8.2-imap - - php8.2-intl - - php8.2-ldap - - php8.2-mbstring - - php8.2-mysql - - php8.2-opcache - - php8.2-readline - - php8.2-sqlite3 - - php8.2-soap - - php8.2-uploadprogress - - php8.2-xml - - php8.2-xmlrpc - - php8.2-xsl - - php8.2-zip - - php-pear + # - name: PHP 8.2 packages + # version: "8.2" + # state: absent + # pkg_absent: + # - libapache2-mod-php8.2 + # - php8.2-phpdbg + # pkg_present: + # - php8.2-apcu + # - php8.2-bcmath + # - php8.2-bz2 + # - php8.2-cli + # - php8.2-common + # - php8.2-curl + # - php8.2-gd + # - php8.2-gmp + # - php8.2-fpm + # - php8.2-imagick + # - php8.2-imap + # - php8.2-intl + # - php8.2-ldap + # - php8.2-mbstring + # - php8.2-mysql + # - php8.2-opcache + # - php8.2-readline + # - php8.2-sqlite3 + # - php8.2-soap + # - php8.2-uploadprogress + # - php8.2-xml + # - php8.2-xmlrpc + # - php8.2-xsl + # - php8.2-zip + # - php-pear - name: PHP 8.1 packages version: "8.1" - state: absent + state: present pkg_absent: - libapache2-mod-php8.1 - php8.1-phpdbg diff --git a/tasks/file_templated.yml b/tasks/file_templated.yml index 651a56b..f9c4d47 100644 --- a/tasks/file_templated.yml +++ b/tasks/file_templated.yml @@ -113,7 +113,9 @@ state: reloaded when: + - php_conf_file_version is defined - php_conf_file_version in php_ver_installed + - php_conf_file_templated.changed is defined - php_conf_file_templated.changed | bool - php_conf_file_sapi is defined - php_conf_file_sapi == "fpm" @@ -123,7 +125,9 @@ path: "{{ php_conf_file_backup }}" state: absent changed_when: false - when: not php_conf_file_templated.changed | bool + when: + - php_conf_file_templated.changed is defined + - not php_conf_file_templated.changed | bool tags: - php diff --git a/tasks/pkg.yml b/tasks/pkg.yml index cfdb22a..e592ac2 100644 --- a/tasks/pkg.yml +++ b/tasks/pkg.yml @@ -71,10 +71,10 @@ var: php_pkg_install verbosity: "{% if ansible_check_mode | bool and php_pkg_install != [] %}0{% elif php_pkg_install != [] %}1{% else %}2{% endif %}" - - name: PHP packages purged + - name: PHP packages absent ansible.builtin.apt: pkg: "{{ php_pkg_rm }}" - purge: true + purge: false state: absent register: php_packages_removed when: php_pkg_rm != [] @@ -83,7 +83,10 @@ ansible.builtin.apt: pkg: "{{ php_pkg_install }}" state: latest + dpkg_options: force-confmiss update_cache: true + environment: + UCF_FORCE_CONFFMISS: "1" register: php_packages_installed when: php_pkg_install != [] diff --git a/templates/php.j2 b/templates/php.j2 index 97836bf..f5e1df0 100644 --- a/templates/php.j2 +++ b/templates/php.j2 @@ -1,11 +1,9 @@ -# {{ systemd_ansible_managed }} - -{% for php_section in | dict2items %} +# {{ ansible_managed }} +{% for php_section in php_conf_file_proposed_vars | dict2items %} [{{ php_section.key }}] {% for php_variable_pair in php_section.value | dict2items %} {{ php_variable_pair.key }} = {{ php_variable_pair.value }} - {% endfor %} {% endfor %} -- GitLab