Execution
Date
24 Jul 2025 10:31:16 +0100
Duration
None
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
9
Tasks
9
Results
1
Plays
1
Files
0
Records
File: /home/ssh-gateway/ansible/kuly/RM10092_agent360_conf_change.yaml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 | --- - name: Search for diskusage block in file and replace it hosts: all gather_facts: false vars: config_file: "/etc/agent360.ini" 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 changed_when: false - 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" - name: Configure diskusage block and restart service when: block_exists.stdout == "found" block: - name: Replace diskusage block with new content ansible.builtin.replace: path: "{{ config_file }}" regexp: | (?sm)^\[diskusage\].*?^(?=\[.*\]|$) replace: | [diskusage] enabled = true exclude = /dev/loop,/dev/snap,/squashfs,/cagefs-skeleton,/restore\n backup: true owner: agent360 mode: '0600' register: replace_result - name: Display replacement result ansible.builtin.debug: msg: "Successfully replaced diskusage block" when: replace_result.changed - name: Display message when no changes were needed ansible.builtin.debug: msg: "No changes made to the file" when: not replace_result.changed - name: Restart agent360 service ansible.builtin.systemd: name: agent360 state: restarted enabled: true register: service_result - name: Wait for service to stabilize ansible.builtin.pause: seconds: 5 when: service_result.changed - name: Check if agent360 service is running ansible.builtin.systemd: name: agent360 state: started register: service_status - name: Display service status ansible.builtin.debug: msg: | Service Status: =============== Name: {{ service_status.name }} State: {{ service_status.state }} Enabled: {{ service_status.enabled }} when: service_status is defined - name: Fail if service is not running ansible.builtin.fail: msg: "agent360 service failed to start properly" when: - service_status is defined - service_status.state != "started" - name: Display final status ansible.builtin.debug: msg: "Configuration update and service restart completed successfully" when: - block_exists.stdout == "found" - service_status is defined - service_status.state == "started" |