Create a Logical Volume on Linux with Ansible or AAP

Mindwatering Incorporated

Author: Tripp W Black

Created: 12/03 at 11:33 AM

 

Category:
Linux
RH AAP

Task:
Create a logical volume via Ansible/AAP.

Notes:
- The lvol module is in the community.general collection.
- The active parameter is true, active and visible, by default, to the host.
- The resizefs expansion is supported for ext3, ext4, XFS, and a couple others.
- If shrinking a LV, ensure there is enough free space, and include the force parameter.
- Use thinpool paramter if using a thin provisioned volue.
- vg: volume group to use
- lv: logical volume name of the new LV to create
- size: the disk space, in MBs, by default, to give the new LV
- pvs: the physical disk volume(s) to span the LV across


Examples:
Code snippet 1:
- name: Create a logical volume of 8 GB within the volume group apps for the Domino app
community.general.lvol:
vg: apps
lv: notesdata
size: 8192


Code snippet 2:
- name: Create a logical volume using all space within the volume group apps for the Domino app
community.general.lvol:
vg: apps
lv: notesdata
size: 100%FREE


Code snippet 3:
- name: Extend an existing logical volume notesdata to consume all remaining space in a volume group
vg: apps
lv: notesdata
size: +100%FREE


Code snippet 4:
- name: Create a logic volume of 16 GB using physical disks/volumes
vg: apps
lv: notesdata
size: 16384
pvs:
- /dev/sdb
- /dev/sdc


Code snippet 5:
- name: Reduce an existing logic volume of 16 GB to 8 GB
vg: apps
lv: notesdata
size: 8192
force: true


Code snippet 6:
- name: Remove a notesdata logical volume from a volume group
vg: apps
lv: notesdata
state: absent
force: true


Code snippet 7:
---
- name:
block:
- name: Create a logical volume using passed item
lvol: "{{ item.vg_name }}"
vg: "{{ item.lv_name }}"
size: "{{ item.lv_size }}"

- name: Create a filesystem in new logical volume
filesystem:
fstype: "{{ item.lv_fstype }}"
dev: "{{ item.device }}"

- name: Create mount point directory
file:
path: "{{ item.path }}"
state: directory
mode: 0775
owner: "{{ item.owner }}"
group: "{{ item.owner }}"
recurse: true

- name: Mount the logical volume to the directory
mount:
backup: true
path: "{{ item.path }}"
src: "{{ item.device }}"
fstype: "{{ item.lv_fstype }}"
opts: defaults
state: mounted

rescue:
- name: Logical volume item failed
fail:
msg:
- "ERROR occurred in role_appname, playbook: appdata_lv.yaml"
- "Failed task: {{ ansible_failed_task.name }}"
- "Failure error message: {{ ansible_failed_result.msg }}"




previous page

×