mirror of
https://github.com/mrlesmithjr/ansible-manage-lvm.git
synced 2026-02-04 08:49:13 +03:00
Compare commits
166 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6d0feecec7 | ||
|
|
416e840eea | ||
|
|
850d571313 | ||
|
|
ff13947aaf | ||
|
|
26246c7160 | ||
|
|
5540f7fda5 | ||
|
|
433b7ca1a9 | ||
|
|
9404a780c5 | ||
|
|
c0184492d5 | ||
|
|
60e08852ea | ||
|
|
42cc915582 | ||
|
|
49edca9134 | ||
|
|
ee1e3d051b | ||
|
|
91f8cfca5d | ||
|
|
3ac9669088 | ||
|
|
4219da5423 | ||
|
|
683c617265 | ||
|
|
b41ffc5e58 | ||
|
|
564d3d1f6f | ||
|
|
1d0fa70d66 | ||
|
|
8c3bca39ec | ||
|
|
4fbcf1cd19 | ||
|
|
11056e2e60 | ||
|
|
220de2d8ac | ||
|
|
3f3a7c7334 | ||
|
|
f901fe42b3 | ||
|
|
d27a3809d9 | ||
|
|
51b7015f9c | ||
|
|
e35a250f7b | ||
|
|
de0507269b | ||
|
|
1b7e7e6b1c | ||
|
|
84ba07bcaf | ||
|
|
a623248cdf | ||
|
|
55b1745ac3 | ||
|
|
c020c6ef2d | ||
|
|
47c980797d | ||
|
|
d6dd5184f0 | ||
|
|
74e7ca5652 | ||
|
|
12346fa038 | ||
|
|
8dc044f7c2 | ||
|
|
aa66814872 | ||
|
|
6e4f217d74 | ||
|
|
483ed18874 | ||
|
|
ea2e60f043 | ||
|
|
a28791cc48 | ||
|
|
b5bf2d266c | ||
|
|
ca903442c8 | ||
|
|
9e69c74f71 | ||
|
|
e9ff7e3faf | ||
|
|
84bfdf54ad | ||
|
|
376f2ce641 | ||
|
|
6e74c9714e | ||
|
|
1f966d2ea1 | ||
|
|
71a3930e5b | ||
|
|
263c8d2b3f | ||
|
|
0bfd390ace | ||
|
|
71bc56d733 | ||
|
|
59ca2aae95 | ||
|
|
cb3a75c984 | ||
|
|
fae4332de8 | ||
|
|
3ea52cdda8 | ||
|
|
2d020f26d8 | ||
|
|
558cd7460e | ||
|
|
3b00335935 | ||
|
|
ac014a161e | ||
|
|
9446ef21d6 | ||
|
|
97300430ad | ||
|
|
73db3c747c | ||
|
|
73b6bce608 | ||
|
|
098bd79154 | ||
|
|
fddf9804dd | ||
|
|
506da4707e | ||
|
|
773ce28061 | ||
|
|
1bb56066fe | ||
|
|
cb792e59a6 | ||
|
|
48e3be3c5c | ||
|
|
2492c96566 | ||
|
|
e4bc8a9e9b | ||
|
|
1d57a469b0 | ||
|
|
19e56ac7d8 | ||
|
|
5c3e601078 | ||
|
|
535b410363 | ||
|
|
f87c42a8c5 | ||
|
|
34e4f08c31 | ||
|
|
f1a54639c6 | ||
|
|
88489df0ac | ||
|
|
b288695b9a | ||
|
|
ed0eb14ce8 | ||
|
|
9c04be9046 | ||
|
|
96fd3b2b06 | ||
|
|
15b2b7b4e0 | ||
|
|
9ead2c9b18 | ||
|
|
79f4787208 | ||
|
|
94582de25d | ||
|
|
6ee72799b4 | ||
|
|
69e25effd4 | ||
|
|
62fc5a5e2b | ||
|
|
c40f9b7d03 | ||
|
|
0621cadde8 | ||
|
|
b7cef8e323 | ||
|
|
59ffcfac4a | ||
|
|
976ff31d00 | ||
|
|
78205e51cb | ||
|
|
b731c20100 | ||
|
|
f2df804926 | ||
|
|
9f37fa3ed1 | ||
|
|
c9a9e1660e | ||
|
|
ec0737d26b | ||
|
|
52c0270a53 | ||
|
|
94be28c09b | ||
|
|
a6b07da847 | ||
|
|
643c7b6ee1 | ||
|
|
b7c3cf9f75 | ||
|
|
e423ebd56b | ||
|
|
9eca9e391b | ||
|
|
881d5d77fa | ||
|
|
89360e3ffe | ||
|
|
5267237c5e | ||
|
|
eda544042a | ||
|
|
c6a7034e4b | ||
|
|
1e997a3e80 | ||
|
|
816d44a6a1 | ||
|
|
883055c33f | ||
|
|
4697b37377 | ||
|
|
325c2d6240 | ||
|
|
7d3e90f9e8 | ||
|
|
db21878de4 | ||
|
|
4a1177e420 | ||
|
|
45315cf2df | ||
|
|
7fd5a8eec9 | ||
|
|
c17a76f9cb | ||
|
|
7e2a076b0a | ||
|
|
4267de6416 | ||
|
|
d3256a3a5a | ||
|
|
f1a9284396 | ||
|
|
dadb9f24f7 | ||
|
|
8666645760 | ||
|
|
2f63eab727 | ||
|
|
6c13d12494 | ||
|
|
050f8a56f1 | ||
|
|
dc1ad5a6f8 | ||
|
|
1a648317c7 | ||
|
|
b955a6f073 | ||
|
|
f81937e9d8 | ||
|
|
c3fea6e456 | ||
|
|
1c3818e5d0 | ||
|
|
12c4dad6e0 | ||
|
|
47f8dae16a | ||
|
|
96fa78d6d0 | ||
|
|
17e8ec1058 | ||
|
|
ba5d929fce | ||
|
|
ea9109220b | ||
|
|
fe860566ba | ||
|
|
d8b3a4e932 | ||
|
|
fc49e1d7b1 | ||
|
|
b15ecea51d | ||
|
|
092546c501 | ||
|
|
9788ee5df6 | ||
|
|
0f428a0e40 | ||
|
|
8957630c04 | ||
|
|
bd866078da | ||
|
|
183087e767 | ||
|
|
25dc548acb | ||
|
|
b3ef85d4f7 | ||
|
|
9f4afa7afb | ||
|
|
5603c5f6b0 |
3
.ansible-lint
Normal file
3
.ansible-lint
Normal file
@@ -0,0 +1,3 @@
|
||||
skip_list:
|
||||
- name[casing]
|
||||
- role-name
|
||||
14
.github/config.yml
vendored
Normal file
14
.github/config.yml
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
# Configuration for request-info - https://github.com/behaviorbot/request-info
|
||||
|
||||
# *Required* Comment to reply with
|
||||
requestInfoReplyComment: >
|
||||
We would appreciate it if you could provide us with more info about this issue/pr!
|
||||
|
||||
# *OPTIONAL* default titles to check against for lack of descriptiveness
|
||||
# MUST BE ALL LOWERCASE
|
||||
requestInfoDefaultTitles:
|
||||
- update readme.md
|
||||
- updates
|
||||
|
||||
# *OPTIONAL* Label to be added to Issues and Pull Requests with insufficient information given
|
||||
requestInfoLabelToAdd: needs-more-info
|
||||
32
.github/release-drafter.yml
vendored
Normal file
32
.github/release-drafter.yml
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
name-template: "v$RESOLVED_VERSION 🌈"
|
||||
tag-template: "v$RESOLVED_VERSION"
|
||||
categories:
|
||||
- title: "🚀 Features"
|
||||
labels:
|
||||
- "feature"
|
||||
- "enhancement"
|
||||
- title: "🐛 Bug Fixes"
|
||||
labels:
|
||||
- "fix"
|
||||
- "bugfix"
|
||||
- "bug"
|
||||
- title: "🧰 Maintenance"
|
||||
label: "chore"
|
||||
- title: "🧺 Miscellaneous" #Everything except ABAP
|
||||
label: "misc"
|
||||
change-template: "- $TITLE @$AUTHOR (#$NUMBER)"
|
||||
change-title-escapes: '\<*_&' # You can add # and @ to disable mentions, and add ` to disable code blocks.
|
||||
version-resolver:
|
||||
major:
|
||||
labels:
|
||||
- "major"
|
||||
minor:
|
||||
labels:
|
||||
- "minor"
|
||||
patch:
|
||||
labels:
|
||||
- "patch"
|
||||
default: patch
|
||||
template: |
|
||||
## Changes
|
||||
$CHANGES
|
||||
10
.github/settings.yml
vendored
Normal file
10
.github/settings.yml
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
# These settings are synced to GitHub by https://probot.github.io/apps/settings/
|
||||
|
||||
repository:
|
||||
# See https://developer.github.com/v3/repos/#edit for all available settings.
|
||||
|
||||
# The name of the repository. Changing this will rename the repository
|
||||
name: ansible-manage-lvm
|
||||
|
||||
# A short description of the repository that will show up on GitHub
|
||||
description: Ansible role to manage LVM Groups/Logical Volumes
|
||||
17
.github/stale.yml
vendored
Normal file
17
.github/stale.yml
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
# Number of days of inactivity before an issue becomes stale
|
||||
daysUntilStale: 60
|
||||
# Number of days of inactivity before a stale issue is closed
|
||||
daysUntilClose: 7
|
||||
# Issues with these labels will never be considered stale
|
||||
exemptLabels:
|
||||
- pinned
|
||||
- security
|
||||
# Label to use when marking an issue as stale
|
||||
staleLabel: wontfix
|
||||
# Comment to post when marking an issue as stale. Set to `false` to disable
|
||||
markComment: >
|
||||
This issue has been automatically marked as stale because it has not had
|
||||
recent activity. It will be closed if no further activity occurs. Thank you
|
||||
for your contributions.
|
||||
# Comment to post when closing a stale issue. Set to `false` to disable
|
||||
closeComment: false
|
||||
41
.github/workflows/molecule.yml
vendored
Normal file
41
.github/workflows/molecule.yml
vendored
Normal file
@@ -0,0 +1,41 @@
|
||||
---
|
||||
name: Molecule
|
||||
on:
|
||||
push:
|
||||
branches-ignore:
|
||||
- main
|
||||
- master
|
||||
pull_request:
|
||||
branches:
|
||||
- develop
|
||||
- main
|
||||
- master
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
fail-fast: false
|
||||
max-parallel: 4
|
||||
matrix:
|
||||
python-version: [3.9]
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: recursive
|
||||
- name: Set up Python ${{ matrix.python-version }}
|
||||
uses: actions/setup-python@v5
|
||||
with:
|
||||
python-version: ${{ matrix.python-version }}
|
||||
- uses: actions/cache@v4
|
||||
with:
|
||||
path: ~/.cache/pip
|
||||
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements*.txt') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-pip-
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
python -m pip install --upgrade pip
|
||||
pip install -r requirements.txt -r requirements-dev.txt
|
||||
- name: Check linting with pre-commit
|
||||
run: pre-commit run --all-files
|
||||
17
.github/workflows/release-drafter.yml
vendored
Normal file
17
.github/workflows/release-drafter.yml
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
name: Release Drafter
|
||||
|
||||
on:
|
||||
push:
|
||||
# branches to consider in the event; optional, defaults to all
|
||||
branches:
|
||||
- main
|
||||
- master
|
||||
|
||||
jobs:
|
||||
update_release_draft:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
# Drafts your next Release notes as Pull Requests are merged into "master"
|
||||
- uses: release-drafter/release-drafter@v5
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
34
.github/workflows/release-galaxy.yml
vendored
Normal file
34
.github/workflows/release-galaxy.yml
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
---
|
||||
name: Ansible Galaxy
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
- master
|
||||
release:
|
||||
types:
|
||||
- published
|
||||
|
||||
jobs:
|
||||
galaxy:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: recursive
|
||||
- name: Set up Python 3.9
|
||||
uses: actions/setup-python@v5
|
||||
with:
|
||||
python-version: '3.9'
|
||||
- uses: actions/cache@v4
|
||||
with:
|
||||
path: ~/.cache/pip
|
||||
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements*.txt') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-pip-
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
python -m pip install --upgrade pip
|
||||
pip install -r requirements.txt -r requirements-dev.txt
|
||||
- name: Trigger a new import on Galaxy.
|
||||
run: ansible-galaxy role import --api-key ${{ secrets.GALAXY_API_KEY }} $(echo ${{ github.repository }} | cut -d/ -f1) $(echo ${{ github.repository }} | cut -d/ -f2)
|
||||
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
.idea
|
||||
**/__pycache__
|
||||
.venv/
|
||||
32
.pre-commit-config.yaml
Normal file
32
.pre-commit-config.yaml
Normal file
@@ -0,0 +1,32 @@
|
||||
# See https://pre-commit.com for more information
|
||||
# See https://pre-commit.com/hooks.html for more hooks
|
||||
repos:
|
||||
- repo: https://github.com/pre-commit/pre-commit-hooks
|
||||
rev: v4.4.0
|
||||
hooks:
|
||||
- id: check-added-large-files
|
||||
- id: check-executables-have-shebangs
|
||||
- id: check-merge-conflict
|
||||
- id: check-symlinks
|
||||
- id: detect-private-key
|
||||
- id: end-of-file-fixer
|
||||
- id: no-commit-to-branch
|
||||
args: [--branch, develop, --branch, master, --branch, main]
|
||||
- id: trailing-whitespace
|
||||
- repo: https://github.com/ansible-community/ansible-lint
|
||||
rev: v6.17.1
|
||||
hooks:
|
||||
- id: ansible-lint
|
||||
- repo: https://github.com/psf/black
|
||||
rev: 23.3.0
|
||||
hooks:
|
||||
- id: black
|
||||
language_version: python3
|
||||
- repo: https://github.com/PyCQA/flake8
|
||||
rev: 6.0.0
|
||||
hooks:
|
||||
- id: flake8
|
||||
- repo: https://github.com/adrienverge/yamllint
|
||||
rev: v1.32.0
|
||||
hooks:
|
||||
- id: yamllint
|
||||
36
.yamllint.yml
Normal file
36
.yamllint.yml
Normal file
@@ -0,0 +1,36 @@
|
||||
---
|
||||
# Based on ansible-lint config
|
||||
extends: default
|
||||
|
||||
ignore: |
|
||||
.venv/
|
||||
|
||||
rules:
|
||||
braces:
|
||||
max-spaces-inside: 1
|
||||
level: error
|
||||
brackets:
|
||||
max-spaces-inside: 1
|
||||
level: error
|
||||
colons:
|
||||
max-spaces-after: -1
|
||||
level: error
|
||||
commas:
|
||||
max-spaces-after: -1
|
||||
level: error
|
||||
comments: disable
|
||||
comments-indentation: disable
|
||||
document-start: disable
|
||||
empty-lines:
|
||||
max: 3
|
||||
level: error
|
||||
hyphens:
|
||||
level: error
|
||||
indentation: disable
|
||||
key-duplicates: enable
|
||||
line-length: disable
|
||||
new-line-at-end-of-file: disable
|
||||
new-lines:
|
||||
type: unix
|
||||
trailing-spaces: disable
|
||||
truthy: disable
|
||||
19
CHANGELOG.md
19
CHANGELOG.md
@@ -1,19 +0,0 @@
|
||||
# Change Log
|
||||
|
||||
## [Unreleased](https://github.com/mrlesmithjr/ansible-manage-lvm/tree/HEAD)
|
||||
|
||||
[Full Changelog](https://github.com/mrlesmithjr/ansible-manage-lvm/compare/v0.1.0...HEAD)
|
||||
|
||||
**Closed issues:**
|
||||
|
||||
- Role fails on CentOS due to system-storage-manager package [\#2](https://github.com/mrlesmithjr/ansible-manage-lvm/issues/2)
|
||||
|
||||
## [v0.1.0](https://github.com/mrlesmithjr/ansible-manage-lvm/tree/v0.1.0) (2016-09-30)
|
||||
**Merged pull requests:**
|
||||
|
||||
- Replace system-storage-manager with lvm2 in centos [\#3](https://github.com/mrlesmithjr/ansible-manage-lvm/pull/3) ([rohitkothari](https://github.com/rohitkothari))
|
||||
- Add xfs\_growfs for xfs systemfile type. [\#1](https://github.com/mrlesmithjr/ansible-manage-lvm/pull/1) ([olo-dw](https://github.com/olo-dw))
|
||||
|
||||
|
||||
|
||||
\* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*
|
||||
145
README.md
145
README.md
@@ -1,86 +1,45 @@
|
||||
# Role Name
|
||||
# ansible-manage-lvm
|
||||
|
||||
An [Ansible] role to manage LVM Groups/Logical Volumes.
|
||||
Ansible role to manage LVM Groups/Logical Volumes.
|
||||
|
||||
> NOTE: Can be used to create, extend or resize LVM Groups and volumes.
|
||||
|
||||
## ⚠️ Important: Ansible Galaxy Role Name
|
||||
|
||||
**As of December 2025**, this role is available on Ansible Galaxy as:
|
||||
|
||||
```yaml
|
||||
- src: mrlesmithjr.manage_lvm # Note: underscore, not hyphen
|
||||
```
|
||||
|
||||
The previous role names (`mrlesmithjr.manage-lvm` and `mrlesmithjr.manage_lvm`) were
|
||||
consolidated into a single role. If you were using `mrlesmithjr.manage-lvm`, please
|
||||
update your `requirements.yml` to use `mrlesmithjr.manage_lvm`.
|
||||
|
||||
**Note:** This role is used by [OpenStack Kayobe](https://docs.openstack.org/kayobe/latest/)
|
||||
for LVM management. The `manage_lvm` name was preserved to maintain compatibility.
|
||||
|
||||
### Historical Download Statistics
|
||||
|
||||
Prior to consolidation, this role had accumulated significant usage:
|
||||
|
||||
| Role Name | Downloads (as of Dec 2025) |
|
||||
|-----------|---------------------------|
|
||||
| `mrlesmithjr.manage_lvm` | 697,492 |
|
||||
| `mrlesmithjr.manage-lvm` | 494,517 |
|
||||
| **Combined Total** | **1,192,009** |
|
||||
|
||||
Due to Ansible Galaxy limitations, download counts reset when roles are re-imported.
|
||||
The historical data above represents the actual community usage of this role.
|
||||
|
||||
## Requirements
|
||||
|
||||
Devices/disks to be members of the LVM setup **must be** identified prior to
|
||||
using this role.
|
||||
|
||||
> NOTE: Ensure that you select the correct devices/disks.
|
||||
>
|
||||
> NOTE: To create an LVM VG w/out creating LVM LVOLS...define lvname w/ var as
|
||||
> `None` as in the below example.
|
||||
|
||||
## Role Variables
|
||||
|
||||
```yaml
|
||||
---
|
||||
# defaults file for ansible-manage-lvm
|
||||
lvm_groups: []
|
||||
# - vgname: ubuntu-vg
|
||||
# disks:
|
||||
# - /dev/sda5
|
||||
# - /dev/sdc
|
||||
# - /dev/sdd
|
||||
# # defines if VG should exist or be removed
|
||||
# # true or false
|
||||
# create: true
|
||||
# lvnames:
|
||||
# - lvname: swap_1
|
||||
# # Define size of lvol
|
||||
# # 100%FREE, 10g, 1024 (megabytes by default)
|
||||
# size: 5g
|
||||
# # Defines additional lvcreate options (e.g. stripes, stripesize, etc)
|
||||
# opts: ''
|
||||
# # Defines if lvol should exist or be removed
|
||||
# # true or false
|
||||
# create: true
|
||||
# # Defines filesystem to format lvol as
|
||||
# filesystem: swap
|
||||
# # Defines if filesystem should be mounted
|
||||
# mount: false
|
||||
# # Defines mountpoint for lvol
|
||||
# mntp: []
|
||||
# # Defines additional mount options (e.g. noatime, noexec, etc)
|
||||
# mopts: ''
|
||||
# - lvname: root
|
||||
# size: 40g
|
||||
# create: true
|
||||
# filesystem: ext4
|
||||
# mount: true
|
||||
# mntp: /
|
||||
# - vgname: test-vg
|
||||
# disks:
|
||||
# - /dev/sdb
|
||||
# create: true
|
||||
# lvnames:
|
||||
# - lvname: test_1
|
||||
# size: 5g
|
||||
# create: true
|
||||
# filesystem: ext4
|
||||
# mount: true
|
||||
# mntp: /mnt/test_1
|
||||
# - lvname: test_2
|
||||
# size: 10g
|
||||
# create: true
|
||||
# filesystem: ext4
|
||||
# mount: true
|
||||
# mntp: /mnt/test_2
|
||||
# - vgname: cinder-volumes
|
||||
# disks:
|
||||
# - /dev/cciss/c0d1
|
||||
# create: true
|
||||
# lvnames:
|
||||
# # Set to None to only create LVM VG w/out creating LVM LVOLS
|
||||
# - None
|
||||
|
||||
# Defines if LVM will be managed by role
|
||||
# default is false to ensure nothing is changed by accident.
|
||||
manage_lvm: false
|
||||
```
|
||||
[defaults/main.yml](defaults/main.yml)
|
||||
|
||||
## Dependencies
|
||||
|
||||
@@ -88,48 +47,18 @@ None
|
||||
|
||||
## Example Playbook
|
||||
|
||||
```yaml
|
||||
---
|
||||
- hosts: test-nodes
|
||||
vars:
|
||||
lvm_groups:
|
||||
- vgname: test-vg
|
||||
disks:
|
||||
- /dev/sdb
|
||||
- /dev/sdc
|
||||
create: true
|
||||
lvnames:
|
||||
- lvname: test_1
|
||||
size: 5g
|
||||
create: true
|
||||
filesystem: ext4
|
||||
mount: true
|
||||
mntp: /mnt/test_1
|
||||
- lvname: test_2
|
||||
size: 10g
|
||||
create: true
|
||||
filesystem: ext4
|
||||
mount: true
|
||||
mntp: /mnt/test_2
|
||||
manage_lvm: true
|
||||
pri_domain_name: 'test.vagrant.local'
|
||||
roles:
|
||||
- role: ansible-manage-lvm
|
||||
tasks:
|
||||
```
|
||||
[playbook.yml](playbook.yml)
|
||||
|
||||
## License
|
||||
|
||||
BSD
|
||||
MIT
|
||||
|
||||
## Author Information
|
||||
|
||||
Larry Smith Jr.
|
||||
|
||||
- [@mrlesmithjr]
|
||||
- <http://everythingshouldbevirtual.com>
|
||||
- mrlesmithjr [at] gmail.com
|
||||
- [@mrlesmithjr](https://twitter.com/mrlesmithjr)
|
||||
- [mrlesmithjr@gmail.com](mailto:mrlesmithjr@gmail.com)
|
||||
- [http://everythingshouldbevirtual.com](http://everythingshouldbevirtual.com)
|
||||
|
||||
[@mrlesmithjr]: https://www.twitter.com/mrlesmithjr
|
||||
|
||||
[ansible]: https://www.ansible.com
|
||||
<a href="https://www.buymeacoffee.com/mrlesmithjr" target="_blank"><img src="https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png" alt="Buy Me A Coffee" style="height: 60px !important;width: 217px !important;" ></a>
|
||||
|
||||
@@ -1,63 +1,92 @@
|
||||
---
|
||||
# defaults file for ansible-manage-lvm
|
||||
lvm_groups: []
|
||||
# - vgname: ubuntu-vg
|
||||
# disks:
|
||||
# - /dev/sda5
|
||||
# - /dev/sdc
|
||||
# - /dev/sdd
|
||||
# # defines if VG should exist or be removed
|
||||
# # true or false
|
||||
# create: true
|
||||
# lvnames:
|
||||
# - lvname: swap_1
|
||||
# # Define size of lvol
|
||||
# # 100%FREE, 10g, 1024 (megabytes by default)
|
||||
# size: 5g
|
||||
# # Defines additional lvcreate options (e.g. stripes, stripesize, etc)
|
||||
# opts: ''
|
||||
# # Defines if lvol should exist or be removed
|
||||
# # true or false
|
||||
# create: true
|
||||
# # Defines filesystem to format lvol as
|
||||
# filesystem: swap
|
||||
# # Defines if filesystem should be mounted
|
||||
# mount: false
|
||||
# # Defines mountpoint for lvol
|
||||
# mntp: []
|
||||
# # Defines additional mount options (e.g. noatime, noexec, etc)
|
||||
# mopts: ''
|
||||
# - lvname: root
|
||||
# size: 40g
|
||||
# create: true
|
||||
# filesystem: ext4
|
||||
# mount: true
|
||||
# mntp: /
|
||||
# - vgname: test-vg
|
||||
# disks:
|
||||
# - /dev/sdb
|
||||
# create: true
|
||||
# lvnames:
|
||||
# - lvname: test_1
|
||||
# size: 5g
|
||||
# create: true
|
||||
# filesystem: ext4
|
||||
# mount: true
|
||||
# mntp: /mnt/test_1
|
||||
# - lvname: test_2
|
||||
# size: 10g
|
||||
# create: true
|
||||
# filesystem: ext4
|
||||
# mount: true
|
||||
# mntp: /mnt/test_2
|
||||
# - vgname: cinder-volumes
|
||||
# disks:
|
||||
# - /dev/cciss/c0d1
|
||||
# create: true
|
||||
# lvnames:
|
||||
# # Set to None to only create LVM VG w/out creating LVM LVOLS
|
||||
# - None
|
||||
# - vgname: ubuntu-vg
|
||||
# disks:
|
||||
# - /dev/sda5
|
||||
# - /dev/sdc
|
||||
# - /dev/sdd
|
||||
# # defines if VG should exist or be removed
|
||||
# # true or false
|
||||
# create: true
|
||||
# # defines if PV should be resized to max size
|
||||
# pvresize: false
|
||||
# lvnames:
|
||||
# - lvname: swap_1
|
||||
# # Define size of lvol
|
||||
# # 100%FREE, 10g, 1024 (megabytes by default)
|
||||
# size: 5g
|
||||
# # Defines additional lvcreate options (e.g. stripes, stripesize, etc)
|
||||
# opts: ''
|
||||
# # Defines if lvol should exist or be removed
|
||||
# # true or false
|
||||
# create: true
|
||||
# # Defines filesystem to format lvol as
|
||||
# filesystem: swap
|
||||
# # Defines if filesystem should be mounted
|
||||
# mount: false
|
||||
# # Defines mountpoint for lvol
|
||||
# mntp: []
|
||||
# # Defines additional mount options (e.g. noatime, noexec, etc)
|
||||
# mopts: ''
|
||||
# - lvname: root
|
||||
# size: 40g
|
||||
# create: true
|
||||
# filesystem: ext4
|
||||
# # Defines options passed to the filesystem creation command
|
||||
# fsopts:
|
||||
# mount: true
|
||||
# mntp: /
|
||||
# - vgname: test-vg
|
||||
# disks:
|
||||
# - /dev/sdb
|
||||
# create: true
|
||||
# lvnames:
|
||||
# - lvname: test_1
|
||||
# size: 5g
|
||||
# create: true
|
||||
# filesystem: ext4
|
||||
# mount: true
|
||||
# mntp: /mnt/test_1
|
||||
# - lvname: test_2
|
||||
# size: 10g
|
||||
# create: true
|
||||
# filesystem: ext4
|
||||
# mount: true
|
||||
# mntp: /mnt/test_2
|
||||
# - vgname: cinder-volumes
|
||||
# disks:
|
||||
# - /dev/cciss/c0d1
|
||||
# create: true
|
||||
# lvnames:
|
||||
# # Set to None to only create LVM VG w/out creating LVM LVOLS
|
||||
# - None
|
||||
# # Using fsopts to create a docker compatible xfs volume
|
||||
# - vgname: docker-volumes
|
||||
# disks:
|
||||
# - /dev/vdc
|
||||
# - /dev/vdd
|
||||
# create: true
|
||||
# lvnames:
|
||||
# - lvname: docker_1
|
||||
# size: 100%FREE
|
||||
# create: true
|
||||
# filesystem: xfs
|
||||
# fsopts: -n ftype=1
|
||||
# mount: true
|
||||
# mntp: /var/lib/docker
|
||||
|
||||
# Defines if LVM will be managed by role
|
||||
# default is false to ensure nothing is changed by accident.
|
||||
manage_lvm: false
|
||||
|
||||
### nvme to scsi device name map binary helper
|
||||
ebsnvme_binary_helper_ver: '0.1.3'
|
||||
ebsnvme_binary_helper_tmp: '/tmp'
|
||||
ebsnvme_binary_helper_path: '/sbin/go-ebsnvme'
|
||||
|
||||
### nvme to scsi device name map script helper
|
||||
ebsnvme_scrip_helper_path: '/usr/local/bin/ebsnvme-id'
|
||||
|
||||
### resize all pv's to max size
|
||||
pvresize_to_max: false
|
||||
|
||||
@@ -1,37 +1,26 @@
|
||||
---
|
||||
galaxy_info:
|
||||
author: Larry Smith Jr.
|
||||
description: Role to manage LVM Groups/Logical Volumes. Can be used to create, extend or resize LVM.
|
||||
#company: your company (optional)
|
||||
# If the issue tracker for your role is not on github, uncomment the
|
||||
# next line and provide a value
|
||||
# issue_tracker_url: http://example.com/issue/tracker
|
||||
# Some suggested licenses:
|
||||
# - BSD (default)
|
||||
# - MIT
|
||||
# - GPLv2
|
||||
# - GPLv3
|
||||
# - Apache
|
||||
# - CC-BY
|
||||
license: license (GPLv2, CC-BY, etc)
|
||||
min_ansible_version: 1.2
|
||||
platforms:
|
||||
- name: EL
|
||||
versions:
|
||||
- 6
|
||||
- 7
|
||||
- name: Ubuntu
|
||||
versions:
|
||||
- precise
|
||||
- trusty
|
||||
- name: Debian
|
||||
versions:
|
||||
- jessie
|
||||
- wheezy
|
||||
description: Ansible role to manage(create, extend, resize) LVM Groups/Logical Volumes.
|
||||
namespace: mrlesmithjr
|
||||
role_name: manage-lvm
|
||||
|
||||
categories:
|
||||
- system
|
||||
license: MIT
|
||||
min_ansible_version: "1.2"
|
||||
platforms:
|
||||
- name: EL
|
||||
versions:
|
||||
- all
|
||||
- name: Fedora
|
||||
versions:
|
||||
- all
|
||||
- name: Ubuntu
|
||||
versions:
|
||||
- all
|
||||
- name: Debian
|
||||
versions:
|
||||
- all
|
||||
galaxy_tags:
|
||||
- system
|
||||
- lvm
|
||||
dependencies: []
|
||||
# List your role dependencies here, one per line.
|
||||
# Be sure to remove the '[]' above if you add dependencies
|
||||
# to this list.
|
||||
|
||||
29
molecule/default/converge.yml
Normal file
29
molecule/default/converge.yml
Normal file
@@ -0,0 +1,29 @@
|
||||
---
|
||||
- name: Converge
|
||||
hosts: all
|
||||
vars:
|
||||
lvm_groups:
|
||||
- vgname: my_vg
|
||||
disks:
|
||||
- /dev/sdb1
|
||||
create: true
|
||||
lvnames:
|
||||
- lvname: my_lv
|
||||
size: 40%VG
|
||||
opts: "--wipesignatures y"
|
||||
create: true
|
||||
filesystem: ext4
|
||||
mount: true
|
||||
mntp: "/var/lib/mountpoint"
|
||||
- lvname: my_lw
|
||||
size: 20%VG
|
||||
opts: "--wipesignatures y"
|
||||
mount: true
|
||||
create: true
|
||||
filesystem: xfs
|
||||
mntp: "/var/lib/mountpoint2"
|
||||
manage_lvm: true
|
||||
tasks:
|
||||
- name: "Include lvm"
|
||||
ansible.builtin.include_role:
|
||||
name: "ansible-manage-lvm"
|
||||
42
molecule/default/molecule.yml
Normal file
42
molecule/default/molecule.yml
Normal file
@@ -0,0 +1,42 @@
|
||||
---
|
||||
driver:
|
||||
name: vagrant
|
||||
provider:
|
||||
name: virtualbox
|
||||
lint: |
|
||||
yamllint .
|
||||
ansible-lint
|
||||
flake8
|
||||
platforms:
|
||||
- name: CentOS-Molecule-LVM
|
||||
box: mrlesmithjr/centos7
|
||||
provider_override_args:
|
||||
- "persistent_storage.enabled = true"
|
||||
- "persistent_storage.location = 'centos-molecule-lvm.vdi'"
|
||||
- "persistent_storage.size = 100"
|
||||
- "persistent_storage.mount = false"
|
||||
- "persistent_storage.diskdevice = '/dev/sdb'"
|
||||
- name: Fedora-Molecule-LVM
|
||||
box: mrlesmithjr/fedora31
|
||||
provider_override_args:
|
||||
- "persistent_storage.enabled = true"
|
||||
- "persistent_storage.location = 'fedora-molecule-lvm.vdi'"
|
||||
- "persistent_storage.size = 100"
|
||||
- "persistent_storage.mount = false"
|
||||
- "persistent_storage.diskdevice = '/dev/sdb'"
|
||||
- name: Ubuntu-Molecule-LVM
|
||||
box: mrlesmithjr/bionic64
|
||||
provider_override_args:
|
||||
- "persistent_storage.enabled = true"
|
||||
- "persistent_storage.location = 'ubuntu-molecule-lvm.vdi'"
|
||||
- "persistent_storage.size = 100"
|
||||
- "persistent_storage.mount = false"
|
||||
- "persistent_storage.diskdevice = '/dev/sdb'"
|
||||
provisioner:
|
||||
name: ansible
|
||||
verifier:
|
||||
name: testinfra
|
||||
env:
|
||||
PYTHONWARNINGS: "ignore:.*U.*mode is deprecated:DeprecationWarning"
|
||||
options:
|
||||
v: 1
|
||||
20
molecule/default/tests/conftest.py
Normal file
20
molecule/default/tests/conftest.py
Normal file
@@ -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
|
||||
)
|
||||
33
molecule/default/tests/test_default.py
Normal file
33
molecule/default/tests/test_default.py
Normal file
@@ -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
|
||||
29
molecule/kvm/converge.yml
Normal file
29
molecule/kvm/converge.yml
Normal file
@@ -0,0 +1,29 @@
|
||||
---
|
||||
- name: Converge
|
||||
hosts: all
|
||||
vars:
|
||||
lvm_groups:
|
||||
- vgname: my_vg
|
||||
disks:
|
||||
- /dev/vdb
|
||||
create: true
|
||||
lvnames:
|
||||
- lvname: my_lv
|
||||
size: 40%VG
|
||||
opts: "--wipesignatures y"
|
||||
create: true
|
||||
filesystem: ext4
|
||||
mount: true
|
||||
mntp: "/var/lib/mountpoint"
|
||||
- lvname: my_lw
|
||||
size: 20%VG
|
||||
opts: "--wipesignatures y"
|
||||
mount: true
|
||||
create: true
|
||||
filesystem: xfs
|
||||
mntp: "/var/lib/mountpoint2"
|
||||
manage_lvm: true
|
||||
tasks:
|
||||
- name: "Include lvm"
|
||||
ansible.builtin.include_role:
|
||||
name: "ansible-manage-lvm"
|
||||
29
molecule/kvm/molecule.yml
Normal file
29
molecule/kvm/molecule.yml
Normal file
@@ -0,0 +1,29 @@
|
||||
---
|
||||
driver:
|
||||
name: vagrant
|
||||
provider:
|
||||
name: libvirt
|
||||
lint: yamllint . && flake8 && ansible-lint
|
||||
platforms:
|
||||
- name: Fedora-Molecule-Volumes-KVM
|
||||
box: fedora/31-cloud-base
|
||||
cpu: 2
|
||||
memory: 2048
|
||||
provider_raw_config_args:
|
||||
- "storage :file, :size => '1G', :device => 'vdb'"
|
||||
provisioner:
|
||||
name: ansible
|
||||
config_options:
|
||||
defaults:
|
||||
forks: 20
|
||||
ssh_connection:
|
||||
pipelining: true
|
||||
ssh_args: -o ControlMaster=auto -o ControlPersist=600s
|
||||
verifier:
|
||||
name: testinfra
|
||||
env:
|
||||
PYTHONWARNINGS: "ignore:.*U.*mode is deprecated:DeprecationWarning"
|
||||
options:
|
||||
v: 1
|
||||
scenario:
|
||||
name: kvm
|
||||
20
molecule/kvm/tests/conftest.py
Normal file
20
molecule/kvm/tests/conftest.py
Normal file
@@ -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
|
||||
)
|
||||
33
molecule/kvm/tests/test_default.py
Normal file
33
molecule/kvm/tests/test_default.py
Normal file
@@ -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
|
||||
14
molecule/kvmonlyvg/converge.yml
Normal file
14
molecule/kvmonlyvg/converge.yml
Normal file
@@ -0,0 +1,14 @@
|
||||
---
|
||||
- name: Converge
|
||||
hosts: all
|
||||
vars:
|
||||
lvm_groups:
|
||||
- vgname: my_vg
|
||||
disks:
|
||||
- /dev/vdb
|
||||
create: true
|
||||
manage_lvm: true
|
||||
tasks:
|
||||
- name: "Include lvm"
|
||||
ansible.builtin.include_role:
|
||||
name: "ansible-manage-lvm"
|
||||
29
molecule/kvmonlyvg/molecule.yml
Normal file
29
molecule/kvmonlyvg/molecule.yml
Normal file
@@ -0,0 +1,29 @@
|
||||
---
|
||||
driver:
|
||||
name: vagrant
|
||||
provider:
|
||||
name: libvirt
|
||||
lint: yamllint . && flake8 && ansible-lint
|
||||
platforms:
|
||||
- name: Fedora-Molecule-Volumes-KVM
|
||||
box: fedora/31-cloud-base
|
||||
cpu: 2
|
||||
memory: 2048
|
||||
provider_raw_config_args:
|
||||
- "storage :file, :size => '1G', :device => 'vdb'"
|
||||
provisioner:
|
||||
name: ansible
|
||||
config_options:
|
||||
defaults:
|
||||
forks: 20
|
||||
ssh_connection:
|
||||
pipelining: true
|
||||
ssh_args: -o ControlMaster=auto -o ControlPersist=600s
|
||||
verifier:
|
||||
name: testinfra
|
||||
env:
|
||||
PYTHONWARNINGS: "ignore:.*U.*mode is deprecated:DeprecationWarning"
|
||||
options:
|
||||
v: 1
|
||||
scenario:
|
||||
name: kvmonlyvg
|
||||
20
molecule/kvmonlyvg/tests/conftest.py
Normal file
20
molecule/kvmonlyvg/tests/conftest.py
Normal file
@@ -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
|
||||
)
|
||||
11
molecule/kvmonlyvg/tests/test_default.py
Normal file
11
molecule/kvmonlyvg/tests/test_default.py
Normal file
@@ -0,0 +1,11 @@
|
||||
"""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
|
||||
22
molecule/kvmsinglelv/converge.yml
Normal file
22
molecule/kvmsinglelv/converge.yml
Normal file
@@ -0,0 +1,22 @@
|
||||
---
|
||||
- name: Converge
|
||||
hosts: all
|
||||
vars:
|
||||
lvm_groups:
|
||||
- vgname: my_vg
|
||||
disks:
|
||||
- /dev/vdb
|
||||
create: true
|
||||
lvnames:
|
||||
- lvname: my_lv
|
||||
size: 40%VG
|
||||
opts: "--wipesignatures y"
|
||||
create: true
|
||||
filesystem: ext4
|
||||
mount: true
|
||||
mntp: "/var/lib/mountpoint"
|
||||
manage_lvm: true
|
||||
tasks:
|
||||
- name: "Include lvm"
|
||||
ansible.builtin.include_role:
|
||||
name: "ansible-manage-lvm"
|
||||
29
molecule/kvmsinglelv/molecule.yml
Normal file
29
molecule/kvmsinglelv/molecule.yml
Normal file
@@ -0,0 +1,29 @@
|
||||
---
|
||||
driver:
|
||||
name: vagrant
|
||||
provider:
|
||||
name: libvirt
|
||||
lint: yamllint . && flake8 && ansible-lint
|
||||
platforms:
|
||||
- name: Fedora-Molecule-Volumes-KVM
|
||||
box: fedora/31-cloud-base
|
||||
cpu: 2
|
||||
memory: 2048
|
||||
provider_raw_config_args:
|
||||
- "storage :file, :size => '1G', :device => 'vdb'"
|
||||
provisioner:
|
||||
name: ansible
|
||||
config_options:
|
||||
defaults:
|
||||
forks: 20
|
||||
ssh_connection:
|
||||
pipelining: true
|
||||
ssh_args: -o ControlMaster=auto -o ControlPersist=600s
|
||||
verifier:
|
||||
name: testinfra
|
||||
env:
|
||||
PYTHONWARNINGS: "ignore:.*U.*mode is deprecated:DeprecationWarning"
|
||||
options:
|
||||
v: 1
|
||||
scenario:
|
||||
name: kvmsinglelv
|
||||
20
molecule/kvmsinglelv/tests/conftest.py
Normal file
20
molecule/kvmsinglelv/tests/conftest.py
Normal file
@@ -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
|
||||
)
|
||||
22
molecule/kvmsinglelv/tests/test_default.py
Normal file
22
molecule/kvmsinglelv/tests/test_default.py
Normal file
@@ -0,0 +1,22 @@
|
||||
"""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_volume_is_mounted(host):
|
||||
host.file("/var/lib/mountpoint").mode == 0o731
|
||||
28
playbook.yml
Normal file
28
playbook.yml
Normal file
@@ -0,0 +1,28 @@
|
||||
---
|
||||
- name: Example playbook
|
||||
hosts: test-nodes
|
||||
vars:
|
||||
lvm_groups:
|
||||
- vgname: test-vg
|
||||
disks:
|
||||
- /dev/sdb
|
||||
- /dev/sdc
|
||||
create: true
|
||||
lvnames:
|
||||
- lvname: test_1
|
||||
size: 5g
|
||||
create: true
|
||||
filesystem: ext4
|
||||
mount: true
|
||||
mntp: /mnt/test_1
|
||||
- lvname: test_2
|
||||
size: 10g
|
||||
create: true
|
||||
filesystem: ext4
|
||||
mount: true
|
||||
mntp: /mnt/test_2
|
||||
manage_lvm: true
|
||||
tasks:
|
||||
- name: Include lvm
|
||||
ansible.builtin.include_role:
|
||||
name: ansible-manage-lvm
|
||||
1546
poetry.lock
generated
Normal file
1546
poetry.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
23
pyproject.toml
Normal file
23
pyproject.toml
Normal file
@@ -0,0 +1,23 @@
|
||||
[tool.poetry]
|
||||
name = "ansible-manage-lvm"
|
||||
version = "0.1.0"
|
||||
description = ""
|
||||
authors = ["Larry Smith Jr. <mrlesmithjr@gmail.com>"]
|
||||
|
||||
[tool.poetry.dependencies]
|
||||
python = ">=3.9,<4.0"
|
||||
ansible = "8.5.0"
|
||||
|
||||
[tool.poetry.group.dev.dependencies]
|
||||
ansible-lint = "6.8.7"
|
||||
black = "^22.10.0"
|
||||
pylint = "^2.15.7"
|
||||
flake8 = "^6.0.0"
|
||||
cookiecutter = "^2.1.1"
|
||||
pre-commit = "^2.20.0"
|
||||
molecule-plugins = {extras = ["vagrant"], version = "^23.4.1"}
|
||||
molecule = {extras = ["docker"], version = "^5.0.1"}
|
||||
|
||||
[build-system]
|
||||
requires = ["poetry-core>=1.0.0"]
|
||||
build-backend = "poetry.core.masonry.api"
|
||||
73
requirements-dev.txt
Normal file
73
requirements-dev.txt
Normal file
@@ -0,0 +1,73 @@
|
||||
ansible-compat==3.0.2 ; python_version >= "3.9" and python_version < "4.0"
|
||||
ansible-core==2.13.10 ; python_version >= "3.9" and python_version < "4.0"
|
||||
ansible-lint==6.8.7 ; python_version >= "3.9" and python_version < "4.0"
|
||||
ansible==6.6.0 ; python_version >= "3.9" and python_version < "4.0"
|
||||
arrow==1.2.3 ; python_version >= "3.9" and python_version < "4.0"
|
||||
astroid==2.15.5 ; python_version >= "3.9" and python_version < "4.0"
|
||||
attrs==23.1.0 ; python_version >= "3.9" and python_version < "4.0"
|
||||
binaryornot==0.4.4 ; python_version >= "3.9" and python_version < "4.0"
|
||||
black==22.12.0 ; python_version >= "3.9" and python_version < "4.0"
|
||||
bracex==2.3.post1 ; python_version >= "3.9" and python_version < "4.0"
|
||||
certifi==2023.5.7 ; python_version >= "3.9" and python_version < "4.0"
|
||||
cffi==1.15.1 ; python_version >= "3.9" and python_version < "4.0"
|
||||
cfgv==3.3.1 ; python_version >= "3.9" and python_version < "4.0"
|
||||
chardet==5.1.0 ; python_version >= "3.9" and python_version < "4.0"
|
||||
charset-normalizer==3.1.0 ; python_version >= "3.9" and python_version < "4.0"
|
||||
click-help-colors==0.9.1 ; python_version >= "3.9" and python_version < "4.0"
|
||||
click==8.1.3 ; python_version >= "3.9" and python_version < "4.0"
|
||||
colorama==0.4.6 ; python_version >= "3.9" and python_version < "4.0" and sys_platform == "win32" or python_version >= "3.9" and python_version < "4.0" and platform_system == "Windows"
|
||||
cookiecutter==2.1.1 ; python_version >= "3.9" and python_version < "4.0"
|
||||
cryptography==41.0.1 ; python_version >= "3.9" and python_version < "4.0"
|
||||
dill==0.3.6 ; python_version >= "3.9" and python_version < "4.0"
|
||||
distlib==0.3.6 ; python_version >= "3.9" and python_version < "4.0"
|
||||
enrich==1.2.7 ; python_version >= "3.9" and python_version < "4.0"
|
||||
filelock==3.12.2 ; python_version >= "3.9" and python_version < "4.0"
|
||||
flake8==6.0.0 ; python_version >= "3.9" and python_version < "4.0"
|
||||
identify==2.5.24 ; python_version >= "3.9" and python_version < "4.0"
|
||||
idna==3.4 ; python_version >= "3.9" and python_version < "4.0"
|
||||
isort==5.12.0 ; python_version >= "3.9" and python_version < "4.0"
|
||||
jinja2-time==0.2.0 ; python_version >= "3.9" and python_version < "4.0"
|
||||
jinja2==3.1.2 ; python_version >= "3.9" and python_version < "4.0"
|
||||
jsonschema==4.17.3 ; python_version >= "3.9" and python_version < "4.0"
|
||||
lazy-object-proxy==1.9.0 ; python_version >= "3.9" and python_version < "4.0"
|
||||
markdown-it-py==3.0.0 ; python_version >= "3.9" and python_version < "4.0"
|
||||
markupsafe==2.1.3 ; python_version >= "3.9" and python_version < "4.0"
|
||||
mccabe==0.7.0 ; python_version >= "3.9" and python_version < "4.0"
|
||||
mdurl==0.1.2 ; python_version >= "3.9" and python_version < "4.0"
|
||||
molecule-plugins[vagrant]==23.4.1 ; python_version >= "3.9" and python_version < "4.0"
|
||||
molecule==5.0.1 ; python_version >= "3.9" and python_version < "4.0"
|
||||
molecule[docker]==5.0.1 ; python_version >= "3.9" and python_version < "4.0"
|
||||
mypy-extensions==0.4.4 ; python_version >= "3.9" and python_version < "4.0"
|
||||
nodeenv==1.8.0 ; python_version >= "3.9" and python_version < "4.0"
|
||||
packaging==23.1 ; python_version >= "3.9" and python_version < "4.0"
|
||||
pathspec==0.11.1 ; python_version >= "3.9" and python_version < "4.0"
|
||||
platformdirs==2.6.2 ; python_version >= "3.9" and python_version < "4.0"
|
||||
pluggy==0.13.1 ; python_version >= "3.9" and python_version < "4.0"
|
||||
pre-commit==2.21.0 ; python_version >= "3.9" and python_version < "4.0"
|
||||
pycodestyle==2.10.0 ; python_version >= "3.9" and python_version < "4.0"
|
||||
pycparser==2.21 ; python_version >= "3.9" and python_version < "4.0"
|
||||
pyflakes==3.0.1 ; python_version >= "3.9" and python_version < "4.0"
|
||||
pygments==2.15.1 ; python_version >= "3.9" and python_version < "4.0"
|
||||
pylint==2.17.4 ; python_version >= "3.9" and python_version < "4.0"
|
||||
pyrsistent==0.19.3 ; python_version >= "3.9" and python_version < "4.0"
|
||||
python-dateutil==2.8.2 ; python_version >= "3.9" and python_version < "4.0"
|
||||
python-slugify==8.0.1 ; python_version >= "3.9" and python_version < "4.0"
|
||||
python-vagrant==1.0.0 ; python_version >= "3.9" and python_version < "4.0"
|
||||
pyyaml==5.4.1 ; python_version >= "3.9" and python_version < "4.0"
|
||||
requests==2.31.0 ; python_version >= "3.9" and python_version < "4.0"
|
||||
resolvelib==0.5.4 ; python_version >= "3.9" and python_version < "4.0"
|
||||
rich==13.4.2 ; python_version >= "3.9" and python_version < "4.0"
|
||||
ruamel-yaml-clib==0.2.7 ; platform_python_implementation == "CPython" and python_version < "3.12" and python_version >= "3.9"
|
||||
ruamel-yaml==0.17.31 ; python_version >= "3.9" and python_version < "4.0"
|
||||
setuptools==67.8.0 ; python_version >= "3.9" and python_version < "4.0"
|
||||
six==1.16.0 ; python_version >= "3.9" and python_version < "4.0"
|
||||
subprocess-tee==0.4.1 ; python_version >= "3.9" and python_version < "4.0"
|
||||
text-unidecode==1.3 ; python_version >= "3.9" and python_version < "4.0"
|
||||
tomli==1.2.3 ; python_version >= "3.9" and python_full_version < "3.11.0a7"
|
||||
tomlkit==0.11.8 ; python_version >= "3.9" and python_version < "4.0"
|
||||
typing-extensions==4.6.3 ; python_version >= "3.9" and python_version < "3.11"
|
||||
urllib3==1.26.16 ; python_version >= "3.9" and python_version < "4.0"
|
||||
virtualenv==20.21.1 ; python_version >= "3.9" and python_version < "4.0"
|
||||
wcmatch==8.4.1 ; python_version >= "3.9" and python_version < "4.0"
|
||||
wrapt==1.15.0 ; python_version >= "3.9" and python_version < "4.0"
|
||||
yamllint==1.32.0 ; python_version >= "3.9" and python_version < "4.0"
|
||||
10
requirements.txt
Normal file
10
requirements.txt
Normal file
@@ -0,0 +1,10 @@
|
||||
ansible-core==2.13.10 ; python_version >= "3.9" and python_version < "4.0"
|
||||
ansible==6.6.0 ; python_version >= "3.9" and python_version < "4.0"
|
||||
cffi==1.15.1 ; python_version >= "3.9" and python_version < "4.0"
|
||||
cryptography==41.0.1 ; python_version >= "3.9" and python_version < "4.0"
|
||||
jinja2==3.1.2 ; python_version >= "3.9" and python_version < "4.0"
|
||||
markupsafe==2.1.3 ; python_version >= "3.9" and python_version < "4.0"
|
||||
packaging==23.1 ; python_version >= "3.9" and python_version < "4.0"
|
||||
pycparser==2.21 ; python_version >= "3.9" and python_version < "4.0"
|
||||
pyyaml==5.4.1 ; python_version >= "3.9" and python_version < "4.0"
|
||||
resolvelib==0.5.4 ; python_version >= "3.9" and python_version < "4.0"
|
||||
70
tasks/amazon.yml
Normal file
70
tasks/amazon.yml
Normal file
@@ -0,0 +1,70 @@
|
||||
---
|
||||
- name: amazon | check for nvme devices
|
||||
ansible.builtin.shell: |
|
||||
set -o pipefail
|
||||
cat /proc/partitions | awk '{print $4}' | grep -q nvme. ; echo $?
|
||||
args:
|
||||
executable: /bin/bash
|
||||
register: blkdev_nvme
|
||||
changed_when: false
|
||||
|
||||
- name: amazon | check for amazon ebs devices
|
||||
ansible.builtin.shell: |
|
||||
set -o pipefail
|
||||
lsblk -O -J | grep -qi "amazon elastic block store" ; echo $?
|
||||
register: blkdev_awsebs
|
||||
changed_when: false
|
||||
args:
|
||||
executable: /bin/bash
|
||||
|
||||
- name: amazon | set flag for nvme subsystem
|
||||
ansible.builtin.set_fact:
|
||||
device_is_nvme: "{{ true if (blkdev_nvme.stdout == '0') else false }}"
|
||||
|
||||
- name: amazon | set flag for aws ebs devices
|
||||
ansible.builtin.set_fact:
|
||||
device_is_awsebs: "{{ true if (blkdev_awsebs.stdout == '0') else false }}"
|
||||
|
||||
- name: Block to map renamed ec2 ebs nvmeXnY devices to their original sdX/xvdX names
|
||||
when: device_is_nvme and device_is_awsebs|bool
|
||||
become: true
|
||||
block:
|
||||
- name: amazon | download nvme mapping binary helper
|
||||
ansible.builtin.get_url:
|
||||
url: "{{ ebsnvme_binary_helper_url }}"
|
||||
dest: "{{ ebsnvme_binary_helper_tmp }}/"
|
||||
mode: u=rw,g=r,o=r
|
||||
changed_when: false
|
||||
|
||||
- name: amazon | extract binary helper
|
||||
ansible.builtin.unarchive:
|
||||
src: "{{ ebsnvme_binary_helper_tmp }}/{{ ebsnvme_binary_helper_file }}"
|
||||
dest: "{{ ebsnvme_binary_helper_tmp }}/"
|
||||
remote_src: yes
|
||||
mode: 0755
|
||||
changed_when: false
|
||||
|
||||
- name: amazon | copy binary helper
|
||||
ansible.builtin.copy:
|
||||
src: "{{ ebsnvme_binary_helper_tmp }}/go-ebsnvme"
|
||||
dest: "{{ ebsnvme_binary_helper_path }}"
|
||||
mode: a+x
|
||||
remote_src: yes
|
||||
|
||||
- name: amazon | template script helper
|
||||
ansible.builtin.template:
|
||||
src: "ebsnvme-id.j2"
|
||||
dest: "{{ ebsnvme_scrip_helper_path }}"
|
||||
mode: a+x
|
||||
|
||||
- name: amazon | template udev rule
|
||||
ansible.builtin.template:
|
||||
src: "70-ec2-nvme-devices.rules.j2"
|
||||
dest: "/etc/udev/rules.d/70-ec2-nvme-devices.rules"
|
||||
mode: 0755
|
||||
register: udev_rule
|
||||
|
||||
- name: amazon | reload and trigger udev rules # noqa no-changed-when no-handler
|
||||
ansible.builtin.shell:
|
||||
cmd: udevadm control --reload-rules && udevadm trigger
|
||||
when: udev_rule.changed
|
||||
@@ -1,23 +1,70 @@
|
||||
---
|
||||
- name: centos | installing lvm2
|
||||
yum:
|
||||
name: "lvm2"
|
||||
- name: centos | installing lvm2 and sg3_utils
|
||||
ansible.builtin.package:
|
||||
name:
|
||||
- lvm2
|
||||
- sg3_utils
|
||||
state: present
|
||||
become: true
|
||||
|
||||
- name: Specific tasks for Amazon EC2
|
||||
ansible.builtin.include_tasks: amazon.yml
|
||||
when: ansible_facts.system_vendor == 'Amazon EC2'
|
||||
|
||||
- name: centos | debug lvg
|
||||
ansible.builtin.debug:
|
||||
var: lv
|
||||
verbosity: 3
|
||||
loop: "{{ lookup('subelements', lvm_groups, 'lvnames', {'skip_missing': True}, wantlist=True) }}"
|
||||
loop_control:
|
||||
loop_var: lv
|
||||
|
||||
- name: centos | install xfs tools
|
||||
ansible.builtin.package:
|
||||
name: "xfsprogs"
|
||||
state: "present"
|
||||
become: true
|
||||
loop: "{{ lookup('subelements', lvm_groups, 'lvnames', {'skip_missing': True}, wantlist=True) }}"
|
||||
loop_control:
|
||||
loop_var: lv
|
||||
when:
|
||||
- lv.1 is defined
|
||||
- lv.1 != "None"
|
||||
- lv.1.filesystem is defined
|
||||
- lv.1.filesystem == "xfs"
|
||||
- lv.1.create is defined
|
||||
- lv.1.create|bool
|
||||
|
||||
- name: centos | installing sg3_utils
|
||||
yum:
|
||||
name: "sg3_utils"
|
||||
state: "present"
|
||||
- name: centos | check for scsi adapters
|
||||
ansible.builtin.find:
|
||||
paths: "/sys/class/scsi_host"
|
||||
file_type: any
|
||||
become: true
|
||||
register: scsi_adapters
|
||||
|
||||
- name: centos | checking for scsi devices
|
||||
shell: "sg_scan"
|
||||
become: true
|
||||
register: "scsi_devices"
|
||||
changed_when: False
|
||||
- name: centos | Check for new disks
|
||||
when: scsi_adapters.matched > 0
|
||||
block:
|
||||
- name: centos | installing sg3_utils
|
||||
ansible.builtin.package:
|
||||
name: sg3_utils
|
||||
state: present
|
||||
become: true
|
||||
|
||||
- name: centos | rescanning for new disks
|
||||
command: "/usr/bin/rescan-scsi-bus.sh"
|
||||
become: true
|
||||
changed_when: False
|
||||
- name: centos | checking for scsi devices
|
||||
ansible.builtin.command: sg_scan
|
||||
become: true
|
||||
register: scsi_devices
|
||||
changed_when: false
|
||||
|
||||
- name: centos | rescanning for new disks
|
||||
ansible.builtin.command: "{{ rescan_scsi_command }}"
|
||||
become: true
|
||||
changed_when: false
|
||||
when: scsi_devices.stdout|length > 0
|
||||
|
||||
- name: centos | rescanning for resized disks
|
||||
ansible.builtin.command: "{{ rescan_scsi_command }} -s"
|
||||
become: true
|
||||
changed_when: false
|
||||
when: scsi_devices.stdout|length > 0
|
||||
|
||||
97
tasks/create_fs.yml
Normal file
97
tasks/create_fs.yml
Normal file
@@ -0,0 +1,97 @@
|
||||
---
|
||||
# unable to resize xfs: looks like we've to reference the mountpoint instead of the device
|
||||
- name: create_fs | check already converted
|
||||
# at least xfs is executed twice if the partition has changed in the meantime
|
||||
# then it tries to recreate the fs on the mounted fs which indeed fails...
|
||||
ansible.builtin.shell: "xfs_info {{ lv.mntp }} | grep -c 'ftype=1'"
|
||||
become: true
|
||||
register: mountedxfs
|
||||
ignore_errors: true
|
||||
changed_when: false
|
||||
when:
|
||||
- lv is defined and lv != 'None'
|
||||
- lv.filesystem is defined
|
||||
- lv.filesystem == "xfs"
|
||||
- lv.create is defined
|
||||
- lv.create|bool
|
||||
|
||||
- name: create_fs | unmounting filesystem(s)
|
||||
ansible.posix.mount:
|
||||
path: "{{ lv.mntp }}"
|
||||
src: "/dev/{{ vg.vgname }}/{{ lv.lvname }}"
|
||||
fstype: "{{ lv.filesystem | default(omit) }}"
|
||||
state: absent
|
||||
become: true
|
||||
when:
|
||||
- lv is defined
|
||||
- lv != 'None'
|
||||
- lv.create is defined
|
||||
- not lv.create|bool
|
||||
- lv.filesystem != "swap"
|
||||
|
||||
- name: create_fs | creating new filesystem on new LVM logical volume(s)
|
||||
community.general.filesystem:
|
||||
fstype: "{{ lv.filesystem }}"
|
||||
dev: "/dev/{{ vg.vgname }}/{{ lv.lvname }}"
|
||||
resizefs: yes
|
||||
become: true
|
||||
when:
|
||||
- vg.create is defined
|
||||
- vg.create|bool
|
||||
- lv is defined
|
||||
- lv != 'None'
|
||||
- lv.create is defined
|
||||
- lv.create|bool
|
||||
- lv.filesystem is defined
|
||||
- lv.filesystem != 'None'
|
||||
- lv.filesystem != 'swap'
|
||||
- lv.filesystem != 'xfs'
|
||||
|
||||
- name: create_fs | creating new xfs filesystem on new LVM logical volume(s)
|
||||
community.general.filesystem:
|
||||
fstype: "{{ lv.filesystem }}"
|
||||
dev: "/dev/{{ vg.vgname }}/{{ lv.lvname }}"
|
||||
opts: "{{ lv.fsopts | default(omit) }}"
|
||||
become: true
|
||||
when:
|
||||
- mountedxfs is failed
|
||||
- vg.create is defined
|
||||
- vg.create|bool
|
||||
- lv is defined
|
||||
- lv != 'None'
|
||||
- lv.create is defined
|
||||
- lv.create|bool
|
||||
- lv.filesystem is defined
|
||||
- lv.filesystem == 'xfs'
|
||||
|
||||
- name: create_fs | mounting new filesystem(s)
|
||||
ansible.posix.mount:
|
||||
path: "{{ lv.mntp }}"
|
||||
src: "/dev/{{ vg.vgname }}/{{ lv.lvname }}"
|
||||
fstype: "{{ lv.filesystem }}"
|
||||
state: mounted
|
||||
opts: "{{ lv.mopts | default('defaults') }}"
|
||||
become: true
|
||||
when:
|
||||
- vg.create is defined
|
||||
- vg.create|bool
|
||||
- lv is defined
|
||||
- lv != 'None'
|
||||
- lv.create is defined
|
||||
- lv.create|bool
|
||||
- lv.mount is defined
|
||||
- lv.mount|bool
|
||||
|
||||
- name: create_fs | resizing xfs filesystem on new LVM logical volume(s) # noqa no-changed-when
|
||||
ansible.builtin.command: "xfs_growfs {{ lv.mntp }}"
|
||||
become: true
|
||||
when:
|
||||
- vg.create is defined
|
||||
- vg.create|bool
|
||||
- lv is defined
|
||||
- lv != 'None'
|
||||
- lv.create is defined
|
||||
- lv.create|bool
|
||||
- lv.filesystem is defined
|
||||
- lv.filesystem == 'xfs'
|
||||
- lvchanged.changed
|
||||
30
tasks/create_lv.yml
Normal file
30
tasks/create_lv.yml
Normal file
@@ -0,0 +1,30 @@
|
||||
---
|
||||
- name: create_lv | Display Volume Group
|
||||
ansible.builtin.debug:
|
||||
var: vg
|
||||
verbosity: 2
|
||||
|
||||
- name: create_lv | creating new LVM logical volume(s)
|
||||
community.general.lvol:
|
||||
vg: "{{ vg.vgname }}"
|
||||
lv: "{{ lv.lvname }}"
|
||||
size: "{{ lv.size }}"
|
||||
shrink: false
|
||||
opts: "{{ lv.opts | default('') }}"
|
||||
state: present
|
||||
become: true
|
||||
register: lvchanged
|
||||
when:
|
||||
- vg.create is defined
|
||||
- vg.create|bool
|
||||
- lv is defined
|
||||
- lv != 'None'
|
||||
- lv.create is defined
|
||||
- lv.create|bool
|
||||
|
||||
- name: create_lv | debug changed attribute
|
||||
ansible.builtin.debug:
|
||||
var: lvchanged
|
||||
|
||||
- name: create_lv | configuring FS
|
||||
ansible.builtin.include_tasks: create_fs.yml
|
||||
17
tasks/create_vg.yml
Normal file
17
tasks/create_vg.yml
Normal file
@@ -0,0 +1,17 @@
|
||||
---
|
||||
- name: create_vg | creating new LVM volume group(s)
|
||||
community.general.lvg:
|
||||
vg: "{{ vg.vgname }}"
|
||||
pvs: "{{ vg.disks | join(',') }}"
|
||||
state: present
|
||||
pvresize: "{{ vg.pvresize | default(pvresize_to_max) }}"
|
||||
become: true
|
||||
when:
|
||||
- vg.create is defined
|
||||
- vg.create|bool
|
||||
|
||||
- name: manage_lvm | loop over logical volume group(s) to create logical volumes
|
||||
ansible.builtin.include_tasks: create_lv.yml
|
||||
loop: "{{ vg.lvnames | default([]) }}"
|
||||
loop_control:
|
||||
loop_var: lv
|
||||
@@ -1,22 +1,40 @@
|
||||
---
|
||||
- name: debian | installing pre-reqs
|
||||
apt:
|
||||
name: "{{ item }}"
|
||||
state: "present"
|
||||
- name: debian | Updating Apt Cache
|
||||
ansible.builtin.apt:
|
||||
update_cache: true
|
||||
cache_valid_time: 3600
|
||||
become: true
|
||||
with_items:
|
||||
- 'lvm2'
|
||||
- 'scsitools'
|
||||
- 'xfsprogs'
|
||||
|
||||
- name: debian | installing pre-reqs
|
||||
ansible.builtin.apt:
|
||||
name:
|
||||
- lvm2
|
||||
- scsitools
|
||||
state: present
|
||||
become: true
|
||||
|
||||
- name: debian | install xfs tools
|
||||
ansible.builtin.apt:
|
||||
name: xfsprogs
|
||||
state: present
|
||||
become: true
|
||||
loop: "{{ lvm_groups | subelements('lvnames') }}"
|
||||
when:
|
||||
- item.1 is defined
|
||||
- item.1 != 'None'
|
||||
- item.1.filesystem is defined
|
||||
- item.1.filesystem == "xfs"
|
||||
- item.1.create is defined
|
||||
- item.1.create|bool
|
||||
|
||||
- name: debian | checking for scsi devices
|
||||
shell: "sg_scan"
|
||||
ansible.builtin.command: sg_scan
|
||||
become: true
|
||||
register: "scsi_devices"
|
||||
changed_when: False
|
||||
register: scsi_devices
|
||||
changed_when: false
|
||||
|
||||
- name: debian | rescanning for new disks added
|
||||
command: "/sbin/rescan-scsi-bus"
|
||||
ansible.builtin.command: "{{ rescan_scsi_command }}"
|
||||
become: true
|
||||
changed_when: False
|
||||
when: scsi_devices['stdout'] != ""
|
||||
changed_when: false
|
||||
when: scsi_devices['stdout'] | length > 0
|
||||
|
||||
@@ -1,12 +1,23 @@
|
||||
---
|
||||
# tasks file for ansible-manage-lvm
|
||||
- include: debian.yml
|
||||
when: ansible_os_family == "Debian"
|
||||
- name: Set rescan_scsi_command for old debian version
|
||||
ansible.builtin.set_fact:
|
||||
rescan_scsi_command: "/sbin/rescan-scsi-bus"
|
||||
when:
|
||||
- ansible_facts.distribution | replace(' ','') | lower == 'debian'
|
||||
- ansible_facts.distribution_release not in ('bookworm', 'sid')
|
||||
- ansible_facts.distribution_major_version is version(10, '<=')
|
||||
|
||||
- include: centos.yml
|
||||
when: ansible_os_family == "RedHat"
|
||||
- name: Debian specific tasks
|
||||
ansible.builtin.include_tasks: debian.yml
|
||||
when: ansible_facts.os_family == "Debian"
|
||||
|
||||
- include: manage_lvm.yml
|
||||
when: >
|
||||
manage_lvm and
|
||||
lvm_groups is defined
|
||||
- name: RHEL specific tasks
|
||||
ansible.builtin.include_tasks: centos.yml
|
||||
when: ansible_facts.os_family == "RedHat"
|
||||
|
||||
- name: Manage LVM
|
||||
ansible.builtin.include_tasks: manage_lvm.yml
|
||||
when:
|
||||
- lvm_groups is defined
|
||||
- manage_lvm|bool
|
||||
|
||||
@@ -1,162 +1,31 @@
|
||||
---
|
||||
- name: manage_lvm | creating new LVM volume group(s)
|
||||
lvg:
|
||||
vg: "{{ item['vgname'] }}"
|
||||
pvs: "{{ item['disks']|join(',') }}"
|
||||
state: "present"
|
||||
become: true
|
||||
with_items: "{{ lvm_groups }}"
|
||||
when: >
|
||||
(item['create'] is defined and
|
||||
item['create'])
|
||||
|
||||
- name: manage_lvm | creating new LVM logical volume(s)
|
||||
lvol:
|
||||
vg: "{{ item[0]['vgname'] }}"
|
||||
lv: "{{ item[1]['lvname'] }}"
|
||||
size: "{{ item[1]['size'] }}"
|
||||
shrink: no
|
||||
opts: "{{ item[1]['opts'] | default('') }}"
|
||||
state: "present"
|
||||
become: true
|
||||
register: lvm
|
||||
with_subelements:
|
||||
- "{{ lvm_groups }}"
|
||||
- lvnames
|
||||
when: >
|
||||
((item[0]['create'] is defined
|
||||
and item[0]['create']) and
|
||||
(item[1] is defined and
|
||||
item[1] != 'None') and
|
||||
(item[1]['create'] is defined and
|
||||
item[1]['create']))
|
||||
|
||||
- name: manage_lvm | creating new filesystem on new LVM logical volume(s)
|
||||
filesystem:
|
||||
fstype: "{{ item[1]['filesystem'] }}"
|
||||
dev: "/dev/{{ item[0]['vgname'] }}/{{ item[1]['lvname'] }}"
|
||||
# resizefs: yes #coming in 2.0 which will replace the resizing filesystem task below
|
||||
become: true
|
||||
with_subelements:
|
||||
- "{{ lvm_groups }}"
|
||||
- lvnames
|
||||
when: >
|
||||
((item[0]['create'] is defined and
|
||||
item[0]['create']) and
|
||||
(item[1] is defined and
|
||||
item[1] != 'None') and
|
||||
(item[1]['create'] is defined and
|
||||
item[1]['create']) and
|
||||
(item[1]['filesystem'] is defined and
|
||||
item[1]['filesystem'] != 'None'))
|
||||
|
||||
- name: manage_lvm | mounting new filesystem(s)
|
||||
mount:
|
||||
name: "{{ item[1]['mntp'] }}"
|
||||
src: "/dev/{{ item[0]['vgname'] }}/{{ item[1]['lvname'] }}"
|
||||
fstype: "{{ item[1]['filesystem'] }}"
|
||||
state: "mounted"
|
||||
opts: "{{ item[1]['mopts'] | default('defaults') }}"
|
||||
become: true
|
||||
with_subelements:
|
||||
- "{{ lvm_groups }}"
|
||||
- lvnames
|
||||
when: >
|
||||
((item[0]['create'] is defined and
|
||||
item[0]['create']) and
|
||||
(item[1] is defined and
|
||||
item[1] != 'None') and
|
||||
(item[1]['create'] is defined and
|
||||
item[1]['create']) and
|
||||
(item[1]['mount'] is defined and
|
||||
item[1]['mount']))
|
||||
|
||||
- name: manage_lvm | resizing filesystem
|
||||
command: resize2fs /dev/{{ item[0]['vgname'] }}/{{ item[1]['lvname'] }}
|
||||
become: true
|
||||
with_subelements:
|
||||
- "{{ lvm_groups }}"
|
||||
- lvnames
|
||||
when: >
|
||||
lvm['changed'] and
|
||||
item[1]['filesystem'] is defined and
|
||||
item[1]['filesystem'] != "None" and
|
||||
item[1]['filesystem'] != "swap" and
|
||||
item[1]['filesystem'] != "xfs" and
|
||||
item[1]['filesystem'] != "btrfs"
|
||||
|
||||
- name: manage_lvm | resizing xfs
|
||||
command: xfs_growfs -d /dev/{{ item[0]['vgname'] }}/{{ item[1]['lvname'] }}
|
||||
become: true
|
||||
with_subelements:
|
||||
- "{{ lvm_groups }}"
|
||||
- lvnames
|
||||
when: >
|
||||
lvm['changed'] and
|
||||
item[1]['filesystem'] is defined and
|
||||
item[1]['filesystem'] == "xfs"
|
||||
|
||||
- name: manage_lvm | resizing swap
|
||||
shell: "swapoff -a && mkswap /dev/{{ item[0]['vgname'] }}/{{ item[1]['lvname'] }} && swapon -va"
|
||||
become: true
|
||||
with_subelements:
|
||||
- "{{ lvm_groups }}"
|
||||
- lvnames
|
||||
when: >
|
||||
lvm['changed'] and
|
||||
item[1]['filesystem'] is defined and
|
||||
item[1]['filesystem'] == "swap"
|
||||
|
||||
- name: manage_lvm | resizing btrfs
|
||||
shell: "btrfs filesystem resize max {{ item[1]['mntp'] }}"
|
||||
become: true
|
||||
with_subelements:
|
||||
- "{{ lvm_groups }}"
|
||||
- lvnames
|
||||
when: >
|
||||
lvm['changed'] and
|
||||
item[1]['filesystem'] is defined and
|
||||
item[1]['filesystem'] == "btrfs"
|
||||
|
||||
- name: manage_lvm | unmounting filesystem(s)
|
||||
mount:
|
||||
name: "{{ item[1]['mntp'] }}"
|
||||
src: "/dev/{{ item[0]['vgname'] }}/{{ item[1]['lvname'] }}"
|
||||
fstype: "{{ item[1]['filesystem'] | default(omit) }}"
|
||||
state: "absent"
|
||||
become: true
|
||||
with_subelements:
|
||||
- "{{ lvm_groups }}"
|
||||
- lvnames
|
||||
when: >
|
||||
(item[1] is defined and
|
||||
item[1] != 'None') and
|
||||
(item[1]['create'] is defined and
|
||||
not item[1]['create'])
|
||||
- name: manage_lvm | manage physical volume group creation
|
||||
ansible.builtin.include_tasks: create_vg.yml
|
||||
loop: "{{ lvm_groups }}"
|
||||
loop_control:
|
||||
loop_var: vg
|
||||
|
||||
- name: manage_lvm | Removing LVM logical volume(s)
|
||||
lvol:
|
||||
vg: "{{ item[0]['vgname'] }}"
|
||||
lv: "{{ item[1]['lvname'] }}"
|
||||
state: "absent"
|
||||
force: yes
|
||||
community.general.lvol:
|
||||
vg: "{{ item.0.vgname }}"
|
||||
lv: "{{ item.1.lvname }}"
|
||||
state: absent
|
||||
force: true
|
||||
become: true
|
||||
with_subelements:
|
||||
- "{{ lvm_groups }}"
|
||||
- lvnames
|
||||
when: >
|
||||
(item[1] is defined and
|
||||
item[1] != 'None') and
|
||||
(item[1]['create'] is defined and
|
||||
not item[1]['create'])
|
||||
loop: "{{ lvm_groups | subelements('lvnames', {'skip_missing': true}) }}"
|
||||
when:
|
||||
- item.1 is defined
|
||||
- item.1 != 'None'
|
||||
- item.1.create is defined
|
||||
- not item.1.create|bool
|
||||
|
||||
- name: manage_lvm | Removing LVM volume group(s)
|
||||
lvg:
|
||||
vg: "{{ item['vgname'] }}"
|
||||
pvs: "{{ item['disks']|join(',') }}"
|
||||
state: "absent"
|
||||
community.general.lvg:
|
||||
vg: "{{ item.vgname }}"
|
||||
pvs: "{{ item.disks | join(',') }}"
|
||||
state: absent
|
||||
become: true
|
||||
with_items: "{{ lvm_groups }}"
|
||||
when: >
|
||||
item['create'] is defined and
|
||||
not item['create']
|
||||
loop: "{{ lvm_groups }}"
|
||||
when:
|
||||
- item.create is defined
|
||||
- not item.create|bool
|
||||
|
||||
2
templates/70-ec2-nvme-devices.rules.j2
Normal file
2
templates/70-ec2-nvme-devices.rules.j2
Normal file
@@ -0,0 +1,2 @@
|
||||
# ebs nvme to scsi device naming mapping
|
||||
KERNEL=="nvme[0-9]*n[0-9]*", ENV{DEVTYPE}=="disk", ATTRS{model}=="Amazon Elastic Block Store", PROGRAM="{{ ebsnvme_scrip_helper_path }} /dev/%k", SYMLINK+="%c"
|
||||
14
templates/ebsnvme-id.j2
Normal file
14
templates/ebsnvme-id.j2
Normal file
@@ -0,0 +1,14 @@
|
||||
#!/bin/bash
|
||||
# This script uses go version of ebsnvme-id to provide
|
||||
# SCSI Disk device name links for nvme devices
|
||||
#
|
||||
# links:
|
||||
#
|
||||
# https://www.logicworks.com/blog/2018/03/manage-aws-ebs-volumes-c5-m5-puppet-chef-ansible/
|
||||
# https://github.com/mvisonneau/go-ebsnvme
|
||||
# https://gist.github.com/lbernail/d851e5b06eb32180a4b8ead2ce4f45db
|
||||
# and working forks like:
|
||||
# (keenan-v1/ebsnvme-id) https://gist.github.com/keenan-v1/aee92cd7383ee02de2a817a004917a03
|
||||
#
|
||||
|
||||
{{ ebsnvme_binary_helper_path }} -n $1 | awk -F '/' '{print $3}'
|
||||
1
tests/.ansible-lint
Normal file
1
tests/.ansible-lint
Normal file
@@ -0,0 +1 @@
|
||||
skip_list: ['305', '503', '602']
|
||||
27
tests/Dockerfile.centos-7
Normal file
27
tests/Dockerfile.centos-7
Normal file
@@ -0,0 +1,27 @@
|
||||
FROM centos:7
|
||||
ENV container=docker
|
||||
|
||||
RUN yum -y install epel-release && \
|
||||
yum -y install gmp-devel libffi-devel openssl-devel python-crypto \
|
||||
python-devel python-pip python-setuptools python-virtualenv \
|
||||
redhat-rpm-config && \
|
||||
yum -y group install "Development Tools"
|
||||
|
||||
# Install systemd -- See https://hub.docker.com/_/centos/
|
||||
RUN (cd /lib/systemd/system/sysinit.target.wants/; for i in *; do [ $i == systemd-tmpfiles-setup.service ] || rm -f $i; done); \
|
||||
rm -f /lib/systemd/system/multi-user.target.wants/*;\
|
||||
rm -f /etc/systemd/system/*.wants/*;\
|
||||
rm -f /lib/systemd/system/local-fs.target.wants/*; \
|
||||
rm -f /lib/systemd/system/sockets.target.wants/*udev*; \
|
||||
rm -f /lib/systemd/system/sockets.target.wants/*initctl*; \
|
||||
rm -f /lib/systemd/system/basic.target.wants/*;\
|
||||
rm -f /lib/systemd/system/anaconda.target.wants/*;
|
||||
|
||||
RUN pip install enum34 ipaddress wheel && \
|
||||
pip install ansible ansible-lint
|
||||
|
||||
COPY .ansible-lint /
|
||||
|
||||
VOLUME ["/sys/fs/cgroup"]
|
||||
|
||||
CMD ["/usr/sbin/init"]
|
||||
13
tests/Dockerfile.debian-stretch
Normal file
13
tests/Dockerfile.debian-stretch
Normal file
@@ -0,0 +1,13 @@
|
||||
FROM debian:stretch
|
||||
ENV container=docker
|
||||
|
||||
RUN apt-get update && \
|
||||
apt-get install -y --no-install-recommends build-essential libffi-dev \
|
||||
libssl-dev python-dev python-minimal python-pip python-setuptools \
|
||||
python-virtualenv systemd && \
|
||||
rm -rf /var/lib/apt/lists/*
|
||||
|
||||
RUN pip install enum34 ipaddress wheel && \
|
||||
pip install ansible ansible-lint
|
||||
|
||||
COPY .ansible-lint /
|
||||
26
tests/Dockerfile.fedora-25
Normal file
26
tests/Dockerfile.fedora-25
Normal file
@@ -0,0 +1,26 @@
|
||||
FROM fedora:25
|
||||
ENV container=docker
|
||||
|
||||
RUN dnf -y install gmp-devel libffi-devel openssl-devel python-crypto \
|
||||
python-devel python-dnf python-pip python-setuptools python-virtualenv \
|
||||
redhat-rpm-config systemd && \
|
||||
dnf -y group install "C Development Tools and Libraries"
|
||||
|
||||
# Install systemd -- See https://hub.docker.com/_/centos/
|
||||
RUN (cd /lib/systemd/system/sysinit.target.wants/; for i in *; do [ $i == systemd-tmpfiles-setup.service ] || rm -f $i; done); \
|
||||
rm -f /lib/systemd/system/multi-user.target.wants/*;\
|
||||
rm -f /etc/systemd/system/*.wants/*;\
|
||||
rm -f /lib/systemd/system/local-fs.target.wants/*; \
|
||||
rm -f /lib/systemd/system/sockets.target.wants/*udev*; \
|
||||
rm -f /lib/systemd/system/sockets.target.wants/*initctl*; \
|
||||
rm -f /lib/systemd/system/basic.target.wants/*;\
|
||||
rm -f /lib/systemd/system/anaconda.target.wants/*;
|
||||
|
||||
RUN pip install enum34 ipaddress wheel && \
|
||||
pip install ansible ansible-lint
|
||||
|
||||
COPY .ansible-lint /
|
||||
|
||||
VOLUME ["/sys/fs/cgroup"]
|
||||
|
||||
CMD ["/usr/sbin/init"]
|
||||
26
tests/Dockerfile.fedora-26
Normal file
26
tests/Dockerfile.fedora-26
Normal file
@@ -0,0 +1,26 @@
|
||||
FROM fedora:26
|
||||
ENV container=docker
|
||||
|
||||
RUN dnf -y install gmp-devel libffi-devel openssl-devel python-crypto \
|
||||
python-devel python-dnf python-pip python-setuptools python-virtualenv \
|
||||
redhat-rpm-config systemd && \
|
||||
dnf -y group install "C Development Tools and Libraries"
|
||||
|
||||
# Install systemd -- See https://hub.docker.com/_/centos/
|
||||
RUN (cd /lib/systemd/system/sysinit.target.wants/; for i in *; do [ $i == systemd-tmpfiles-setup.service ] || rm -f $i; done); \
|
||||
rm -f /lib/systemd/system/multi-user.target.wants/*;\
|
||||
rm -f /etc/systemd/system/*.wants/*;\
|
||||
rm -f /lib/systemd/system/local-fs.target.wants/*; \
|
||||
rm -f /lib/systemd/system/sockets.target.wants/*udev*; \
|
||||
rm -f /lib/systemd/system/sockets.target.wants/*initctl*; \
|
||||
rm -f /lib/systemd/system/basic.target.wants/*;\
|
||||
rm -f /lib/systemd/system/anaconda.target.wants/*;
|
||||
|
||||
RUN pip install enum34 ipaddress wheel && \
|
||||
pip install ansible ansible-lint
|
||||
|
||||
COPY .ansible-lint /
|
||||
|
||||
VOLUME ["/sys/fs/cgroup"]
|
||||
|
||||
CMD ["/usr/sbin/init"]
|
||||
13
tests/Dockerfile.ubuntu-bionic
Normal file
13
tests/Dockerfile.ubuntu-bionic
Normal file
@@ -0,0 +1,13 @@
|
||||
FROM ubuntu:bionic
|
||||
ENV container=docker
|
||||
|
||||
RUN apt-get update && \
|
||||
apt-get install -y --no-install-recommends build-essential libffi-dev \
|
||||
libssl-dev python-dev python-minimal python-pip python-setuptools \
|
||||
python-virtualenv systemd && \
|
||||
rm -rf /var/lib/apt/lists/*
|
||||
|
||||
RUN pip install enum34 ipaddress wheel && \
|
||||
pip install ansible ansible-lint
|
||||
|
||||
COPY .ansible-lint /
|
||||
13
tests/Dockerfile.ubuntu-xenial
Normal file
13
tests/Dockerfile.ubuntu-xenial
Normal file
@@ -0,0 +1,13 @@
|
||||
FROM ubuntu:xenial
|
||||
ENV container=docker
|
||||
|
||||
RUN apt-get update && \
|
||||
apt-get install -y --no-install-recommends build-essential libffi-dev \
|
||||
libssl-dev python-dev python-minimal python-pip python-setuptools \
|
||||
python-virtualenv && \
|
||||
rm -rf /var/lib/apt/lists/*
|
||||
|
||||
RUN pip install enum34 ipaddress wheel && \
|
||||
pip install ansible ansible-lint
|
||||
|
||||
COPY .ansible-lint /
|
||||
1
tests/inventory
Normal file
1
tests/inventory
Normal file
@@ -0,0 +1 @@
|
||||
localhost
|
||||
6
tests/test.yml
Normal file
6
tests/test.yml
Normal file
@@ -0,0 +1,6 @@
|
||||
---
|
||||
# - name: Test role
|
||||
# hosts: localhost
|
||||
# connection: local
|
||||
# roles:
|
||||
# - role: ansible-manage-lvm
|
||||
@@ -1,2 +1,7 @@
|
||||
---
|
||||
# vars file for ansible-manage-lvm
|
||||
|
||||
ebsnvme_binary_helper_file: go-ebsnvme_{{ ebsnvme_binary_helper_ver }}_linux_amd64.tar.gz
|
||||
ebsnvme_binary_helper_url: https://github.com/mvisonneau/go-ebsnvme/releases/download/{{ ebsnvme_binary_helper_ver }}/{{ ebsnvme_binary_helper_file }}
|
||||
|
||||
rescan_scsi_command: "/usr/bin/rescan-scsi-bus.sh"
|
||||
|
||||
Reference in New Issue
Block a user