-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathprovision-storage.yml
More file actions
85 lines (75 loc) · 2.05 KB
/
provision-storage.yml
File metadata and controls
85 lines (75 loc) · 2.05 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
---
- name: Provision external storage device for logical volumes (LVM)
hosts: localhost
connection: local
become: true
vars:
device: /dev/sda
confirm_device: /dev/sdXX
partition: 1
volume_group: vg1
logical_volumes:
- name: vol01
mount_point: /opt/docker
size: 5G
- name: vol02
mount_point: /var/lib/docker
size: 10G
- name: vol03
mount_point: /srv
size: 100G
tasks:
# Verify device against device_confirm variable as a sort of failsafe.
- name: Verifying device
community.general.parted:
device: "{{ device }}"
unit: MiB
register: device_info
failed_when: not device_info.disk.dev == confirm_device
- name: Installing LVM2
apt:
name: lvm2
state: latest
update_cache: yes
# Use the whole device as a single LVM partition in a GUID partition table.
- name: Repartitioning device
community.general.parted:
device: "{{ device }}"
label: gpt
number: "{{ partition }}"
flags: [ lvm ]
state: present
- name: Creating volume group
community.general.lvg:
vg: "{{ volume_group }}"
pvs: "{{ device }}{{ partition }}"
- name: Creating volumes
community.general.lvol:
vg: "{{ volume_group }}"
lv: "{{ item.name }}"
size: "{{ item.size }}"
with_items:
- "{{ logical_volumes }}"
- name: Creating filesystems
filesystem:
fstype: ext4
dev: "/dev/{{ volume_group }}/{{ item.name }}"
with_items:
- "{{ logical_volumes }}"
- name: Creating mount-point directories
file:
path: "{{ item.mount_point }}"
state: directory
with_items:
- "{{ logical_volumes }}"
# The mount module also adds filesystems to /etc/fstab.
- name: Mounting filesystems
mount:
path: "{{ item.mount_point }}"
src: "/dev/{{ volume_group }}/{{ item.name }}"
fstype: ext4
opts: defaults,noatime
state: mounted
with_items:
- "{{ logical_volumes }}"
# Reference: https://www.redhat.com/sysadmin/automating-logical-volume-manager