-
Notifications
You must be signed in to change notification settings - Fork 12
/
vm_extend_lv_with_new_disk.yml
50 lines (40 loc) · 1.28 KB
/
vm_extend_lv_with_new_disk.yml
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
---
- name: Provision new disk to VM
hosts: all
vars:
- vm_lv_name: "home"
- vm_vg_name: "rvg"
- lv_size: '+100%FREE'
collections:
- redhat.rhel_system_roles
- community.general
tasks:
- name: Register unused disk to variable
find_unused_disk:
min_size: '1g'
register: vm_unused_disk
failed_when: "'Unable to find unused disk' in vm_unused_disk"
- name: Unused disk output debug
debug:
msg: "{{ vm_unused_disk }}"
verbosity: 1
- name: Unused disks debug
debug:
msg: "{{ vm_unused_disk.disks[0] }}"
verbosity: 1
- name: Check if there is empty disks and abort playbook if there isn't
when: vm_unused_disk.disks[0] == "Unable to find unused disk"
fail:
msg: "Unable to find unused disk from the VM."
- name: Create PV with CMD
command: pvcreate "/dev/{{ vm_unused_disk.disks[0] }}"
- name: Add PV to given VG with CMD
command: vgextend "{{ vm_vg_name }}" "/dev/{{ vm_unused_disk.disks[0] }}"
- name: >
Extend the logical volume to take all remaining space of the PVs
and resize the underlying filesystem
lvol:
vg: "{{ vm_vg_name }}"
lv: "{{ vm_lv_name }}"
size: "{{ lv_size }}"
resizefs: true