lvg: Add parameter to disable removal of extra physical volumes (#9698)
* Add parameter to disable removal of extra physical volumes Signed-off-by: Massl123 <Massl123@users.noreply.github.com> * Set PR number in changelog fragment Signed-off-by: Massl123 <Massl123@users.noreply.github.com> * Fix tests Signed-off-by: Massl123 <Massl123@users.noreply.github.com> * Apply suggestions from code review Co-authored-by: Felix Fontein <felix@fontein.de> * Add comment in pvs Signed-off-by: Massl123 <Massl123@users.noreply.github.com> --------- Signed-off-by: Massl123 <Massl123@users.noreply.github.com> Co-authored-by: Felix Fontein <felix@fontein.de>pull/9722/head
parent
165106d2bd
commit
1beee87961
|
@ -0,0 +1,2 @@
|
||||||
|
minor_changes:
|
||||||
|
- lvg - add ``remove_extra_pvs`` parameter to control if ansible should remove physical volumes which are not in the ``pvs`` parameter (https://github.com/ansible-collections/community.general/pull/9698).
|
|
@ -34,6 +34,7 @@ options:
|
||||||
- List of comma-separated devices to use as physical devices in this volume group.
|
- List of comma-separated devices to use as physical devices in this volume group.
|
||||||
- Required when creating or resizing volume group.
|
- Required when creating or resizing volume group.
|
||||||
- The module will take care of running pvcreate if needed.
|
- The module will take care of running pvcreate if needed.
|
||||||
|
- O(remove_extra_pvs) controls whether or not unspecified physical devices are removed from the volume group.
|
||||||
type: list
|
type: list
|
||||||
elements: str
|
elements: str
|
||||||
pesize:
|
pesize:
|
||||||
|
@ -88,6 +89,12 @@ options:
|
||||||
type: bool
|
type: bool
|
||||||
default: false
|
default: false
|
||||||
version_added: 7.1.0
|
version_added: 7.1.0
|
||||||
|
remove_extra_pvs:
|
||||||
|
description:
|
||||||
|
- Remove physical volumes from the volume group which are not in O(pvs).
|
||||||
|
type: bool
|
||||||
|
default: true
|
||||||
|
version_added: 10.4.0
|
||||||
seealso:
|
seealso:
|
||||||
- module: community.general.filesystem
|
- module: community.general.filesystem
|
||||||
- module: community.general.lvol
|
- module: community.general.lvol
|
||||||
|
@ -383,6 +390,7 @@ def main():
|
||||||
force=dict(type='bool', default=False),
|
force=dict(type='bool', default=False),
|
||||||
reset_vg_uuid=dict(type='bool', default=False),
|
reset_vg_uuid=dict(type='bool', default=False),
|
||||||
reset_pv_uuid=dict(type='bool', default=False),
|
reset_pv_uuid=dict(type='bool', default=False),
|
||||||
|
remove_extra_pvs=dict(type="bool", default=True),
|
||||||
),
|
),
|
||||||
required_if=[
|
required_if=[
|
||||||
['reset_pv_uuid', True, ['pvs']],
|
['reset_pv_uuid', True, ['pvs']],
|
||||||
|
@ -399,6 +407,7 @@ def main():
|
||||||
vgoptions = module.params['vg_options'].split()
|
vgoptions = module.params['vg_options'].split()
|
||||||
reset_vg_uuid = module.boolean(module.params['reset_vg_uuid'])
|
reset_vg_uuid = module.boolean(module.params['reset_vg_uuid'])
|
||||||
reset_pv_uuid = module.boolean(module.params['reset_pv_uuid'])
|
reset_pv_uuid = module.boolean(module.params['reset_pv_uuid'])
|
||||||
|
remove_extra_pvs = module.boolean(module.params["remove_extra_pvs"])
|
||||||
|
|
||||||
this_vg = find_vg(module=module, vg=vg)
|
this_vg = find_vg(module=module, vg=vg)
|
||||||
present_state = state in ['present', 'active', 'inactive']
|
present_state = state in ['present', 'active', 'inactive']
|
||||||
|
@ -494,6 +503,9 @@ def main():
|
||||||
devs_to_remove = list(set(current_devs) - set(dev_list))
|
devs_to_remove = list(set(current_devs) - set(dev_list))
|
||||||
devs_to_add = list(set(dev_list) - set(current_devs))
|
devs_to_add = list(set(dev_list) - set(current_devs))
|
||||||
|
|
||||||
|
if not remove_extra_pvs:
|
||||||
|
devs_to_remove = []
|
||||||
|
|
||||||
if current_devs:
|
if current_devs:
|
||||||
if present_state:
|
if present_state:
|
||||||
for device in current_devs:
|
for device in current_devs:
|
||||||
|
|
|
@ -24,6 +24,8 @@
|
||||||
|
|
||||||
- import_tasks: test_grow_reduce.yml
|
- import_tasks: test_grow_reduce.yml
|
||||||
|
|
||||||
|
- import_tasks: test_remove_extra_pvs.yml
|
||||||
|
|
||||||
- import_tasks: test_pvresize.yml
|
- import_tasks: test_pvresize.yml
|
||||||
|
|
||||||
- import_tasks: test_active_change.yml
|
- import_tasks: test_active_change.yml
|
||||||
|
|
|
@ -0,0 +1,40 @@
|
||||||
|
---
|
||||||
|
# Copyright (c) Ansible Project
|
||||||
|
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
# test_grow_reduce already checks the base case with default parameters (remove additional PVs)
|
||||||
|
|
||||||
|
- name: "Create volume group on first disk"
|
||||||
|
lvg:
|
||||||
|
vg: testvg
|
||||||
|
pvs: "{{ loop_device1 }}"
|
||||||
|
|
||||||
|
- name: "get lvm facts"
|
||||||
|
setup:
|
||||||
|
|
||||||
|
- debug: var=ansible_lvm
|
||||||
|
|
||||||
|
- name: "Assert the testvg span only on first disk"
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- ansible_lvm.pvs[loop_device1].vg == "testvg"
|
||||||
|
- 'loop_device2 not in ansible_lvm.pvs or
|
||||||
|
ansible_lvm.pvs[loop_device2].vg == ""'
|
||||||
|
|
||||||
|
- name: "Extend to second disk AND keep first disk"
|
||||||
|
lvg:
|
||||||
|
vg: testvg
|
||||||
|
pvs: "{{ loop_device2 }}"
|
||||||
|
remove_extra_pvs: false
|
||||||
|
|
||||||
|
- name: "get lvm facts"
|
||||||
|
setup:
|
||||||
|
|
||||||
|
- debug: var=ansible_lvm
|
||||||
|
|
||||||
|
- name: "Assert the testvg spans on both disks"
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- ansible_lvm.pvs[loop_device1].vg == "testvg"
|
||||||
|
- ansible_lvm.pvs[loop_device2].vg == "testvg"
|
Loading…
Reference in New Issue