diff --git a/tasks/check_init.yml b/tasks/check_init.yml new file mode 100644 index 0000000000000000000000000000000000000000..200ffe8af0dc6cb1da35a8d16990c8225d09a54b --- /dev/null +++ b/tasks/check_init.yml @@ -0,0 +1,39 @@ +# Copyright 2019-2023 Chris Croome +# +# This file is part of the Webarchitects PHP Ansible role. +# +# The Webarchitects PHP Ansible role is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. +# +# The Webarchitects PHP Ansible role is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with the Webarchitects PHP Ansible role. If not, see <https://www.gnu.org/licenses/>. +--- +- name: Check the init system + block: + + # When in a docker container php_init.stdout == "sh" + - name: Check if system has been booted with systemd as init system + ansible.builtin.command: ps -p 1 -o comm= + changed_when: false + check_mode: false + register: php_ps + failed_when: php_ps.rc is not regex('^0|47$') + + - name: Set a fact for the init system + ansible.builtin.set_fact: + php_init: "{{ php_ps.stdout }}" + when: php_ps.rc == 0 + + - name: When the exit code is 47 assume is is because this is a chroot + ansible.builtin.set_fact: + php_init: "{{ php_ps.stdout }}" + when: php_ps.rc == 47 + + - name: Debug the ini system + ansible.builtin.debug: + var: php_init + verbosity: "{% if ansible_check_mode | bool %}0{% else %}1{% endif %}" + + tags: + - php +... diff --git a/tasks/file_edited.yml b/tasks/file_edited.yml index 95b3cb6aa8b51189340e049763ac8926d1586468..264bf96aab255e831e66a7bba7d409c446b370c8 100644 --- a/tasks/file_edited.yml +++ b/tasks/file_edited.yml @@ -110,7 +110,7 @@ owner: root group: root - - name: Test and reload PHP configuration file when file is in a FPM directory + - name: Test and reload PHP configuration file when file is in a FPM directory and the init system is systemd block: - name: Test PHP configuration @@ -159,6 +159,7 @@ state: reloaded when: + - php_init == "systemd" - php_conf_file_version in php_ver_installed - php_conf_file_changed | bool - php_conf_file_sapi is defined diff --git a/tasks/file_templated.yml b/tasks/file_templated.yml index f9c4d475462df882fd069464c12e263a941b9ef3..96f26776286c84814ee4ca0ad48bf3af82a0f6e5 100644 --- a/tasks/file_templated.yml +++ b/tasks/file_templated.yml @@ -64,7 +64,7 @@ group: root register: php_conf_file_templated - - name: Test and reload PHP configuration file when file is in a FPM directory + - name: Test and reload PHP configuration file when file is in a FPM directory and the init system is systemd block: - name: Test PHP configuration @@ -113,6 +113,7 @@ state: reloaded when: + - php_init == "systemd" - php_conf_file_version is defined - php_conf_file_version in php_ver_installed - php_conf_file_templated.changed is defined diff --git a/tasks/main.yml b/tasks/main.yml index 782909c9e53c2843b129da96c6568fac8bed7890..601a2f01c549f8613e6a7f36b7d643abd80b4882 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -43,6 +43,15 @@ - php_cfg - php_conf + - name: Include the init system check tasks + ansible.builtin.include_tasks: check_vars.yml + tags: + - php_apt + - php_cfg + - php_conf + - php_mods + - php_pkg + - name: Include Sury PHP apt repo tasks ansible.builtin.include_tasks: apt.yml when: php_sury is defined