diff --git a/README.md b/README.md index 7302a5f..0ba67e5 100644 --- a/README.md +++ b/README.md @@ -1,19 +1,16 @@ -proxmox-vm-tools -================ +# proxmox-vm-tools Gestion de vms kvm en environnement proxmox -Prerequis ---------- +## Prerequis - un compte de service dans le cluster proxmox - un api token pour ce compte de service - les droits PVEVMAdmin et PVEDatastoreUser associés au token -Variables ---------- +# Variables Exemple de variables pour setup_vm.yml @@ -34,16 +31,28 @@ pvmt_vm_cores: 2 pvmt_vm_storage: local-lvm pvmt_vm_ciuser: svc-ansible pvmt_vm_sshkeys: 'ssh-rsa AAA [...] 06Rnk= user@machine' -pvmt_vm_disk_grow: +pvmt_vm_disk: - disk: scsi1 size: 1G - partition: / - - disk: scsi1 - size: 1G - partition: /var + pvuuid: uCbfU7-SI8m-ixnk-vMKJ-gpoQ-LgIh-58whLX + encrypted: "false" - disk: scsi2 size: 2G - partition: /data1 + pvuuid: 34azET-vMKJ-gpoQ-3Vm4-jiY9-3yAl-62r7i3 + encrypted: "true" +pvmt_vm_lvm_volumes: + - name: root + size: 6G + vg: system + - name: swap + size: 1G + vg: system + - name: data1 + size: 10G + vg: luksdata + - name: data2 + size: 10G + vg: luksdata # vlan vars nom_du_vlan: @@ -54,17 +63,18 @@ nom_du_vlan: searchdomain: domaine.local ``` -Dependences ------------ -Exemple de playbook --------------------- +## Exemple d'utilisation -License -------- -https://www.gnu.org/licenses/gpl-3.0.fr.html +## Gestion des disques +- Si nécessaire les nouveaux volume groups sont à créer manuellement avant de pouvoir être référencés, par exemple : +`vgcreate luksdata /dev/mapper/mondisque` + +- Si de nouveaux volumes lvm sont créés, ils ne sont pour autant ni formatés ni montés quelque part et doivent être définis dans fstab + +- Si un volume est agrandi, le système de fichiers du volume l'est aussi diff --git a/tasks/resize_disk.yml b/tasks/resize_disk.yml new file mode 100644 index 0000000..a0b0070 --- /dev/null +++ b/tasks/resize_disk.yml @@ -0,0 +1,40 @@ +- 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 le PV {{ item.pvuuid }} + shell: | + set -x + # detection de la nouvelle taille des disques + for i in `ls /sys/class/block/*/device/rescan`; do echo 1 > $i; done + + PV=$(pvs -v | grep {{ item.pvuuid }} | awk '{ print $1 }') + + if [ '{{ item.encrypted }}' = 'true' ] + then + echo "$PV est chiffre, agrandissement du disque chiffre" + cryptsetup resize $PV + fi + echo "Agrandissement du PV" + pvresize $PV + register: _shell_result + delegate_to: "{{ pvmt_vm_ip }}" + +- debug: + var: _shell_result.stdout_lines + +- debug: + var: _shell_result.stderr_lines + diff --git a/tasks/resize_partition.yml b/tasks/resize_partition.yml deleted file mode 100644 index 0e248ee..0000000 --- a/tasks/resize_partition.yml +++ /dev/null @@ -1,57 +0,0 @@ -- 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" - - lsblk -pP $pv | grep $pv | grep 'TYPE="crypt"' - if [ $? -eq 0 ] - 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 - diff --git a/tasks/setup_vm.yml b/tasks/setup_vm.yml index 67f47a7..c043419 100644 --- a/tasks/setup_vm.yml +++ b/tasks/setup_vm.yml @@ -67,8 +67,19 @@ - local_action: wait_for port=22 host="{{ pvmt_vm_ip }}" search_regex=OpenSSH -- name: Agrandit la partition {{ item.partition }} - include_tasks: resize_partition.yml +- name: Agrandit le disque + include_tasks: resize_disk.yml with_items: - - "{{ pvmt_vm_disk_grow }}" - + - "{{ pvmt_vm_disk }}" + + +- name: Definit logical volume + lvol: + vg: "{{ item.vg }}" + lv: "{{ item.name }}" + size: "{{ item.size }}" + resizefs: true + delegate_to: "{{ pvmt_vm_ip }}" + with_items: + - "{{ pvmt_vm_lvm_volumes }}" +