mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-10-03 15:04:02 -07:00
lvm_pv_move_data: new module (#10416)
* Added lvm_pv_move_data module
* Removed trailing whitespace
* Decreased loop devices file size
* Remove test VG if exists
* Force remove test VG if exists
* Renamed test VG and LV names
* Updated assert conditions
* Added .ansible to .gitignore
* Force extending VG
* Wiping LVM metadata from PVs before creating VG
* Clean FS, LV, VG and PSs before run
* Migrated to CmdRunner
* Added more detailed info in case of failure and cosmetic changes
* Remove redundant params from CmdRunner call
* Updates the RETURN documentation block to properly specify the return type
of the 'actions' field:
- Changes return status from 'always' to 'success'
- Adds missing 'elements: str' type specification
(cherry picked from commit e91e2ef6f8
)
Co-authored-by: Klention Mali <45871249+klention@users.noreply.github.com>
115 lines
3.8 KiB
YAML
115 lines
3.8 KiB
YAML
---
|
|
# 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: Creating a 500MB file for the first loop device
|
|
ansible.builtin.command: dd if=/dev/zero of={{ remote_tmp_dir }}/test_lvm_pv_01.img bs=1M count=500
|
|
args:
|
|
creates: "{{ remote_tmp_dir }}/test_lvm_pv_01.img"
|
|
|
|
- name: Creating a 1000MB file for the second loop device
|
|
ansible.builtin.command: dd if=/dev/zero of={{ remote_tmp_dir }}/test_lvm_pv_02.img bs=1M count=1000
|
|
args:
|
|
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
|
|
ansible.builtin.command: losetup -f
|
|
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
|
|
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
|
|
ansible.builtin.command: losetup -f
|
|
register: loop_device_02
|
|
|
|
- name: Wiping existing LVM metadata
|
|
community.general.lvm_pv:
|
|
device: "{{ loop_device_02.stdout }}"
|
|
force: true
|
|
state: absent
|
|
|
|
- name: Associating loop device with file
|
|
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
|
|
community.general.lvm_pv:
|
|
device: "{{ loop_device_01.stdout }}"
|
|
register: pv_creation_result_01
|
|
|
|
- name: Checking the first physical volume size
|
|
ansible.builtin.command: pvs --noheadings -o pv_size --units M {{ loop_device_01.stdout }}
|
|
register: pv_size_output_01
|
|
|
|
- name: Creating physical volume for the second loop device
|
|
community.general.lvm_pv:
|
|
device: "{{ loop_device_02.stdout }}"
|
|
register: pv_creation_result_02
|
|
|
|
- name: Checking the second physical volume size
|
|
ansible.builtin.command: pvs --noheadings -o pv_size --units M {{ loop_device_02.stdout }}
|
|
register: pv_size_output_02
|
|
|
|
- name: Creating volume group
|
|
community.general.lvg:
|
|
vg: testvg
|
|
pvs:
|
|
- "{{ loop_device_01.stdout }}"
|
|
- "{{ loop_device_02.stdout }}"
|
|
force: true
|
|
register: vg_creation_result
|
|
|
|
- name: Creating LV testlv on VG testvg
|
|
community.general.lvol:
|
|
vg: testvg
|
|
lv: testlv
|
|
size: 100%FREE
|
|
force: true
|
|
register: lv_creation_result
|
|
|
|
- name: Creating xfs filesystem on LV testlv
|
|
community.general.filesystem:
|
|
dev: /dev/testvg/testlv
|
|
fstype: xfs
|
|
state: present
|
|
register: fs_creation_result
|
|
|
|
- name: Mounting LV testlv
|
|
ansible.posix.mount:
|
|
fstab: '{{ remote_tmp_dir }}/fstab'
|
|
path: '{{ remote_tmp_dir }}/tmp_mount'
|
|
src: '/dev/testvg/testlv'
|
|
fstype: xfs
|
|
opts: rw,noauto
|
|
state: mounted
|
|
register: mount_result
|
|
|
|
- name: Asserting PVs, VG, LV and filesystem were created successfully
|
|
ansible.builtin.assert:
|
|
that:
|
|
- pv_creation_result_01 is changed
|
|
- pv_creation_result_02 is changed
|
|
- vg_creation_result is changed
|
|
- lv_creation_result is changed
|
|
- fs_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) < 600
|
|
- (pv_size_output_02.stdout | trim | regex_replace('M', '') | float) > 950
|
|
- (pv_size_output_02.stdout | trim | regex_replace('M', '') | float) < 1100
|
|
- "'created' in pv_creation_result_01.msg"
|
|
- "'created' in pv_creation_result_02.msg"
|