Execution
Date 24 Jul 2025 09:52:07 +0100
Duration 00:00:02.01
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
1 Files
0 Records

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

---
- name: Search for diskusage block in file
  hosts: all
  gather_facts: false
  vars:
    config_file: "/etc/agent360.ini"
  tasks:
    - name: Read the configuration file
      ansible.builtin.slurp:
        src: "{{ config_file }}"
      register: file_content
      ignore_errors: true

    - name: Fail if file doesn't exist
      ansible.builtin.fail:
        msg: "File {{ config_file }} not found"
      when: file_content is failed

    - name: Decode file content
      ansible.builtin.set_fact:
        decoded_content: "{{ (file_content.content | b64decode).splitlines() }}"

    - name: Extract diskusage block
      ansible.builtin.set_fact:
        diskusage_block: "{{ decoded_content | select('match', '\\[diskusage\\]') | list }}"

    - name: Find diskusage block and extract content
      ansible.builtin.set_fact:
        block_content: |
          {% set found_block = false %}
          {% set result = [] %}
          {% for line in decoded_content %}
          {%   if line.strip() == '[diskusage]' %}
          {%     set found_block = true %}
          {%   elif found_block and line.startswith('[') and line.endswith(']') and line != '[diskusage]' %}
          {%     set found_block = false %}
          {%   elif found_block %}
          {%     set result = result.append(line) %}
          {%   endif %}
          {% endfor %}
          {{ result | join('\n') }}
        block_found: |
          {% set found = false %}
          {% for line in decoded_content %}
          {%   if line.strip() == '[diskusage]' %}
          {%     set found = true %}
          {%   endif %}
          {% endfor %}
          {{ found }}

    - name: Display diskusage block content
      ansible.builtin.debug:
        msg: |
          Diskusage block content:
          =======================
          {{ block_content }}
      when: block_found | bool

    - name: Display message if block not found
      ansible.builtin.debug:
        msg: "Block [diskusage] not found in the file"
      when: not (block_found | bool)