Execution
Date 03 Mar 2026 21:51:42 +0000
Duration 00:00:08.99
Controller ssh-gw-4.layershift.com
User root
Versions
Ansible 2.16.13
ara 1.7.4 / 1.7.4
Python 3.10.10
Summary
5 Hosts
3 Tasks
15 Results
1 Plays
1 Files
0 Records

File: /home/ssh-gateway/ansible/ansible-luca/ioncube-fixer.yaml

---
- name: RM10252 - PHP EOL Checker
  hosts: all
  gather_facts: false

  tasks:
    - name: Get Info
      plesk_info:
      register: plsk

    - name: Fixing poorly loaded ioncube Zend module
      ansible.builtin.shell: |
        set -o pipefail
        paths=$(find /opt/alt/php* -name "default.ini" | xargs grep -l "^zend_extension=.*ioncube_loader_lin.*" 2>/dev/null)

        if [[ -n "$paths" ]]; then
          package_names=$(echo "$paths" | awk -F'/' '{ print $3 "-" $4 "-ioncube-loader" }' )

          while IFS= read -r path <&3 && IFS= read -r package <&4; do

            if [[ "$package" == *"alt-php"* && "$path" == "/opt/alt/php"* ]]; then
              echo "[ INFO ] Installing package: $package"
              
              healthy_ioncube=$(echo $path | sed 's|/etc/php.d/default.ini|etc/php.d.all/ioncube_loader.ini')
              rc=0

              if [[ ! -f "$healthy_ioncube" ]]; then
                dnf install -y "$package"
              fi

              if [ "$rc" == 0 ]; then
                echo "[ INFO ] Removing the ioncube_loader_lin.so module from $path!"
                sed -i '/zend_extension=\/opt\/alt\/php.*\/ioncube_loader_lin_.*\.so/d' "$path"

                php_bin=$(echo $path | sed 's|/etc/php.d/default.ini|/usr/bin/php|')
                ioncube_ini=$(echo $path | sed 's|/php.d/default.ini|/php.d.all/ioncube_loader.ini|')
                dest_path=$(echo $path | sed 's|default.ini|10-ioncube_loader.ini|')

                ln -s "$ioncube_ini" "$dest_path"

                if ! "$php_bin" -i |  grep -w "ionCube24 v1[4-5]"; then
                  echo "[ ERROR ] Ioncube wasn't enabled successfully!"
                  exit 128
                else
                  echo "[ INFO ] Ioncube was enabled successfully!"
                  exit 0
                fi

              else
                echo "[ ERROR ] Failed to install $package. Stopping script!"
                exit 128
              fi

            else
              echo "[ ERROR ] Something went wrong: $path $package"
              exit 128
            fi

          done 3<<< "$paths" 4<<< "$package_names"
          find /opt/alt/php* -name "ioncube_loader_lin*.so" -type f -delete

        else
          echo "[ INFO ] ioncube_loader_lin.so file wasn't found!"
        fi

      args:
        executable: /bin/bash
      register: output
      when: (plsk.plesk_found and plsk.imunify_found) or (plsk.plesk_found and plsk.cloudlinux_found)
      changed_when: output.rc == 0
      failed_when: false

    - name: Record servers where the script failed
      ansible.builtin.lineinfile:
        create: true
        mode: '0644'
        path: RM10252/hostnames
        line: "{{ inventory_hostname }}"
      when: output.rc != 0
      delegate_to: localhost