Clean FS, LV, VG and PSs before run

This commit is contained in:
Klention Mali 2025-07-19 15:05:05 +02:00
commit 08b654f48b
No known key found for this signature in database
GPG key ID: 777C0B2D8F048DAB
5 changed files with 74 additions and 21 deletions

View file

@ -13,6 +13,14 @@
community.general.filesystem: community.general.filesystem:
dev: /dev/vg_tmp_test/lv_tmp_test dev: /dev/vg_tmp_test/lv_tmp_test
state: absent state: absent
force: true
- name: Deleting testlv logical volume
community.general.lvol:
vg: testvg
lv: testlv
force: true
state: absent
- name: Detaching first loop device - name: Detaching first loop device
ansible.builtin.command: losetup -d {{ loop_device_01.stdout }} ansible.builtin.command: losetup -d {{ loop_device_01.stdout }}

View file

@ -13,28 +13,39 @@
args: args:
creates: "{{ remote_tmp_dir }}/test_lvm_pv_02.img" creates: "{{ remote_tmp_dir }}/test_lvm_pv_02.img"
- name: Pausing for a random time between 5-15 seconds
ansible.builtin.pause:
seconds: "{{ range(5, 16) | random }}"
- name: Creating loop device - name: Creating loop device
ansible.builtin.command: losetup -f ansible.builtin.command: losetup -f
register: loop_device_01 register: loop_device_01
- name: Wiping existing LVM metadata
community.general.lvm_pv:
device: "{{ loop_device_01.stdout }}"
force: true
state: absent
- name: Associating loop device with file - name: Associating loop device with file
ansible.builtin.command: 'losetup {{ loop_device_01.stdout }} {{ remote_tmp_dir }}/test_lvm_pv_01.img' ansible.builtin.command: 'losetup {{ loop_device_01.stdout }} {{ remote_tmp_dir }}/test_lvm_pv_01.img'
- name: Pausing for a random time between 5-15 seconds
ansible.builtin.pause:
seconds: "{{ range(5, 16) | random }}"
- name: Creating loop device - name: Creating loop device
ansible.builtin.command: losetup -f ansible.builtin.command: losetup -f
register: loop_device_02 register: loop_device_02
- name: Associating loop device with file
ansible.builtin.command: 'losetup {{ loop_device_02.stdout }} {{ remote_tmp_dir }}/test_lvm_pv_02.img'
- name: Wiping existing LVM metadata - name: Wiping existing LVM metadata
community.general.lvm_pv: community.general.lvm_pv:
device: "{{ item }}" device: "{{ loop_device_02.stdout }}"
force: true force: true
state: absent state: absent
loop:
- "{{ loop_device_01.stdout }}" - name: Associating loop device with file
- "{{ loop_device_02.stdout }}" ansible.builtin.command: 'losetup {{ loop_device_02.stdout }} {{ remote_tmp_dir }}/test_lvm_pv_02.img'
- name: Creating physical volume for the first loop device - name: Creating physical volume for the first loop device
community.general.lvm_pv: community.general.lvm_pv:
@ -54,10 +65,12 @@
ansible.builtin.command: pvs --noheadings -o pv_size --units M {{ loop_device_02.stdout }} ansible.builtin.command: pvs --noheadings -o pv_size --units M {{ loop_device_02.stdout }}
register: pv_size_output_02 register: pv_size_output_02
- name: Creating volume group on top of first device {{ loop_device_01.stdout }} - name: Creating volume group
community.general.lvg: community.general.lvg:
vg: testvg vg: testvg
pvs: "{{ loop_device_01.stdout }}" pvs:
- "{{ loop_device_01.stdout }}"
- "{{ loop_device_02.stdout }}"
force: true force: true
register: vg_creation_result register: vg_creation_result
@ -88,9 +101,9 @@
- name: Asserting physical volume was created - name: Asserting physical volume was created
ansible.builtin.assert: ansible.builtin.assert:
that: that:
- pv_creation_result_01.changed == true - pv_creation_result_01 is changed
- pv_creation_result_02.changed == true - pv_creation_result_02 is changed
- vg_creation_result.changed == true - vg_creation_result is changed
- (pv_size_output_01.stdout | trim | regex_replace('M', '') | float) > 450 - (pv_size_output_01.stdout | trim | regex_replace('M', '') | float) > 450
- (pv_size_output_01.stdout | trim | regex_replace('M', '') | float) < 600 - (pv_size_output_01.stdout | trim | regex_replace('M', '') | float) < 600
- (pv_size_output_02.stdout | trim | regex_replace('M', '') | float) > 950 - (pv_size_output_02.stdout | trim | regex_replace('M', '') | float) > 950

View file

@ -12,11 +12,15 @@
- name: Install required packages (Linux) - name: Install required packages (Linux)
when: ansible_system == 'Linux' when: ansible_system == 'Linux'
ansible.builtin.package: ansible.builtin.package:
name: lvm2 name:
- lvm2
- xfsprogs
state: present state: present
- name: Testing lvm_pv_move_data module - name: Testing lvm_pv_move_data module
block: block:
- import_tasks: prepare.yml
- import_tasks: creation.yml - import_tasks: creation.yml
- import_tasks: moving.yml - import_tasks: moving.yml

View file

@ -8,13 +8,18 @@
args: args:
creates: "{{ remote_tmp_dir }}/tmp_mount/test_file" creates: "{{ remote_tmp_dir }}/tmp_mount/test_file"
- name: Extending VG testvg with second device {{ loop_device_02.stdout }} - name: Growing the second loop device file to 1500MB
community.general.lvg: ansible.builtin.shell: truncate -s 1500M {{ remote_tmp_dir }}/test_lvm_pv_02.img
vg: testvg
pvs: "{{ loop_device_02.stdout }}"
force: true
- name: Moving data from {{ loop_device_01.stdout }} to {{ loop_device_02.stdout }} (both in same VG) - name: Refreshing the second loop device
ansible.builtin.shell: losetup -c {{ loop_device_02.stdout }}
- name: Resizing the second physical volume
community.general.lvm_pv:
device: "{{ loop_device_02.stdout }}"
resize: true
- name: Moving data from between PVs (both in same VG)
community.general.lvm_pv_move_data: community.general.lvm_pv_move_data:
source: "{{ loop_device_01.stdout }}" source: "{{ loop_device_01.stdout }}"
destination: "{{ loop_device_02.stdout }}" destination: "{{ loop_device_02.stdout }}"
@ -27,5 +32,5 @@
- name: Asserting data was moved successfully - name: Asserting data was moved successfully
ansible.builtin.assert: ansible.builtin.assert:
that: that:
- move_result.changed == true - move_result is changed
- "'moved data from' in creation_result.msg" - "'moved data from' in move_result.msg"

View file

@ -0,0 +1,23 @@
---
# 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
- name: Removing xfs filesystem from LV lv_tmp_test
community.general.filesystem:
dev: /dev/vg_tmp_test/lv_tmp_test
state: absent
force: true
- name: Deleting testlv logical volume
community.general.lvol:
vg: testvg
lv: testlv
force: true
state: absent
- name: Deleting volume group testvg
community.general.lvg:
vg: testvg
force: true
state: absent