-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate_mount_point.yml
55 lines (48 loc) · 1.43 KB
/
create_mount_point.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
---
- name: Get disk label and create a mount point
hosts: all
become: yes
tasks:
- name: Gather disk facts
command: lsblk -o NAME,TYPE,SIZE,UUID,MOUNTPOINT -dn
register: lsblk_output
- name: Debug lsblk output
debug:
var: lsblk_output.stdout_lines
- name: Find non-main disk
set_fact:
non_main_disk_info: "{{ item.split() }}"
loop: "{{ lsblk_output.stdout_lines }}"
loop_control:
label: "{{ item }}"
when:
- item.split() | length >= 5
- item.split()[1] == 'disk'
- item.split()[0] != 'sda'
- item.split()[4] == ''
- name: Fail if no suitable non-main disk is found
fail:
msg: "No suitable non-main disk found."
when: non_main_disk_info is not defined
- name: Create filesystem on the non-main disk
filesystem:
fstype: ext4
dev: "/dev/{{ non_main_disk_info[0] }}"
when: non_main_disk_info is defined
- name: Create mount point directory
file:
path: /mnt/my_mount_point
state: directory
- name: Mount the filesystem
mount:
path: /mnt/my_mount_point
src: "/dev/{{ non_main_disk_info[0] }}"
fstype: ext4
state: mounted
- name: Persist the mount in fstab
mount:
path: /mnt/my_mount_point
src: "/dev/{{ non_main_disk_info[0] }}"
fstype: ext4
opts: defaults
state: present