I am using RHEL v8.10 and I have written ansible playbook to partition disk /dev/sda3 created, logical volume vg-system-home and vg-system-var which i wanted to extend to 100G and 20G but since this two are mounted already .
Either I am unmount them it gives resource busy or trying to extend the disk or remove this native volume manager and add the new volume home and mount on the /etc/fstab is not working . I appreciate your immediate help or guidance to fix this issue.
---
hosts: all
vars:
extra_volumes: "true"
logical_volumes:
- name: home
size: "100G"
mount_path: "/home"
vgroup: "system"
fstype: "ext4"
- name: var
size: "7G"
mount_path: "/var"
vgroup: "system"
fstype: "ext4"
- name: opt
size: "1G"
mount_path: "/opt"
vgroup: "system"
fstype: "ext4"
- name: opt_ibm
size: "20G"
mount_path: "/opt/ibm"
vgroup: "system"
fstype: "ext4"
tasks:
- name: "Get machine facts"
ansible.builtin.setup:
register: machine_facts
- name: "Set the variable start_4th_partition"
ansible.builtin.set_fact:
start_4th_partition: "{{ (machine_facts.ansible_facts.ansible_devices['sda'].partitions['sda3'].start|int + machine_facts.ansible_facts.ansible_devices['sda'].partitions['sda3'].sectors|int + 200)|int }}"
- name: "Create partition"
become: true
parted: # community.general.parted does not work in Ansible 2.9
device: /dev/sda
state: present
number: 4
unit: "s"
part_start: "{{ start_4th_partition|int }}s"
part_end: "100%"
label: "gpt"
when: extra_volumes is defined
- name: "Update the volume group (adding new partition)"
become: true
lvg: # community.general.lvg does not work in Ansible 2.9
vg: system
pvs: /dev/sda4
when: extra_volumes is defined
- name: "Ensure the correct capacity for logical volume"
become: true
lvol: # community.general.lvol does not work in Ansible 2.9
vg: "{{ item.vgroup }}"
lv: "{{
item.name }}"
size: "{{ item.size }}"
resizefs: true
force: true
loop: "{{ logical_volumes }}"
when: extra_volumes is defined
- name: Create or resize a volume group on top of /dev/sdb1 and /dev/sdc5.
community.general.lvg:
vg: vg.services
pvs: /dev/sda3,/dev/sda4
- name: "Resize ext4 var Filesystem on logical volume"
become: true
filesystem: # community.general.filesystem does not work in Ansible 2.9
dev: "/dev/system/home"
fstype: "ext4"
resizefs: true
when: extra_volumes is defined
- name: "Ensure Logical Volume is mounted"
become: true
mount: # ansible.posix.mount does not work in Ansible 2.9
path: "{{ item.mount_path }}"
src: "/dev/{{ item.vgroup }}/{{
item.name }}"
fstype: "{{ item.fstype }}"
opts: "{{ item.opts | default('noatime') }}"
state: mounted
loop: "{{ logical_volumes }}"
when: extra_volumes is defined
notify: reboot-vm