Execution
Date 23 May 2025 14:10:09 +0100
Duration 00:06:35.75
Controller ssh-gw-4.layershift.com
User root
Versions
Ansible 2.16.11
ara 1.7.2 / 1.7.2
Python 3.10.10
Summary
391 Hosts
9 Tasks
3486 Results
1 Plays
1 Files
0 Records

File: /home/ssh-gateway/ansible/kuly/RM10018-update-wptoolkit.yaml

---
- name: Update Plesk panel.ini with ext-wp-toolkit settings (if Plesk server)
  hosts: all
  gather_facts: false

  vars:
    panel_ini_path: "/usr/local/psa/admin/conf/panel.ini"
    section_header: "[ext-wp-toolkit]"
    config_block: |

      [ext-wp-toolkit]
      showVirtualPatchesUpsellWhenRestrictedViaPlans = true
      purchaseDeluxeGuardianBaseUrl = https://plesk.layershift.com/
      virtualPatchesLicenseAdditionalLimit = 0
      virtualPatchesLicensingForEndCustomers = false


  tasks:
    - name: Get the Plesk info
      plesk_info:
      register: plsk

    - name: Conditional block for updating panel.ini (only on Plesk servers)
      when: plsk.plesk_found
      block:
        - name: Check if section exists in panel.ini file
          ansible.builtin.shell: "grep -qF '{{ section_header }}' {{ panel_ini_path }} && echo 'found' || echo 'not found'"
          register: section_exists_result
          changed_when: false
          args:
            _uses_shell: true

        - name: Set fact based on whether section exists
          ansible.builtin.set_fact:
            section_exists: "{{ section_exists_result.stdout == 'found' }}"

        - name: Alert if section is already present
          ansible.builtin.debug:
            msg: "⚠️ Section {{ section_header }} already exists in {{ panel_ini_path }}. No changes will be made."
          when: section_exists

        - name: Generate timestamp for backup filename
          ansible.builtin.shell: date +'%Y-%m-%d_%H-%M-%S'
          delegate_to: localhost
          run_once: true
          register: timestamp_result

        - name: Set backup path using generated timestamp
          ansible.builtin.set_fact:
            backup_path: "{{ panel_ini_path }}_{{ timestamp_result.stdout }}"

        - name: Backup panel.ini before modifying
          ansible.builtin.copy:
            src: "{{ panel_ini_path }}"
            dest: "{{ backup_path }}"
            remote_src: true
            mode: '0644'
          when: not section_exists

        - name: Append configuration block to panel.ini
          ansible.builtin.lineinfile:
            dest: "{{ panel_ini_path }}"
            line: "{{ config_block }}"
            create: false
          when: not section_exists

        - name: Notify user of successful update
          ansible.builtin.debug:
            msg: "✅ Configuration successfully added to {{ panel_ini_path }}"
          when: not section_exists