---
- name: Check for PHP FPM errors using standalone script
hosts: all
gather_facts: false
tasks:
- name: Get server info
plesk_info:
register: plsk
- name: On plesk server execute block
when: plsk.plesk_found
block:
- name: Upload standalone FPM error check script
ansible.builtin.copy:
src: zz-rm10179-check-for-php-errors.sh
dest: /root/zz-rm10179-check-for-php-errors.sh
mode: '0755'
changed_when: false
- name: Execute the FPM error check script
ansible.builtin.shell: |
set -o pipefail
/root/zz-rm10179-check-for-php-errors.sh --check-only
args:
executable: /bin/bash
register: script_out
failed_when: false # Don't fail the playbook on non-zero exit code
changed_when: >
(script_out.rc != 0) or
(':warning:' in script_out.stdout) or
(':gear:' in script_out.stdout)
- name: Extract clean status components
ansible.builtin.set_fact:
# Extract just the handler lists without the prefixes
in_use_clean: "{{ (script_out.stdout | regex_search('in use: ([^,]+(?:, [^,]+)*)') | default('None') | regex_replace('in use: ', '') | trim) }}"
manual_fix_clean: "{{ (script_out.stdout | regex_search('need manual: ([^,]+(?:, [^,]+)*)') | default('None') | regex_replace('need manual: ', '') | trim) }}"
would_fix_clean: "{{ (script_out.stdout | regex_search('would fix: ([^,]+(?:, [^,]+)*)') | default('None') | regex_replace('would fix: ', '') | trim) }}"
- name: Extract counts for summary
ansible.builtin.set_fact:
in_use_count: "{{ (in_use_clean.split(',') | length) if in_use_clean != 'None' else 0 }}"
manual_fix_count: "{{ (manual_fix_clean.split(',') | length) if manual_fix_clean != 'None' else 0 }}"
would_fix_count: "{{ (would_fix_clean.split(',') | length) if would_fix_clean != 'None' else 0 }}"
- name: Create clean summary line
ansible.builtin.set_fact:
summary_line: |
{{ inventory_hostname }} -
{% if in_use_count > 0 %}❌ {{ in_use_count }} in-use: {{ in_use_clean }}{% endif %}
{% if manual_fix_count > 0 %}{% if in_use_count > 0 %}, {% endif %}🔧 {{ manual_fix_count }} manual: {{ manual_fix_clean }}{% endif %}
{% if would_fix_count > 0 %}{% if in_use_count > 0 or manual_fix_count > 0 %}, {% endif %}✅ {{ would_fix_count }} would-fix: {{ would_fix_clean }}{% endif %}
{% if in_use_count == 0 and manual_fix_count == 0 and would_fix_count == 0 %}✅ Clean - No PHP FPM errors{% endif %}
| RC: {{ script_out.rc }}
- name: Display clean summary and save to file
ansible.builtin.lineinfile:
path: "/home/ssh-gateway/ansible/kuly/zz-rm10179-check-for-php-errors.txt"
line: "{{ summary_line | trim | regex_replace('\\s+', ' ') }}"
create: true
mode: '0644'
delegate_to: 127.0.0.1
- name: Show detailed output when problems found
ansible.builtin.debug:
msg: |
FPM Error Check Results for {{ inventory_hostname }}:
{{ script_out.stdout }}
when: >
(script_out.rc != 0) or
(':warning:' in script_out.stdout) or
(':gear:' in script_out.stdout) or
(':check:' in script_out.stdout and 'would fix' in script_out.stdout)
- name: Show success message when no problems
ansible.builtin.debug:
msg: "✅ No PHP FPM errors found on {{ inventory_hostname }}"
when: >
(script_out.rc == 0) and
(':warning:' not in script_out.stdout) and
(':gear:' not in script_out.stdout) and
(':check:' not in script_out.stdout or 'No problems found' in script_out.stdout)