Execution
Date 07 Nov 2025 09:27:19 +0000
Duration 00:00:21.94
Controller ssh-gw-4.layershift.com
User root
Versions
Ansible 2.16.11
ara 1.7.3 / 1.7.3
Python 3.10.10
Summary
2 Hosts
10 Tasks
10 Results
1 Plays
1 Files
0 Records

File: /home/ssh-gateway/ansible/kuly/zz-rm10179-check-for-php-errors.yaml

---
- 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: Parse problematic handlers from output
          ansible.builtin.set_fact:
            problematic_handlers: "{{ script_out.stdout | regex_findall('(?:in use:|need manual:)([^\\n]+)') }}"

        - name: Extract in-use problematic handlers
          ansible.builtin.set_fact:
            in_use_handlers: "{{ script_out.stdout | regex_search('in use:([^,]+)') | default('None') }}"

        - name: Extract manual-fix handlers
          ansible.builtin.set_fact:
            manual_fix_handlers: "{{ script_out.stdout | regex_search('need manual:([^\\n]+)') | default('None') }}"

        - name: Extract would-fix handlers
          ansible.builtin.set_fact:
            would_fix_handlers: "{{ script_out.stdout | regex_search('would fix:([^\\n]+)') | default('None') }}"

        - name: Display summary and save to file
          ansible.builtin.lineinfile:
            path: "/home/ssh-gateway/ansible/kuly/zz-rm10179-check-for-php-errors.txt"
            line: "{{ inventory_hostname }} - {{ script_out.stdout | regex_search('Status: ([^\\n]+)') | default('Status: Unknown') }} | In-use: {{ in_use_handlers | trim }} | Manual-fix: {{ manual_fix_handlers | trim }} | Would-fix: {{ would_fix_handlers | trim }} | RC: {{ script_out.rc }}"
            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)