diff --git a/roles/common_healthcheck/tasks/main.yaml b/roles/common_healthcheck/tasks/main.yaml index c024da8..bf2d491 100644 --- a/roles/common_healthcheck/tasks/main.yaml +++ b/roles/common_healthcheck/tasks/main.yaml @@ -23,8 +23,8 @@ become: false # We have to use this complicated pipeline because of Alpine and its wierd df implementation ansible.builtin.shell: set -o pipefail && df -h / | tail -1 | awk '{gsub(/%/, "", $5); print $5}' - register: free_disk_space_result - failed_when: free_disk_space_result.stdout | int > 85 + register: common_healthcheck_space_left_result + failed_when: common_healthcheck_space_left_result.stdout | int > 85 changed_when: false # This task does not change the system rescue: @@ -41,5 +41,9 @@ body: - "{{ ansible_facts['hostname'] }}: Disk space is low" delegate_to: 127.0.0.1 - failed_when: false + failed_when: false # It's OK if it fails, not critical changed_when: false # This task does not change the system + + - name: Resize rootfs if it's an LXC + ansible.builtin.include_tasks: resize_lxc_rootfs.yaml + when: ansible_virtualization_type == 'lxc' diff --git a/roles/common_healthcheck/tasks/resize_lxc_rootfs.yaml b/roles/common_healthcheck/tasks/resize_lxc_rootfs.yaml new file mode 100644 index 0000000..b07bc1a --- /dev/null +++ b/roles/common_healthcheck/tasks/resize_lxc_rootfs.yaml @@ -0,0 +1,22 @@ +--- +- name: Get container info by name + delegate_to: localhost + become: false + community.general.proxmox_vm_info: + validate_certs: false + node: proxmox-server + api_user: root@pam + api_host: 192.168.0.2 + api_token_id: ansible + api_token_secret: "{{ proxmox_token_secret }}" + + name: "{{ inventory_hostname }}" + type: lxc + register: common_healthcheck_vmid + +- name: Resize LXC's rootfs + become: true + ansible.builtin.command: + cmd: pct resize {{ common_healthcheck_vmid.proxmox_vms[0].vmid }} rootfs +5G + delegate_to: 192.168.0.2 + changed_when: true