Обновить ansible/expand_ubuntu_lvm.yml

This commit is contained in:
2026-05-06 20:16:51 +03:00
parent 8b08e3a7fb
commit 700699004d
2 changed files with 66 additions and 139 deletions
+66
View File
@@ -0,0 +1,66 @@
---
- name: Expand Ubuntu LVM root filesystem
hosts: all
gather_facts: no
become: yes
vars:
root_disk: /dev/sda
root_partition: /dev/sda3
root_partition_number: 3
root_lv: /dev/mapper/ubuntu--vg-ubuntu--lv
tasks:
- name: Rescan SCSI bus
ansible.builtin.shell: |
for host in /sys/class/scsi_host/host*; do
echo "- - -" > "$host/scan"
done
args:
executable: /bin/bash
changed_when: true
- name: Wait after rescan
ansible.builtin.pause:
seconds: 5
- name: Ensure growpart is installed
ansible.builtin.apt:
name: cloud-guest-utils
state: present
update_cache: yes
- name: Expand partition if needed
ansible.builtin.command: "growpart {{ root_disk }} {{ root_partition_number }}"
register: growpart_result
changed_when: "'CHANGED:' in growpart_result.stdout"
failed_when: >
growpart_result.rc != 0 and
'NOCHANGE:' not in growpart_result.stdout
- name: Resize LVM physical volume
ansible.builtin.command: "pvresize {{ root_partition }}"
register: pvresize_result
changed_when: "'resized' in (pvresize_result.stdout | lower) or 'changed' in (pvresize_result.stdout | lower)"
failed_when: false
- name: Extend root logical volume and filesystem
ansible.builtin.command: "lvextend -r -l +100%FREE {{ root_lv }}"
register: lvextend_result
changed_when: "'logical volume' in (lvextend_result.stdout | lower) or 'size of logical volume' in (lvextend_result.stdout | lower)"
failed_when: false
- name: Show final disk state
ansible.builtin.shell: |
pvs
vgs
lvs
df -h /
args:
executable: /bin/bash
register: final_state
changed_when: false
- name: Print final disk state
ansible.builtin.debug:
var: final_state.stdout_lines