mirror of
https://github.com/mrlesmithjr/ansible-manage-lvm.git
synced 2026-09-06 23:48:12 +03:00
Compare commits
18 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 26246c7160 | |||
| 5540f7fda5 | |||
| 433b7ca1a9 | |||
| 9404a780c5 | |||
| c0184492d5 | |||
| 60e08852ea | |||
| 42cc915582 | |||
| 49edca9134 | |||
| ee1e3d051b | |||
| 91f8cfca5d | |||
| 3ac9669088 | |||
| 4219da5423 | |||
| 683c617265 | |||
| b41ffc5e58 | |||
| 564d3d1f6f | |||
| 1d0fa70d66 | |||
| 8c3bca39ec | |||
| 4fbcf1cd19 |
+3
-4
@@ -9,6 +9,8 @@ lvm_groups: []
|
|||||||
# # defines if VG should exist or be removed
|
# # defines if VG should exist or be removed
|
||||||
# # true or false
|
# # true or false
|
||||||
# create: true
|
# create: true
|
||||||
|
# # defines if PV should be resized to max size
|
||||||
|
# pvresize: false
|
||||||
# lvnames:
|
# lvnames:
|
||||||
# - lvname: swap_1
|
# - lvname: swap_1
|
||||||
# # Define size of lvol
|
# # Define size of lvol
|
||||||
@@ -86,8 +88,5 @@ ebsnvme_binary_helper_path: '/sbin/go-ebsnvme'
|
|||||||
### nvme to scsi device name map script helper
|
### nvme to scsi device name map script helper
|
||||||
ebsnvme_scrip_helper_path: '/usr/local/bin/ebsnvme-id'
|
ebsnvme_scrip_helper_path: '/usr/local/bin/ebsnvme-id'
|
||||||
|
|
||||||
### auto pvresize (waiting until ansible 2.10 or above as collections have new lvg with integrated pvresize)
|
### resize all pv's to max size
|
||||||
### waiting for new module in collection set to true or run pvresize manually on remote systems
|
|
||||||
### https://docs.ansible.com/ansible/3/collections/community/general/lvg_module.html
|
|
||||||
###
|
|
||||||
pvresize_to_max: false
|
pvresize_to_max: false
|
||||||
|
|||||||
@@ -1 +0,0 @@
|
|||||||
../default/tests
|
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
"""PyTest Fixtures."""
|
||||||
|
from __future__ import absolute_import
|
||||||
|
import os
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
|
||||||
|
def pytest_runtest_setup(item):
|
||||||
|
"""Run tests only when under molecule with testinfra installed."""
|
||||||
|
try:
|
||||||
|
import testinfra
|
||||||
|
except ImportError:
|
||||||
|
pytest.skip("Test requires testinfra", allow_module_level=True)
|
||||||
|
if "MOLECULE_INVENTORY_FILE" in os.environ:
|
||||||
|
pytest.testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
|
||||||
|
os.environ["MOLECULE_INVENTORY_FILE"]
|
||||||
|
).get_hosts("all")
|
||||||
|
else:
|
||||||
|
pytest.skip(
|
||||||
|
"Test should run only from inside molecule.", allow_module_level=True
|
||||||
|
)
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
"""Role testing files using testinfra."""
|
||||||
|
|
||||||
|
|
||||||
|
def test_lvm_package_shall_be_installed(host):
|
||||||
|
assert host.package("lvm2").is_installed
|
||||||
|
|
||||||
|
|
||||||
|
def test_non_persistent_volume_group_is_created(host):
|
||||||
|
command = """sudo vgdisplay | grep -c 'my_vg'"""
|
||||||
|
cmd = host.run(command)
|
||||||
|
assert "1" in cmd.stdout
|
||||||
|
|
||||||
|
|
||||||
|
def test_mylv_logical_volume_is_created(host):
|
||||||
|
command = """sudo lvs -o lv_name my_vg --separator='|' --noheadings \
|
||||||
|
| grep -c 'my_lv'"""
|
||||||
|
cmd = host.run(command)
|
||||||
|
assert int(cmd.stdout.rstrip()) >= 1
|
||||||
|
|
||||||
|
|
||||||
|
def test_mylv_logical_volume2_is_created(host):
|
||||||
|
command = """sudo lvs -o lv_name my_vg --separator='|' --noheadings \
|
||||||
|
| grep -c 'my_lw'"""
|
||||||
|
cmd = host.run(command)
|
||||||
|
assert int(cmd.stdout.rstrip()) >= 1
|
||||||
|
|
||||||
|
|
||||||
|
def test_volume_is_mounted(host):
|
||||||
|
host.file("/var/lib/mountpoint").mode == 0o731
|
||||||
|
|
||||||
|
|
||||||
|
def test_volume2_is_mounted(host):
|
||||||
|
host.file("/var/lib/mountpoint2").mode == 0o731
|
||||||
@@ -1 +0,0 @@
|
|||||||
../../default/tests/conftest.py
|
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
"""PyTest Fixtures."""
|
||||||
|
from __future__ import absolute_import
|
||||||
|
import os
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
|
||||||
|
def pytest_runtest_setup(item):
|
||||||
|
"""Run tests only when under molecule with testinfra installed."""
|
||||||
|
try:
|
||||||
|
import testinfra
|
||||||
|
except ImportError:
|
||||||
|
pytest.skip("Test requires testinfra", allow_module_level=True)
|
||||||
|
if "MOLECULE_INVENTORY_FILE" in os.environ:
|
||||||
|
pytest.testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
|
||||||
|
os.environ["MOLECULE_INVENTORY_FILE"]
|
||||||
|
).get_hosts("all")
|
||||||
|
else:
|
||||||
|
pytest.skip(
|
||||||
|
"Test should run only from inside molecule.", allow_module_level=True
|
||||||
|
)
|
||||||
@@ -1 +0,0 @@
|
|||||||
../../default/tests/conftest.py
|
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
"""PyTest Fixtures."""
|
||||||
|
from __future__ import absolute_import
|
||||||
|
import os
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
|
||||||
|
def pytest_runtest_setup(item):
|
||||||
|
"""Run tests only when under molecule with testinfra installed."""
|
||||||
|
try:
|
||||||
|
import testinfra
|
||||||
|
except ImportError:
|
||||||
|
pytest.skip("Test requires testinfra", allow_module_level=True)
|
||||||
|
if "MOLECULE_INVENTORY_FILE" in os.environ:
|
||||||
|
pytest.testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
|
||||||
|
os.environ["MOLECULE_INVENTORY_FILE"]
|
||||||
|
).get_hosts("all")
|
||||||
|
else:
|
||||||
|
pytest.skip(
|
||||||
|
"Test should run only from inside molecule.", allow_module_level=True
|
||||||
|
)
|
||||||
Generated
+841
-874
File diff suppressed because it is too large
Load Diff
+1
-1
@@ -6,7 +6,7 @@ authors = ["Larry Smith Jr. <mrlesmithjr@gmail.com>"]
|
|||||||
|
|
||||||
[tool.poetry.dependencies]
|
[tool.poetry.dependencies]
|
||||||
python = ">=3.9,<4.0"
|
python = ">=3.9,<4.0"
|
||||||
ansible = "6.6.0"
|
ansible = "8.5.0"
|
||||||
|
|
||||||
[tool.poetry.group.dev.dependencies]
|
[tool.poetry.group.dev.dependencies]
|
||||||
ansible-lint = "6.8.7"
|
ansible-lint = "6.8.7"
|
||||||
|
|||||||
+2
-2
@@ -30,7 +30,7 @@
|
|||||||
- lv.filesystem != "swap"
|
- lv.filesystem != "swap"
|
||||||
|
|
||||||
- name: create_fs | creating new filesystem on new LVM logical volume(s)
|
- name: create_fs | creating new filesystem on new LVM logical volume(s)
|
||||||
community.general.system.filesystem:
|
community.general.filesystem:
|
||||||
fstype: "{{ lv.filesystem }}"
|
fstype: "{{ lv.filesystem }}"
|
||||||
dev: "/dev/{{ vg.vgname }}/{{ lv.lvname }}"
|
dev: "/dev/{{ vg.vgname }}/{{ lv.lvname }}"
|
||||||
resizefs: yes
|
resizefs: yes
|
||||||
@@ -48,7 +48,7 @@
|
|||||||
- lv.filesystem != 'xfs'
|
- lv.filesystem != 'xfs'
|
||||||
|
|
||||||
- name: create_fs | creating new xfs filesystem on new LVM logical volume(s)
|
- name: create_fs | creating new xfs filesystem on new LVM logical volume(s)
|
||||||
community.general.system.filesystem:
|
community.general.filesystem:
|
||||||
fstype: "{{ lv.filesystem }}"
|
fstype: "{{ lv.filesystem }}"
|
||||||
dev: "/dev/{{ vg.vgname }}/{{ lv.lvname }}"
|
dev: "/dev/{{ vg.vgname }}/{{ lv.lvname }}"
|
||||||
opts: "{{ lv.fsopts | default(omit) }}"
|
opts: "{{ lv.fsopts | default(omit) }}"
|
||||||
|
|||||||
+1
-1
@@ -5,7 +5,7 @@
|
|||||||
verbosity: 2
|
verbosity: 2
|
||||||
|
|
||||||
- name: create_lv | creating new LVM logical volume(s)
|
- name: create_lv | creating new LVM logical volume(s)
|
||||||
community.general.system.lvol:
|
community.general.lvol:
|
||||||
vg: "{{ vg.vgname }}"
|
vg: "{{ vg.vgname }}"
|
||||||
lv: "{{ lv.lvname }}"
|
lv: "{{ lv.lvname }}"
|
||||||
size: "{{ lv.size }}"
|
size: "{{ lv.size }}"
|
||||||
|
|||||||
+2
-14
@@ -1,27 +1,15 @@
|
|||||||
---
|
---
|
||||||
- name: create_vg | creating new LVM volume group(s)
|
- name: create_vg | creating new LVM volume group(s)
|
||||||
community.general.system.lvg:
|
community.general.lvg:
|
||||||
vg: "{{ vg.vgname }}"
|
vg: "{{ vg.vgname }}"
|
||||||
pvs: "{{ vg.disks | join(',') }}"
|
pvs: "{{ vg.disks | join(',') }}"
|
||||||
state: present
|
state: present
|
||||||
|
pvresize: "{{ vg.pvresize | default(pvresize_to_max) }}"
|
||||||
become: true
|
become: true
|
||||||
when:
|
when:
|
||||||
- vg.create is defined
|
- vg.create is defined
|
||||||
- vg.create|bool
|
- vg.create|bool
|
||||||
|
|
||||||
### workaround: auto pvresize waiting for upgrade to new module supporting integrated pvresize
|
|
||||||
### ref: https://docs.ansible.com/ansible/3/collections/community/general/lvg_module.html
|
|
||||||
- name: create_vg | pvresize to max available free space
|
|
||||||
ansible.builtin.command: "pvresize {{ pv }}"
|
|
||||||
loop: "{{ vg.disks | default([]) }}"
|
|
||||||
loop_control:
|
|
||||||
loop_var: pv
|
|
||||||
changed_when: false
|
|
||||||
when:
|
|
||||||
- vg.create is defined
|
|
||||||
- vg.create|bool
|
|
||||||
- pvresize_to_max|bool
|
|
||||||
|
|
||||||
- name: manage_lvm | loop over logical volume group(s) to create logical volumes
|
- name: manage_lvm | loop over logical volume group(s) to create logical volumes
|
||||||
ansible.builtin.include_tasks: create_lv.yml
|
ansible.builtin.include_tasks: create_lv.yml
|
||||||
loop: "{{ vg.lvnames | default([]) }}"
|
loop: "{{ vg.lvnames | default([]) }}"
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
loop_var: vg
|
loop_var: vg
|
||||||
|
|
||||||
- name: manage_lvm | Removing LVM logical volume(s)
|
- name: manage_lvm | Removing LVM logical volume(s)
|
||||||
community.general.system.lvol:
|
community.general.lvol:
|
||||||
vg: "{{ item.0.vgname }}"
|
vg: "{{ item.0.vgname }}"
|
||||||
lv: "{{ item.1.lvname }}"
|
lv: "{{ item.1.lvname }}"
|
||||||
state: absent
|
state: absent
|
||||||
@@ -20,7 +20,7 @@
|
|||||||
- not item.1.create|bool
|
- not item.1.create|bool
|
||||||
|
|
||||||
- name: manage_lvm | Removing LVM volume group(s)
|
- name: manage_lvm | Removing LVM volume group(s)
|
||||||
community.general.system.lvg:
|
community.general.lvg:
|
||||||
vg: "{{ item.vgname }}"
|
vg: "{{ item.vgname }}"
|
||||||
pvs: "{{ item.disks | join(',') }}"
|
pvs: "{{ item.disks | join(',') }}"
|
||||||
state: absent
|
state: absent
|
||||||
|
|||||||
Reference in New Issue
Block a user