-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate-disk.yml
52 lines (45 loc) · 1.26 KB
/
create-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
51
52
- name: Setup LVM PV VG
hosts: docker
gather_facts: True
vars:
ansible_ssh_pass: "{{server_password}}"
mntp: "/data"
vgname: "datavg"
pvname: "/dev/vdb"
lvname: "datalv"
vgfree: 100
size: "+100%FREE"
tasks:
- name: pvcreate
shell: "pvcreate {{pvname}}"
when: ansible_lvm["pvs"][pvname] is not defined
- name: Check for "{{vgname}}" VG
shell: "vgcreate {{vgname}} {{pvname}} && sleep 10"
when: ansible_lvm["vgs"][vgname] is not defined
- name: gather facts
setup:
- name: Check for VG Size of {{vgfree}}GiB
fail:
msg: "{{vg_free_g}} < {{vgfree}}"
vars:
vg_free_g: "{{ ansible_facts['lvm']['vgs'][vgname]['free_g'] | int }}"
when: vg_free_g|int < vgfree|int
- name: "check lvs"
shell: "lvs |grep {{vgname}}"
register: lvs_check
ignore_errors: true
- name: "Create {{vgfree}}GiB LVM on {{vgname}} VG"
shell: "lvcreate -l {{size}} -n {{lvname}} {{vgname}}"
when: lvs_check.rc != 0
- name: Set Filesystem
filesystem:
dev: "/dev/{{vgname}}/{{lvname}}"
fstype: xfs
when: lvs_check.rc != 0
- name: Mount LV
mount:
path: "{{mntp}}"
src: "/dev/{{vgname}}/{{lvname}}"
fstype: xfs
state: mounted
when: lvs_check.rc != 0