diff mbox series

[v1,06/13] playbooks: Add a role to create an LVM volume group

Message ID 20250310141813.969325-7-cel@kernel.org (mailing list archive)
State New
Headers show
Series Block device provisioning for storage nodes | expand

Commit Message

Chuck Lever March 10, 2025, 2:18 p.m. UTC
From: Chuck Lever <chuck.lever@oracle.com>

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.

Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
---
 kconfigs/Kconfig.nfsd                         |  6 +--
 playbooks/roles/iscsi/tasks/main.yml          | 25 +++-------
 playbooks/roles/iscsi/vars/Debian.yml         |  1 -
 playbooks/roles/iscsi/vars/RedHat.yml         |  1 -
 playbooks/roles/iscsi/vars/Suse.yml           |  1 -
 playbooks/roles/nfsd/defaults/main.yml        |  1 -
 playbooks/roles/nfsd/tasks/main.yml           | 23 +++------
 playbooks/roles/smbd/defaults/main.yml        |  1 -
 playbooks/roles/smbd/tasks/main.yml           | 23 +++------
 playbooks/roles/volume_group/README.md        | 48 +++++++++++++++++++
 .../roles/volume_group/defaults/main.yml      |  2 +
 playbooks/roles/volume_group/tasks/main.yml   | 31 ++++++++++++
 12 files changed, 105 insertions(+), 58 deletions(-)
 create mode 100644 playbooks/roles/volume_group/README.md
 create mode 100644 playbooks/roles/volume_group/defaults/main.yml
 create mode 100644 playbooks/roles/volume_group/tasks/main.yml
diff mbox series

Patch

diff --git a/kconfigs/Kconfig.nfsd b/kconfigs/Kconfig.nfsd
index d071f5fba278..60e9da1aba2d 100644
--- a/kconfigs/Kconfig.nfsd
+++ b/kconfigs/Kconfig.nfsd
@@ -67,14 +67,14 @@  config NFSD_LEASE_TIME
 	  complete faster.
 
 choice
-	prompt "Local or external physical storage"
+	prompt "Persistent storage for exported file systems"
 	default NFSD_EXPORT_STORAGE_LOCAL
 
 config NFSD_EXPORT_STORAGE_LOCAL
 	bool "Local"
 	help
-	  Exported file systems will reside on physical storage
-	  local to the NFS server itself.
+	  Exported file systems will reside on block devices local
+	  to the NFS server itself.
 
 config NFSD_EXPORT_STORAGE_ISCSI
 	bool "iSCSI"
diff --git a/playbooks/roles/iscsi/tasks/main.yml b/playbooks/roles/iscsi/tasks/main.yml
index bbb49756f4da..2638bacc882b 100644
--- a/playbooks/roles/iscsi/tasks/main.yml
+++ b/playbooks/roles/iscsi/tasks/main.yml
@@ -18,24 +18,13 @@ 
     name: "{{ iscsi_target_packages }}"
     state: present
 
-- name: Initialize the list of local physical volumes
-  ansible.builtin.set_fact:
-    iscsi_lvm_pvs: []
-
-- name: Expand the list of local physical volumes
-  ansible.builtin.set_fact:
-    iscsi_lvm_pvs: "{{ iscsi_lvm_pvs + [iscsi_target_pv_prefix + item | string] }}"
-  with_items: "{{ range(1, iscsi_target_pv_count + 1) }}"
-  loop_control:
-    label: "Adding {{ iscsi_target_pv_prefix + item | string }} ..."
-
-- name: Create LVM volume group {{ iscsi_target_vg_name }}
-  become: true
-  become_flags: 'su - -c'
-  become_method: ansible.builtin.sudo
-  community.general.lvg:
-    vg: "{{ iscsi_target_vg_name }}"
-    pvs: "{{ iscsi_lvm_pvs | join(',') }}"
+- name: Set up a volume group on local block devices
+  ansible.builtin.include_role:
+    name: volume_group
+  vars:
+    volume_group_name: "{{ iscsi_target_vg_name }}"
+    volume_device_prefix: "{{ iscsi_target_pv_prefix }}"
+    volume_device_count: "{{ iscsi_target_pv_count }}"
 
 - name: Create a directory for storing iSCSI persistent reservations
   become: true
diff --git a/playbooks/roles/iscsi/vars/Debian.yml b/playbooks/roles/iscsi/vars/Debian.yml
index 9571f1de98c2..e353c17ee568 100644
--- a/playbooks/roles/iscsi/vars/Debian.yml
+++ b/playbooks/roles/iscsi/vars/Debian.yml
@@ -1,5 +1,4 @@ 
 ---
 iscsi_target_packages:
-  - lvm2
   - targetcli-fb
   - sg3_utils
diff --git a/playbooks/roles/iscsi/vars/RedHat.yml b/playbooks/roles/iscsi/vars/RedHat.yml
index 6082344368d6..b5376613d55e 100644
--- a/playbooks/roles/iscsi/vars/RedHat.yml
+++ b/playbooks/roles/iscsi/vars/RedHat.yml
@@ -1,6 +1,5 @@ 
 ---
 iscsi_target_packages:
-  - lvm2
   - targetcli
   - sg3_utils
 
diff --git a/playbooks/roles/iscsi/vars/Suse.yml b/playbooks/roles/iscsi/vars/Suse.yml
index 63393d988f1e..1b1c0b25a8aa 100644
--- a/playbooks/roles/iscsi/vars/Suse.yml
+++ b/playbooks/roles/iscsi/vars/Suse.yml
@@ -1,6 +1,5 @@ 
 ---
 iscsi_target_packages:
-  - lvm2
   - targetcli-fb
   - sg3_utils
 
diff --git a/playbooks/roles/nfsd/defaults/main.yml b/playbooks/roles/nfsd/defaults/main.yml
index 271d2d1d8912..ccdee468bd02 100644
--- a/playbooks/roles/nfsd/defaults/main.yml
+++ b/playbooks/roles/nfsd/defaults/main.yml
@@ -1,7 +1,6 @@ 
 # SPDX-License-Identifier GPL-2.0+
 ---
 # Our sensible defaults for the nfsd role.
-nfsd_lvm_pvs: []
 nfsd_export_device_prefix: ""
 nfsd_export_device_count: 0
 nfsd_export_label: "export"
diff --git a/playbooks/roles/nfsd/tasks/main.yml b/playbooks/roles/nfsd/tasks/main.yml
index 7e18c3813900..144ecd86686e 100644
--- a/playbooks/roles/nfsd/tasks/main.yml
+++ b/playbooks/roles/nfsd/tasks/main.yml
@@ -30,22 +30,13 @@ 
     - nfsd_export_storage_iscsi|bool
     - nfsd_export_fstype != "tmpfs"
 
-- name: Build string of devices to use as PVs
-  set_fact:
-    nfsd_lvm_pvs: "{{ nfsd_lvm_pvs + [ nfsd_export_device_prefix + item|string ] }}"
-  with_items: "{{ range(1, nfsd_export_device_count + 1) }}"
-  loop_control:
-    label: "Physical volume: {{ nfsd_export_device_prefix + item|string }}"
-  when:
-    - nfsd_export_storage_local|bool
-
-- name: Create a new LVM VG
-  become: yes
-  become_flags: 'su - -c'
-  become_method: sudo
-  community.general.lvg:
-    vg: "exports"
-    pvs: "{{ nfsd_lvm_pvs | join(',') }}"
+- name: Set up a volume group on local block devices
+  ansible.builtin.include_role:
+    name: volume_group
+  vars:
+    volume_group_name: "exports"
+    volume_device_prefix: "{{ nfsd_export_device_prefix }}"
+    volume_device_count: "{{ nfsd_export_device_count }}"
   when:
     - nfsd_export_storage_local|bool
     - nfsd_export_fstype != "tmpfs"
diff --git a/playbooks/roles/smbd/defaults/main.yml b/playbooks/roles/smbd/defaults/main.yml
index d75cc0b4ce75..4161224f27b9 100644
--- a/playbooks/roles/smbd/defaults/main.yml
+++ b/playbooks/roles/smbd/defaults/main.yml
@@ -1,5 +1,4 @@ 
 ---
-smbd_lvm_pvs: []
 smbd_share_device_prefix: ""
 smbd_share_device_count: 0
 smbd_share_label: "share"
diff --git a/playbooks/roles/smbd/tasks/main.yml b/playbooks/roles/smbd/tasks/main.yml
index bb19009606f7..486ccdc613bf 100644
--- a/playbooks/roles/smbd/tasks/main.yml
+++ b/playbooks/roles/smbd/tasks/main.yml
@@ -22,22 +22,13 @@ 
     group: root
     mode: 0644
 
-- name: Build string of devices to use as PVs
-  set_fact:
-    smbd_lvm_pvs: "{{ smbd_lvm_pvs + [ smbd_share_device_prefix + item|string ] }}"
-  with_items: "{{ range(1, smbd_share_device_count + 1) }}"
-
-- name: Print the PV list
-  ansible.builtin.debug:
-    var: smbd_lvm_pvs
-
-- name: Create a new LVM VG
-  become: yes
-  become_flags: 'su - -c'
-  become_method: sudo
-  community.general.lvg:
-    vg: "shares"
-    pvs: "{{ smbd_lvm_pvs | join(',') }}"
+- name: Set up a volume group on local block devices
+  ansbiel.builtin.include_role:
+    name: volume_group
+  var:
+    volume_group_name: "shares"
+    volume_device_prefix: "{{ smbd_share_device_prefix }}"
+    volume_device_count: "{{ smbd_share_device_count }}"
 
 - name: Create {{ smbd_share_path }}
   become: yes
diff --git a/playbooks/roles/volume_group/README.md b/playbooks/roles/volume_group/README.md
new file mode 100644
index 000000000000..56cb7c55f9f4
--- /dev/null
+++ b/playbooks/roles/volume_group/README.md
@@ -0,0 +1,48 @@ 
+volume_group
+============
+
+The volume_group playbook creates a logical volume group
+on a target node using unused block devices.
+
+Requirements
+------------
+
+The ansible community.general collection must be installed on the
+control host.
+
+Role Variables
+--------------
+
+  * volume_group_name: The name for new volume group (string)
+  * volume_device_prefix: The pathname prefix for block devices to
+    consider for the new volume group (string)
+  * volume_device_count: The number of block devices to include in
+    the new volume group (int)
+
+Dependencies
+------------
+
+None.
+
+Example Playbook
+----------------
+
+Below is an example playbook task:
+
+```
+- name: Create a volume group for NFSD exports
+  ansible.builtin.include_role:
+    name: volume_group
+  vars:
+    volume_group_name: "exports"
+    volume_device_prefix: "/dev/disk/by-id/virtio*"
+    volume_count: 3
+```
+
+For further examples refer to one of this role's users, the
+[https://github.com/linux-kdevops/kdevops](kdevops) project.
+
+License
+-------
+
+copyleft-next-0.3.1
diff --git a/playbooks/roles/volume_group/defaults/main.yml b/playbooks/roles/volume_group/defaults/main.yml
new file mode 100644
index 000000000000..68f3fb3f5775
--- /dev/null
+++ b/playbooks/roles/volume_group/defaults/main.yml
@@ -0,0 +1,2 @@ 
+---
+physical_volumes: []
diff --git a/playbooks/roles/volume_group/tasks/main.yml b/playbooks/roles/volume_group/tasks/main.yml
new file mode 100644
index 000000000000..086c86454893
--- /dev/null
+++ b/playbooks/roles/volume_group/tasks/main.yml
@@ -0,0 +1,31 @@ 
+---
+- name: Gather hardware facts
+  ansible.builtin.gather_facts:
+    gather_subset:
+      - "!all"
+      - "!min"
+      - "hardware"
+
+- name: Install dependencies for LVM support
+  become: true
+  become_flags: 'su - -c'
+  become_method: ansible.builtin.sudo
+  ansible.builtin.package:
+    name:
+      - lvm2
+    state: present
+
+- name: Enumerate block devices to provision as physical volumes
+  ansible.builtin.set_fact:
+    physical_volumes: "{{ physical_volumes + [volume_device_prefix + item | string] }}"
+  with_items: "{{ range(1, volume_device_count + 1) }}"
+  loop_control:
+    label: "Block device: {{ volume_device_prefix + item | string }}"
+
+- name: Create an LVM Volume Group
+  become: true
+  become_flags: "su - -c"
+  become_method: ansible.builtin.sudo
+  community.general.lvg:
+    vg: "{{ volume_group_name }}"
+    pvs: "{{ physical_volumes | join(',') }}"