Execution
Date 13 Sep 2024 10:24:29 +0100
Duration 00:00:04.77
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
1 Hosts
7 Tasks
7 Results
1 Plays
6 Files
0 Records

File: /home/ssh-gateway/ansible/kuly/remove_ini_blocks.yaml

---
- name: Remove specific monitoring blocks
  hosts: all
  gather_facts: true
  roles:
    - plesk
  tasks:
    - name: Execute on plesk servers
      when: plesk_found
      block:
        - name: Backup /etc/agent360-custom.ini with a timestamp
          ansible.builtin.copy:
            src: /etc/agent360-custom.ini
            dest: "/etc/agent360-custom.ini.bak_{{ ansible_date_time.epoch }}"
            remote_src: true
            mode: '0644'

        - name: Read the /etc/agent360-custom.ini file
          ansible.builtin.slurp:
            path: /etc/agent360-custom.ini
          register: agent_ini_file

        - name: Remove php_errors_monitoring block
          ansible.builtin.replace:
            path: /etc/agent360-custom.ini
            regexp: '(\[php_errors_monitoring\](?:\n[^\[]*)*)'
            replace: ''
          when: "'[php_errors_monitoring]' in (agent_ini_file.content | b64decode)"

        - name: Remove apache_error_monitoring block (until next block or EOF)
          ansible.builtin.replace:
            path: /etc/agent360-custom.ini
            regexp: '(\[apache_error_monitoring\](?:\n[^\[]*)*)'
            replace: ''
          when: "'[apache_error_monitoring]' in (agent_ini_file.content | b64decode)"

        - name: Ensure exactly one blank line between INI blocks
          ansible.builtin.replace:
            path: /etc/agent360-custom.ini
            regexp: '(\n+)(\[.*\])'
            replace: '\n\n\2'