ansible-role-proxmox_vm_tools/tasks/resize_partition.yml
2022-08-06 11:55:56 +02:00

57 lines
1.6 KiB
YAML

- name: Agrandit le disque {{ item.disk }} de {{ item.size }}
uri:
url: "https://{{ pvmt_api_host }}:8006/api2/json/nodes/{{ pvmt_node }}/qemu/{{ pvmt_vm_id }}/resize"
validate_certs: no
method: PUT
headers:
Authorization: PVEAPIToken={{ pvmt_api_user }}!{{ pvmt_api_token_id }}={{ pvmt_api_token_secret }}
body_format: form-urlencoded
body:
disk: "{{ item.disk }}"
size: "{{ item.size }}"
- name: Attend l'application du changement
wait_for:
timeout: 2
- name: Agrandit la partition {{ item.partition }}
shell: |
set -x
# detection de la nouvelle taille des disques
for i in `ls /sys/class/block/*/device/rescan`; do echo 1 > $i; done
# teste si partition LVM
dev=$(mount | grep "\s{{ item.partition }}\s" | cut -d ' ' -f 1)
lvdisplay $dev
if [ $? -eq 0 ]
then
# identification du PV
echo "$dev est un LV"
vg=$(lvdisplay -C -o vg_name $dev | tail -n -1 | awk '{print $1}')
echo "$dev est dans le VG $vg"
pv=$(pvdisplay -C -o pv_name -S vg_name=$vg | tail -n -1 | awk '{ print $1 }')
echo "$vg est dans le PV $pv"
cryptsetup isLuks $pv
if [ $? ]
then
echo "$pv est chiffre, agrandissement du disque chiffre"
cryptsetup resize $pv
fi
echo "Agrandissement du PV"
pvresize $pv
echo "Agrandissement d'une partition LVM"
lvextend -l +100%FREE $dev
fi
# agrandissement du systeme de fichiers
xfs_growfs {{ item.partition }}
register: _shell_result
delegate_to: "{{ pvmt_vm_ip }}"
- debug:
var: _shell_result.stdout_lines
- debug:
var: _shell_result.stderr_lines