Skip to content

Commit 1bdc2ac

Browse files
committed
playbooks: Add a role to create an LVM volume group
There are currently three playbooks that need to set up a volume group: nfsd, smbd, and iscsi. All three need to steer their way around the physical root and data partitions, in addition to managing the differences between cloud providers. Refactor (de-duplicate) the LVM-related tasks in these three playbooks into a new role that can be shared and then later updated to avoid already in-use physical block devices. Reviewed-by: Luis Chamberlain <[email protected]> Signed-off-by: Chuck Lever <[email protected]>
1 parent d0ddc8e commit 1bdc2ac

File tree

12 files changed

+105
-58
lines changed

12 files changed

+105
-58
lines changed

kconfigs/Kconfig.nfsd

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,14 @@ config NFSD_LEASE_TIME
6767
complete faster.
6868

6969
choice
70-
prompt "Local or external physical storage"
70+
prompt "Persistent storage for exported file systems"
7171
default NFSD_EXPORT_STORAGE_LOCAL
7272

7373
config NFSD_EXPORT_STORAGE_LOCAL
7474
bool "Local"
7575
help
76-
Exported file systems will reside on physical storage
77-
local to the NFS server itself.
76+
Exported file systems will reside on block devices local
77+
to the NFS server itself.
7878

7979
config NFSD_EXPORT_STORAGE_ISCSI
8080
bool "iSCSI"

playbooks/roles/iscsi/tasks/main.yml

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,24 +18,13 @@
1818
name: "{{ iscsi_target_packages }}"
1919
state: present
2020

21-
- name: Initialize the list of local physical volumes
22-
ansible.builtin.set_fact:
23-
iscsi_lvm_pvs: []
24-
25-
- name: Expand the list of local physical volumes
26-
ansible.builtin.set_fact:
27-
iscsi_lvm_pvs: "{{ iscsi_lvm_pvs + [iscsi_target_pv_prefix + item | string] }}"
28-
with_items: "{{ range(1, iscsi_target_pv_count + 1) }}"
29-
loop_control:
30-
label: "Adding {{ iscsi_target_pv_prefix + item | string }} ..."
31-
32-
- name: Create LVM volume group {{ iscsi_target_vg_name }}
33-
become: true
34-
become_flags: 'su - -c'
35-
become_method: ansible.builtin.sudo
36-
community.general.lvg:
37-
vg: "{{ iscsi_target_vg_name }}"
38-
pvs: "{{ iscsi_lvm_pvs | join(',') }}"
21+
- name: Set up a volume group on local block devices
22+
ansible.builtin.include_role:
23+
name: volume_group
24+
vars:
25+
volume_group_name: "{{ iscsi_target_vg_name }}"
26+
volume_device_prefix: "{{ iscsi_target_pv_prefix }}"
27+
volume_device_count: "{{ iscsi_target_pv_count }}"
3928

4029
- name: Create a directory for storing iSCSI persistent reservations
4130
become: true
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
---
22
iscsi_target_packages:
3-
- lvm2
43
- targetcli-fb
54
- sg3_utils

playbooks/roles/iscsi/vars/RedHat.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
---
22
iscsi_target_packages:
3-
- lvm2
43
- targetcli
54
- sg3_utils
65

playbooks/roles/iscsi/vars/Suse.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
---
22
iscsi_target_packages:
3-
- lvm2
43
- targetcli-fb
54
- sg3_utils
65

playbooks/roles/nfsd/defaults/main.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# SPDX-License-Identifier GPL-2.0+
22
---
33
# Our sensible defaults for the nfsd role.
4-
nfsd_lvm_pvs: []
54
nfsd_export_device_prefix: ""
65
nfsd_export_device_count: 0
76
nfsd_export_label: "export"

playbooks/roles/nfsd/tasks/main.yml

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -30,22 +30,13 @@
3030
- nfsd_export_storage_iscsi|bool
3131
- nfsd_export_fstype != "tmpfs"
3232

33-
- name: Build string of devices to use as PVs
34-
set_fact:
35-
nfsd_lvm_pvs: "{{ nfsd_lvm_pvs + [ nfsd_export_device_prefix + item|string ] }}"
36-
with_items: "{{ range(1, nfsd_export_device_count + 1) }}"
37-
loop_control:
38-
label: "Physical volume: {{ nfsd_export_device_prefix + item|string }}"
39-
when:
40-
- nfsd_export_storage_local|bool
41-
42-
- name: Create a new LVM VG
43-
become: yes
44-
become_flags: 'su - -c'
45-
become_method: sudo
46-
community.general.lvg:
47-
vg: "exports"
48-
pvs: "{{ nfsd_lvm_pvs | join(',') }}"
33+
- name: Set up a volume group on local block devices
34+
ansible.builtin.include_role:
35+
name: volume_group
36+
vars:
37+
volume_group_name: "exports"
38+
volume_device_prefix: "{{ nfsd_export_device_prefix }}"
39+
volume_device_count: "{{ nfsd_export_device_count }}"
4940
when:
5041
- nfsd_export_storage_local|bool
5142
- nfsd_export_fstype != "tmpfs"
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
---
2-
smbd_lvm_pvs: []
32
smbd_share_device_prefix: ""
43
smbd_share_device_count: 0
54
smbd_share_label: "share"

playbooks/roles/smbd/tasks/main.yml

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,13 @@
2222
group: root
2323
mode: 0644
2424

25-
- name: Build string of devices to use as PVs
26-
set_fact:
27-
smbd_lvm_pvs: "{{ smbd_lvm_pvs + [ smbd_share_device_prefix + item|string ] }}"
28-
with_items: "{{ range(1, smbd_share_device_count + 1) }}"
29-
30-
- name: Print the PV list
31-
ansible.builtin.debug:
32-
var: smbd_lvm_pvs
33-
34-
- name: Create a new LVM VG
35-
become: yes
36-
become_flags: 'su - -c'
37-
become_method: sudo
38-
community.general.lvg:
39-
vg: "shares"
40-
pvs: "{{ smbd_lvm_pvs | join(',') }}"
25+
- name: Set up a volume group on local block devices
26+
ansbiel.builtin.include_role:
27+
name: volume_group
28+
var:
29+
volume_group_name: "shares"
30+
volume_device_prefix: "{{ smbd_share_device_prefix }}"
31+
volume_device_count: "{{ smbd_share_device_count }}"
4132

4233
- name: Create {{ smbd_share_path }}
4334
become: yes
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
volume_group
2+
============
3+
4+
The volume_group playbook creates a logical volume group
5+
on a target node using unused block devices.
6+
7+
Requirements
8+
------------
9+
10+
The ansible community.general collection must be installed on the
11+
control host.
12+
13+
Role Variables
14+
--------------
15+
16+
* volume_group_name: The name for new volume group (string)
17+
* volume_device_prefix: The pathname prefix for block devices to
18+
consider for the new volume group (string)
19+
* volume_device_count: The number of block devices to include in
20+
the new volume group (int)
21+
22+
Dependencies
23+
------------
24+
25+
None.
26+
27+
Example Playbook
28+
----------------
29+
30+
Below is an example playbook task:
31+
32+
```
33+
- name: Create a volume group for NFSD exports
34+
ansible.builtin.include_role:
35+
name: volume_group
36+
vars:
37+
volume_group_name: "exports"
38+
volume_device_prefix: "/dev/disk/by-id/virtio*"
39+
volume_count: 3
40+
```
41+
42+
For further examples refer to one of this role's users, the
43+
[https://github.com/linux-kdevops/kdevops](kdevops) project.
44+
45+
License
46+
-------
47+
48+
copyleft-next-0.3.1

0 commit comments

Comments
 (0)