Execution
Date 24 Jul 2025 09:54:22 +0100
Duration 00:00:02.68
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
6 Tasks
6 Results
1 Plays
1 Files
0 Records

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

---
- name: Search for diskusage block in file (simplified version)
  hosts: all
  gather_facts: false
  vars:
    config_file: "/etc/agent360.ini"  # Change this to your file path
  tasks:
    - name: Check if file exists
      ansible.builtin.stat:
        path: "{{ config_file }}"
      register: file_stat

    - name: Fail if file doesn't exist
      ansible.builtin.fail:
        msg: "File {{ config_file }} not found"
      when: not file_stat.stat.exists

    - name: Extract diskusage block using awk
      ansible.builtin.shell: |
        awk '
        /^\[diskusage\]$/ { found=1; print; next }
        found && /^\[.*\]$/ && !/^\[diskusage\]$/ { found=0; next }
        found { print }
        ' "{{ config_file }}"
      register: block_content
      ignore_errors: true

    - name: Display diskusage block content
      ansible.builtin.debug:
        msg: |
          Diskusage block content:
          =======================
          {{ block_content.stdout }}
      when: block_content.stdout != ""

    - name: Check if block was found
      ansible.builtin.shell: "grep -q '^\\[diskusage\\]$' {{ config_file }} && echo 'found' || echo 'not found'"
      register: block_exists
      changed_when: false

    - name: Display message if block not found
      ansible.builtin.debug:
        msg: "Block [diskusage] not found in the file"
      when: block_exists.stdout == "not found"