Skip to content

Commit 32fe1c3

Browse files
committed
Adding LVM configuration management
Ensures that only current or configured volumes are visible on the host. Once VMs utilize lvm and for example iSCSI block devices are used, the host can accidentially scan VM PVs and destroy exclusive device access. This typically prevents live migration if not otherwise prohibited by lvm filters.
1 parent 39dda11 commit 32fe1c3

File tree

5 files changed

+175
-0
lines changed

5 files changed

+175
-0
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
---
2+
# Copyright 2025, Rackspace Technology, Inc.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
- name: Discover current pv devices
17+
ansible.builtin.shell: |
18+
set -o pipefail
19+
/sbin/pvdisplay | awk '/PV\ Name/ {print $3}' | sed 's/\/dev\///g'
20+
args:
21+
executable: /bin/bash
22+
register: lvm_devices
23+
changed_when: lvm_devices.rc != 0
24+
failed_when: false
25+
26+
- name: Ensure "/etc/lvm" directory
27+
ansible.builtin.file:
28+
state: "directory"
29+
path: "/etc/lvm"
30+
mode: "0755"
31+
when: lvm_devices.rc == 0
32+
33+
- name: Update lvm.conf
34+
ansible.builtin.template:
35+
src: "lvm.conf.j2"
36+
dest: "/etc/lvm/lvm.conf"
37+
owner: "root"
38+
group: "root"
39+
backup: "yes"
40+
mode: "0644"
41+
when: lvm_devices.rc == 0

ansible/roles/host_setup/tasks/main.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,5 +165,8 @@
165165
- name: Configure custom multipath.conf
166166
ansible.builtin.include_tasks: custom_multipath.yml
167167

168+
- name: Configure custom lvm.conf
169+
ansible.builtin.include_tasks: lvm_config.yml
170+
168171
- name: Install RAID controller CLI tools
169172
ansible.builtin.include_tasks: raid_cli_tools.yml
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
# {{ ansible_managed }}
2+
3+
{% set used_lvm_devices = [] %}
4+
{% if host_lvm_devices_filter_override|length > 0 %}
5+
{% set used_lvm_devices = host_lvm_devices_filter_override %}
6+
{% else %}
7+
{% set lv_devices = lvm_devices.stdout.split('\n') %}
8+
{% if lv_devices|length > 0 %}
9+
{% for net in lv_devices %}
10+
{% if net != '' %}
11+
{% set lv_device = '"a/' + net + '/"' %}
12+
{% if used_lvm_devices.append(lv_device) %}{% endif %}
13+
{% endif %}
14+
{% endfor %}
15+
{% endif %}
16+
17+
# Ansible Discovered LVM Devices {{ lv_devices }}
18+
{% endif %}
19+
20+
{% if used_lvm_devices|length <= 0 %}
21+
{# If there are no LVM devices present, allow all devices to be scanned #}
22+
{% if used_lvm_devices.append('"a/.*/"') %}{% endif %}
23+
{% else %}
24+
{# Append 'loop.*' to the list to help with AIO deployments. #}
25+
{% if used_lvm_devices.append('"a/loop.*/"') %}{% endif %}
26+
{# Disable scanning any other devices than the ones listed. #}
27+
{% if used_lvm_devices.append('"r/.*/"') %}{% endif %}
28+
{% endif %}
29+
30+
devices {
31+
dir = "/dev"
32+
scan = [ "/dev" ]
33+
obtain_device_list_from_udev = 1
34+
preferred_names = [ ]
35+
filter = [ {{ used_lvm_devices|join(', ') }} ]
36+
cache_dir = "/run/lvm"
37+
cache_file_prefix = ""
38+
write_cache_state = 1
39+
sysfs_scan = 1
40+
multipath_component_detection = 1
41+
md_component_detection = 1
42+
md_chunk_alignment = 1
43+
data_alignment_detection = 1
44+
data_alignment = 0
45+
data_alignment_offset_detection = 1
46+
ignore_suspended_devices = 0
47+
disable_after_error_count = 0
48+
require_restorefile_with_uuid = 1
49+
pv_min_size = 2048
50+
issue_discards = 1
51+
}
52+
allocation {
53+
maximise_cling = 1
54+
mirror_logs_require_separate_pvs = 0
55+
thin_pool_metadata_require_separate_pvs = 0
56+
}
57+
log {
58+
verbose = 0
59+
silent = 0
60+
syslog = 1
61+
overwrite = 0
62+
level = 0
63+
indent = 1
64+
command_names = 0
65+
prefix = " "
66+
}
67+
backup {
68+
backup = 1
69+
backup_dir = "/etc/lvm/backup"
70+
archive = 1
71+
archive_dir = "/etc/lvm/archive"
72+
retain_min = 10
73+
retain_days = 30
74+
}
75+
shell {
76+
history_size = 100
77+
}
78+
global {
79+
umask = 077
80+
test = 0
81+
units = "h"
82+
si_unit_consistency = 1
83+
activation = 1
84+
proc = "/proc"
85+
locking_type = 1
86+
wait_for_locks = 1
87+
fallback_to_clustered_locking = 1
88+
fallback_to_local_locking = 1
89+
locking_dir = "/run/lock/lvm"
90+
prioritise_write_locks = 1
91+
abort_on_internal_errors = 0
92+
detect_internal_vg_cache_corruption = 0
93+
metadata_read_only = 0
94+
mirror_segtype_default = "mirror"
95+
use_lvmetad = 0
96+
thin_check_executable = "/usr/sbin/thin_check"
97+
thin_check_options = [ "-q" ]
98+
}
99+
activation {
100+
checks = 0
101+
udev_sync = 1
102+
udev_rules = 1
103+
verify_udev_operations = 0
104+
retry_deactivation = 1
105+
missing_stripe_filler = "error"
106+
use_linear_target = 1
107+
reserved_stack = 64
108+
reserved_memory = 8192
109+
process_priority = -18
110+
mirror_region_size = 512
111+
readahead = "auto"
112+
raid_fault_policy = "warn"
113+
mirror_log_fault_policy = "allocate"
114+
mirror_image_fault_policy = "remove"
115+
snapshot_autoextend_threshold = 100
116+
snapshot_autoextend_percent = 20
117+
thin_pool_autoextend_threshold = 100
118+
thin_pool_autoextend_percent = 20
119+
use_mlockall = 0
120+
monitoring = 0
121+
polling_interval = 15
122+
}
123+
dmeventd {
124+
mirror_library = "libdevmapper-event-lvm2mirror.so"
125+
snapshot_library = "libdevmapper-event-lvm2snapshot.so"
126+
thin_library = "libdevmapper-event-lvm2thin.so"
127+
}

ansible/roles/host_setup/vars/debian.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,5 @@ _host_distro_packages:
6666
_hosts_package_list:
6767
- name: ca-certificates
6868
state: latest
69+
70+
host_lvm_devices_filter_override: []

ansible/roles/host_setup/vars/ubuntu.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,5 @@ _hosts_package_list:
6767
state: "{{ host_package_state }}"
6868
- name: ca-certificates
6969
state: latest
70+
71+
host_lvm_devices_filter_override: []

0 commit comments

Comments
 (0)