-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlvm-partition_data.yml
56 lines (51 loc) · 1.47 KB
/
lvm-partition_data.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
51
52
53
54
55
56
---
- name: Playbook to create LV, Filesystem and Mount it
hosts: k8s_servers
remote_user: root
become: yes
become_method: sudo
#gather_facts: no
vars:
raw_disks: /dev/sdb # /dev/vdb,dev/vdc
vg_name: vg10
lv_name: container_data
lv_size: +100%FREE #80%VG, 200G
fs_type: xfs
mount_path: /var/lib/longhorn
delete_mount_path: false
tasks:
- name: Install lvm2 package
ansible.builtin.package:
name: [lvm2,xfsprogs]
state: present
- name: Create volume group
community.general.lvg:
vg: "{{ vg_name }}"
pvs: "{{ raw_disks }}"
state: present
- name: Create Logical Volume for data persistence
community.general.lvol:
vg: "{{ vg_name }}"
lv: "{{ lv_name }}"
size: "{{ lv_size }}"
state: present
- name: Create filesystem on LV
community.general.filesystem:
fstype: "{{ fs_type }}"
resizefs: true
dev: /dev/{{ vg_name }}/{{ lv_name }}
state: present
- name: Get LV UUID
ansible.builtin.command: lsblk /dev/{{ vg_name }}/{{ lv_name }} -no UUID
register: lv_uuid
- name: Remove {{ mount_path }} if exist
ansible.builtin.file:
path: "{{ mount_path }}"
state: absent
when: delete_mount_path
- name: Mount created filesystem
ansible.posix.mount:
path: "{{ mount_path }}"
src: UUID={{ lv_uuid.stdout }}
state: mounted
fstype: "{{ fs_type }}"