11---
2+ - name : check path
3+ set_fact :
4+ nvme_path_edited : " {% if nvme_path[-1] == '/' %}{{nvme_path[:-1]}}{% else%}{{nvme_path}}{% endif %}"
5+
6+ - name : Get the number of NVMe's
7+ set_fact :
8+ nvme_count : " {{ hostvars[inventory_hostname]['ansible_devices'] | select('match','nvme[0-9]n1') | list | length}}"
9+
10+ - name : Create a LVM?
11+ set_fact :
12+ one_lv : " {{( log_vol | bool ) and ( ( nvme_count | int ) > 1 )}}"
13+
214- name : Create a new primary partition
315 parted :
4- device : /dev/nvme0n1
16+ device : " /dev/{{item}} "
517 number : 1
618 state : present
719 label : gpt
8- when : " 'nvme0n1' in hostvars[inventory_hostname].ansible_devices"
20+ with_items :
21+ - " {{ hostvars[inventory_hostname]['ansible_devices'] | select('match','nvme[0-9]n1') | list }}"
22+
923- name : create a filesystem
1024 filesystem :
11- dev : /dev/nvme0n1p1
25+ dev : " /dev/{{item}}p1 "
1226 fstype : xfs
13- opts : -L localscratch
14- when : " 'nvme0n1' in hostvars[inventory_hostname].ansible_devices"
27+ opts : " -L locscratch{{item | replace('nvme','') | replace('n1','')}}"
28+ with_items :
29+ - " {{ hostvars[inventory_hostname]['ansible_devices'] | select('match','nvme[0-9]n1') | list }}"
30+ when : not ( one_lv | bool )
31+
1532- name : Mount local volume
1633 mount :
17- path : " {{ nvme_path } }"
18- src : LABEL=localscratch
34+ path : " {% if item | replace('nvme','') | replace('n1','') == '0' %}{{ nvme_path_edited}}{% else%}{{ nvme_path_edited}}{{item | replace('nvme','') | replace('n1','')}}{% endif % }"
35+ src : " LABEL=locscratch{{item | replace('nvme','') | replace('n1','')}} "
1936 fstype : xfs
2037 opts : defaults,noatime
2138 state : mounted
22- when : " 'nvme0n1' in hostvars[inventory_hostname].ansible_devices"
23- - name : " set permissions on {{ nvme_path }}"
39+ with_items :
40+ - " {{ hostvars[inventory_hostname]['ansible_devices'] | select('match','nvme[0-9]n1') | list }}"
41+ when : not ( one_lv | bool )
42+
43+ - name : " set permissions on {{ nvme_path_edited }}"
2444 become : true
2545 file :
26- path : " {{ nvme_path } }"
46+ path : " {% if item | replace('nvme','') | replace('n1','') == '0' %}{{ nvme_path_edited}}{% else%}{{ nvme_path_edited}}{{item | replace('nvme','') | replace('n1','')}}{% endif % }"
2747 state : directory
2848 owner : " {{ ansible_user }}"
2949 mode : 0775
3050 group : " {{privilege_group_name}}"
3151 recurse : no
32- when : " 'nvme0n1' in hostvars[inventory_hostname].ansible_devices"
52+ with_items :
53+ - " {{ hostvars[inventory_hostname]['ansible_devices'] | select('match','nvme[0-9]n1') | list }}"
54+ when : not ( one_lv | bool )
55+
56+ - name : Create volume group
57+ lvg :
58+ vg : " vg_nvmes"
59+ pvs : " {{['/dev/']|product(hostvars[inventory_hostname]['ansible_devices'] | select('match','nvme[0-9]n1') | list)|map('join', '') | join(',')}}"
60+ when : one_lv | bool
61+
62+ - name : Create Logical volume
63+ lvol :
64+ vg : " vg_nvmes"
65+ lv : " lv_nvmes"
66+ size : 100%FREE
67+ opts : " {% if redundancy | bool %}--type raid10{% else%}-i4{% endif %}"
68+ when : one_lv | bool
69+
70+ - name : Create file system
71+ filesystem :
72+ fstype : xfs
73+ dev : " /dev/vg_nvmes/lv_nvmes"
74+ when : one_lv | bool
75+
76+ - name : Mount local volume
77+ mount :
78+ path : " {{ nvme_path_edited}}"
79+ src : " /dev/vg_nvmes/lv_nvmes"
80+ fstype : xfs
81+ opts : defaults,noatime
82+ state : mounted
83+ when : one_lv | bool
84+
85+ - name : " set permissions on {{ nvme_path_edited }}"
86+ become : true
87+ file :
88+ path : " {{ nvme_path_edited}}"
89+ state : directory
90+ owner : " {{ ansible_user }}"
91+ mode : 0775
92+ group : " {{privilege_group_name}}"
93+ recurse : no
94+ when : one_lv | bool
0 commit comments