Skip to main content

LVM Facts Overview

LVM Facts Overview

LVM Facts is a module that reports Logical Volume Manager (LVM) information as facts. It lists and reports details about defined AIX LVM components such as Physical Volumes (PVs), Logical Volumes (LVs), and Volume Groups (VGs). The module can specify the name of an LVM component and the type of LVM component to report information on, including PVs, LVs, VGs, or all components. Users can provide existing LVM facts to which the queried facts should be updated, or the LVM facts in the ansible_facts will be replaced. The module gathers information using commands like lsvg and lspv to retrieve details about VGs, PVs, and LVs. The gathered facts are then added to ansible_facts, providing a comprehensive overview of the LVM components on the system.

How to Use LVM Facts

This example shows how to gather all LVM facts, VG facts, update PV facts to existing LVM facts, and gather LV facts using the lvm_facts module.


The following code demonstrates how to gather all LVM facts, VG facts, update PV facts to existing LVM facts, and gather LV facts using the lvm_facts module.

- name: Gather all lvm facts
lvm_facts:
- name: Gather VG facts
lvm_facts:
name: all
component: vg
- name: Update PV facts to existing LVM facts
lvm_facts:
name: all
component: pv
lvm: "{{ ansible_facts.LVM }}"
- name: Gather LV facts
lvm_facts:
name: all
component: lv
'''

Main Functions

There are several main functions in this module. Some of them are load_pvs, parse_pvs, load_vgs, parse_vgs, load_lvs, and parse_lvs. We will dive a little into each of these functions.

load_pvs

The load_pvs function retrieves details for the specified Physical Volume (PV) or all PVs. It runs the lspv command to gather information and updates the LVM facts with the retrieved data.


The load_pvs function retrieves details for the specified Physical Volume (PV) or all PVs. It runs the lspv command to gather information and updates the LVM facts with the retrieved data.

def load_pvs(module, name, LVM):
"""
Get the details for the specified PV or all
arguments:
module (dict): Ansible module argument spec.
name (str): physical volume name.
LVM (dict): LVM facts.
return:
warnings (list): List of warning messages
LVM (dict): LVM facts
"""
warnings = []
cmd = "lspv"
rc, stdout, stderr = module.run_command(cmd)
if rc != 0:
warnings.append(
f"Command failed. cmd={cmd} rc={rc} stdout={stdout} stderr={stderr}")
else:
for ln in stdout.splitlines():
fields = ln.split()
pv = fields[0]

parse_pvs

The parse_pvs function parses the output of the lspv command for a specific PV. It extracts relevant data and formats it into a dictionary that is used to update the LVM facts.

load_vgs

The load_vgs function retrieves details for the specified Volume Group (VG) or all VGs. It runs the lsvg command to gather information and updates the LVM facts with the retrieved data.


The load_vgs function retrieves details for the specified Volume Group (VG) or all VGs. It runs the lsvg command to gather information and updates the LVM facts with the retrieved data.

def load_vgs(module, name, LVM):
"""
Get the details for the specified VG or all
arguments:
module (dict): Ansible module argument spec.
name (str): volume group name.
LVM (dict): LVM facts.
return:
warnings (list): List of warning messages
LVM (dict): LVM facts
"""
warnings = []
cmd = "lsvg"
rc, stdout, stderr = module.run_command(cmd)
if rc != 0:
warnings.append(f"Command failed. cmd={cmd} rc={rc} stdout={stdout} stderr={stderr}")
else:
for ln in stdout.splitlines():
vg = ln.split()[0].strip()
if (name != 'all' and name != vg):
continue

load_lvs

The load_lvs function retrieves details for the specified Logical Volume (LV) or all LVs. It runs the lsvg -l command to gather information and updates the LVM facts with the retrieved data.


The load_lvs function retrieves details for the specified Logical Volume (LV) or all LVs. It runs the lsvg -l command to gather information and updates the LVM facts with the retrieved data.

def load_lvs(module, name, LVM):
"""
Get the details for the specified LV or all
arguments:
module (dict): Ansible module argument spec.
name (str): logical volume name.
LVM (dict): LVM facts.
return:
warnings (list): List of warning messages
LVM (dict): LVM facts
"""
warnings = []
cmd = "lsvg"
rc, stdout, stderr = module.run_command(cmd)
if rc != 0:
warnings.append(f"Command failed. cmd={cmd} rc={rc} stdout={stdout} stderr={stderr}")
else:
for line in stdout.splitlines():
vg = line.split()[0].strip()
cmd = f"lsvg -l { vg }"
rc, stdout, stderr = module.run_command(cmd)

 

This is an auto-generated document by Swimm 🌊 and has not yet been verified by a human