Compare commits

...

48 Commits

Author SHA1 Message Date
Larry Smith Jr f1a54639c6 Merge pull request #48 from Tcharl/rebased
XFS resize
2020-06-07 20:05:35 -04:00
Larry Smith Jr 88489df0ac Merge pull request #45 from OsgiliathEnterprise/master
Allow to define only volume groups
2020-06-07 20:05:22 -04:00
Charlie Mordant b288695b9a lint 2020-06-07 17:25:33 +02:00
Charlie Mordant ed0eb14ce8 xfs resize 2020-06-07 17:17:48 +02:00
Charlie Mordant 9c04be9046 Merge pull request #14 from OsgiliathEnterprise/rebased
Rebased from upstream
2020-05-15 00:03:37 +02:00
Charlie Mordant 96fd3b2b06 rebase done 2020-05-14 23:46:35 +02:00
Charlie Mordant 15b2b7b4e0 rebased mrjsmith 2020-05-14 23:43:59 +02:00
Larry Smith Jr 9ead2c9b18 Merge pull request #38 from mrlesmithjr/issue-37
Issue 37
2020-05-14 09:52:39 -04:00
Charlie Mordant 79f4787208 Merge pull request #13 from Tcharl/master
Merge pull request #5 from Tcharl/id2
2020-05-11 18:44:01 +02:00
Charlie Mordant 94582de25d use symbolic links instead of replicating files 2020-05-11 17:38:02 +02:00
Charlie Mordant 6ee72799b4 improve tests 2020-05-11 17:09:58 +02:00
Charlie Mordant 69e25effd4 improve tests 2020-05-11 16:56:04 +02:00
Charlie Mordant 62fc5a5e2b testing singl lv and only vg 2020-05-11 16:35:31 +02:00
Charlie Mordant c40f9b7d03 testing singl lv and only vg 2020-05-11 16:35:00 +02:00
Charlie Mordant 0621cadde8 avoid error when lv not defined 2020-05-11 14:36:04 +02:00
Charlie Mordant b7cef8e323 avoid error when lv not defined 2020-05-11 14:26:48 +02:00
Charlie Mordant 59ffcfac4a avoid error when lv not defined 2020-05-11 14:23:32 +02:00
Charlie Mordant 976ff31d00 avoid error when lv not defined 2020-05-11 14:21:02 +02:00
Charlie Mordant 78205e51cb Merge pull request #12 from Tcharl/id2
rename manage_lvm.yml due to recursive parsing error
2020-05-11 13:53:03 +02:00
Charlie Mordant b731c20100 rename manage_lvm.yml due to recursive parsing error 2020-05-11 13:51:45 +02:00
Charlie Mordant f2df804926 Merge pull request #11 from OsgiliathEnterprise/id2
Id2
2020-05-11 13:39:16 +02:00
Larry Smith Jr 9f37fa3ed1 Cleaned up tasks
These changes include:
- Cleaning up logic of conditionals for more clarity
- Naming of tasks as some were either missing or incorrect
- Removing unnecessary parens, etc.
- Closes #37
2020-04-27 13:50:00 -04:00
Larry Smith Jr c9a9e1660e Cleaned up conditionals logic 2020-04-27 13:47:43 -04:00
Larry Smith Jr ec0737d26b Cleaned up distro specific tasks
- Cleaned up conditions, etc.
2020-04-27 13:47:40 -04:00
Larry Smith Jr 52c0270a53 Updated Molecule Vagrant boxes for testing
- We need to test against CentOS, Fedora, and Ubuntu
- Added my Vagrant boxes to ensure that we know what is included, etc.
- This ensures we can at least test these distros locally
2020-04-27 13:46:08 -04:00
Larry Smith Jr 94be28c09b Updated repo info 2020-04-27 13:43:46 -04:00
Larry Smith Jr a6b07da847 Added example playbook 2020-04-27 13:43:46 -04:00
Larry Smith Jr 643c7b6ee1 Updated Galaxy meta info 2020-04-27 13:43:46 -04:00
Larry Smith Jr b7c3cf9f75 Merge pull request #44 from mrlesmithjr/issue-42
Fix original issue
2020-04-27 13:41:35 -04:00
Larry Smith Jr e423ebd56b Fix original issue
- The previous patch did not resolve the original issue raised. This now
  works and has been tested with the configuration provided as part of
  the open issue.

- Resolves #42
2020-04-27 13:39:59 -04:00
Larry Smith Jr 9eca9e391b Merge pull request #43 from mrlesmithjr/issue-42
Issue 42
2020-04-27 11:58:16 -04:00
Larry Smith Jr 881d5d77fa Fixing syntax issue for wantlist 2020-04-27 11:26:18 -04:00
Larry Smith Jr 89360e3ffe Trying to fix the subelements lookup for a single element
This addresses #42. Will need to do some validation testing, etc.
2020-04-27 11:16:02 -04:00
Larry Smith Jr 5267237c5e Merge pull request #41 from OsgiliathEnterprise/master
Fix xfs package installation win centos environment | travis-molecule-kvm tests
2020-04-26 01:20:28 -04:00
Charlie Mordant eda544042a Merge pull request #10 from Tcharl/id2
remove unused molecule env property
2020-04-24 17:23:27 +02:00
Charlie Mordant c6a7034e4b remove unused molecule env property 2020-04-24 17:22:07 +02:00
Charlie Mordant 1e997a3e80 Merge pull request #5 from Tcharl/id2
xfs support on centos
2020-04-23 19:56:02 +02:00
Charlie Mordant 816d44a6a1 Merge pull request #9 from Tcharl/id2
add molecule tests, fix xfs installation
2020-04-23 19:52:08 +02:00
Charlie Mordant 883055c33f lint 2020-04-23 19:38:35 +02:00
Charlie Mordant 4697b37377 Merge pull request #8 from Tcharl/master
enable molecule tests
2020-04-23 19:36:15 +02:00
Charlie Mordant 325c2d6240 install xfs 2020-04-23 19:25:09 +02:00
Charlie Mordant db21878de4 Merge pull request #4 from Tcharl/id2
Id2
2020-04-21 19:06:23 +02:00
Charlie Mordant d3256a3a5a Merge pull request #3 from Tcharl/id2
code smells
2020-04-17 13:13:37 +02:00
Charlie Mordant 6c13d12494 Merge pull request #2 from Tcharl/id2
typo in check
2020-04-15 19:09:33 +02:00
Charlie Mordant dc1ad5a6f8 Merge pull request #1 from Tcharl/id2
avoid reexecution of xfs creation
2020-04-15 19:01:39 +02:00
Charlie Mordant 1a648317c7 Merge pull request #3 from OsgiliathEnterprise/id2
makes xfs mountpoint repeatable
2020-04-15 18:54:40 +02:00
Charlie Mordant c3fea6e456 Merge pull request #2 from OsgiliathEnterprise/id2
mistake on remove volume
2020-04-15 17:36:01 +02:00
Charlie Mordant 12c4dad6e0 Merge pull request #1 from OsgiliathEnterprise/id2
Xfs support
2020-04-15 17:14:12 +02:00
28 changed files with 563 additions and 456 deletions
+1 -60
View File
@@ -34,67 +34,8 @@ jobs:
sudo apt update sudo apt update
sudo apt -y install python3-setuptools python3 python3-pip docker vagrant sudo apt -y install python3-setuptools python3 python3-pip docker vagrant
sudo pip3 install wheel sudo pip3 install wheel
sudo pip3 install docker molecule testinfra yamllint ansible-lint flake8 molecule-vagrant sudo pip3 install molecule testinfra yamllint ansible-lint flake8 molecule-vagrant
- name: molecule lint - name: molecule lint
run: | run: |
molecule lint molecule lint
molecule:
runs-on: ubuntu-latest
if: "false"
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
- uses: actions/checkout@v2
- name: configure keyboard layout
run: |
echo XKBLAYOUT='us' > /etc/default/keyboard
- name: install virtualization stack
env:
DEBIAN_FRONTEND: noninteractive
run: |
sudo apt-get update
sudo apt -y install cpu-checker
kvm-ok
# shit happens here, containerization sucks... that was worth the try
- name: install virtualization stack
env:
DEBIAN_FRONTEND: noninteractive
run: |
sudo apt -y install policycoreutils-python-utils qemu-kvm qemu-utils libvirt-clients libvirt-daemon-system bridge-utils python3-libvirt libnss-libvirt libguestfs-tools virtinst virt-top genisoimage libvirt-dev libvirt-bin
- name: install vagrant
env:
VAGRANT_DISABLE_STRICT_DEPENDENCY_ENFORCEMENT: 1
run: |
wget https://releases.hashicorp.com/vagrant/2.2.7/vagrant_2.2.7_x86_64.deb
sudo apt -y install ./vagrant_2.2.7_x86_64.deb
vagrant plugin install vagrant-persistent-storage
vagrant plugin install vagrant-libvirt
sudo groupadd --system libvirt
sudo usermod -a -G libvirt $(whoami)
sudo /etc/init.d/libvirtd restart
- name: Install molecule
run: |
sudo apt -y install python3-setuptools
pip3 install molecule-vagrant wheel
- name: create molecule vm
env:
LC_ALL: C.UTF-8
LANG: C.UTF-8
run: |
molecule create --scenario-name kvm
- name: verify
run: |
molecule verify
- name: teardown
run: |
molecule destroy
+26 -9
View File
@@ -1,15 +1,32 @@
--- ---
sudo: required dist: bionic
language: python language: python
services: python:
- docker - "3.8"
before_install: before_install:
- sudo apt-get -qq update - |
install: sudo apt -y install bridge-utils dnsmasq-base ebtables libvirt-bin libvirt-dev qemu-kvm qemu-utils ruby-dev
- pip3 install -r requirements.txt
- ansible --version - |
- molecule --version wget https://releases.hashicorp.com/vagrant/2.2.7/vagrant_2.2.7_x86_64.deb
sudo apt -y install ./vagrant_2.2.7_x86_64.deb
sudo vagrant plugin install vagrant-libvirt
- |
sudo apt-get -y purge python3-openssl && sudo apt-get -y autoremove
sudo apt-get update && sudo apt-get install -y ca-certificates curl gcc iproute2 python3 python3-dev sudo
curl -skL https://bootstrap.pypa.io/get-pip.py | sudo -H python3
sudo pip3 install wheel
sudo pip3 install netaddr python-vagrant yamllint testinfra flake8
sudo pip3 install ansible ansible-lint
sudo pip3 install -I molecule molecule-vagrant
script: script:
- molecule lint - |
sudo molecule test --scenario-name kvm
sudo molecule test --scenario-name kvmsinglelv
sudo molecule test --scenario-name kvmonlyvg
notifications: notifications:
webhooks: https://galaxy.ansible.com/api/v1/notifications/ webhooks: https://galaxy.ansible.com/api/v1/notifications/
+44
View File
@@ -1,3 +1,47 @@
commit 881d5d77fa435ccaa026c3341d0d2ac1fb537b98
Author: Larry Smith Jr <mrlesmithjr@gmail.com>
Date: Mon Apr 27 11:26:18 2020 -0400
Fixing syntax issue for wantlist
commit 89360e3ffef9ff1dbbb5ad525a7ee1d77e6b8895
Author: Larry Smith Jr <mrlesmithjr@gmail.com>
Date: Mon Apr 27 11:16:02 2020 -0400
Trying to fix the subelements lookup for a single element
This addresses #42. Will need to do some validation testing, etc.
commit c6a7034e4b0b381c5c5b44a15ce7baad7eab9c1b
Author: Charlie Mordant <cmordant1@gmail.com>
Date: Fri Apr 24 17:22:07 2020 +0200
remove unused molecule env property
commit 883055c33f2d6b4c0df8e61ce49771c451905334
Author: Charlie Mordant <cmordant1@gmail.com>
Date: Thu Apr 23 19:38:35 2020 +0200
lint
commit 325c2d6240022fe17abf40dffee842ccf79543f1
Author: Charlie Mordant <cmordant1@gmail.com>
Date: Thu Apr 23 19:25:09 2020 +0200
install xfs
commit 4a1177e420fd9632f77d07ce0a19f89a1515f8eb
Author: Charlie Mordant <cmordant1@gmail.com>
Date: Tue Apr 21 19:01:29 2020 +0200
use xfs_info on mountpoint instead of lvm
commit 7fd5a8eec9f4b5110929862056ab88c4db3f14de
Author: Larry Smith Jr <mrlesmithjr@gmail.com>
Date: Sun Apr 19 01:59:29 2020 -0400
Only doing a Molecule lint at this time
commit 7e2a076b0a8155015fd21502db860fa89a2114b3 commit 7e2a076b0a8155015fd21502db860fa89a2114b3
Author: Larry Smith Jr <mrlesmithjr@gmail.com> Author: Larry Smith Jr <mrlesmithjr@gmail.com>
Date: Sun Apr 19 01:44:38 2020 -0400 Date: Sun Apr 19 01:44:38 2020 -0400
+8 -109
View File
@@ -1,6 +1,6 @@
# 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. > NOTE: Can be used to create, extend or resize LVM Groups and volumes.
@@ -9,78 +9,9 @@ An [Ansible] role to manage LVM Groups/Logical Volumes.
Devices/disks to be members of the LVM setup **must be** identified prior to Devices/disks to be members of the LVM setup **must be** identified prior to
using this role. 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 ## Role Variables
```yaml [defaults/main.yml](defaults/main.yml)
---
# 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
```
## Dependencies ## Dependencies
@@ -88,48 +19,16 @@ None
## Example Playbook ## Example Playbook
```yaml [playbook.yml](playbook.yml)
---
- 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:
```
## License ## License
BSD MIT
## Author Information ## Author Information
Larry Smith Jr. Larry Smith Jr.
- [@mrlesmithjr] - [@mrlesmithjr](https://twitter.com/mrlesmithjr)
- <http://everythingshouldbevirtual.com> - [mrlesmithjr@gmail.com](mailto:mrlesmithjr@gmail.com)
- mrlesmithjr [at] gmail.com - [http://everythingshouldbevirtual.com](http://everythingshouldbevirtual.com)
[@mrlesmithjr]: https://www.twitter.com/mrlesmithjr
[ansible]: https://www.ansible.com
+12 -8
View File
@@ -1,24 +1,28 @@
--- ---
galaxy_info: galaxy_info:
author: Larry Smith Jr. author: Larry Smith Jr.
description: Role to manage LVM Groups/Logical Volumes. Can be used to create, extend or resize LVM. description: Ansible role to manage(create, extend, resize) LVM Groups/Logical Volumes.
license: MIT license: MIT
min_ansible_version: 1.2 min_ansible_version: 1.2
platforms: platforms:
- name: fedora
versions:
- 31
- name: EL - name: EL
versions: versions:
- 6 - all
- 7 - name: Fedora
versions:
- all
- name: Ubuntu - name: Ubuntu
versions: versions:
- precise - all
- trusty
- name: Debian - name: Debian
versions: versions:
- jessie - all
- wheezy
galaxy_tags: galaxy_tags:
- system - system
- lvm
dependencies: [] dependencies: []
+1 -2
View File
@@ -15,7 +15,7 @@
filesystem: ext4 filesystem: ext4
mount: true mount: true
mntp: "/var/lib/mountpoint" mntp: "/var/lib/mountpoint"
- lvname: my_lv2 - lvname: my_lw
size: 20%VG size: 20%VG
opts: "--wipesignatures y" opts: "--wipesignatures y"
mount: true mount: true
@@ -23,7 +23,6 @@
filesystem: xfs filesystem: xfs
mntp: "/var/lib/mountpoint2" mntp: "/var/lib/mountpoint2"
manage_lvm: true manage_lvm: true
tasks: tasks:
- name: "Include lvm" - name: "Include lvm"
include_role: include_role:
+20 -8
View File
@@ -3,22 +3,34 @@ driver:
name: vagrant name: vagrant
provider: provider:
name: virtualbox name: virtualbox
lint: yamllint . && flake8 && ansible-lint --exclude=meta lint: yamllint . && flake8 && ansible-lint
platforms: platforms:
- name: Fedora-Molecule-LVM - name: CentOS-Molecule-LVM
box: bento/fedora-31 box: mrlesmithjr/centos7
# box-url: ${platform_root}/packer/bento/builds/fedora-31-x86_64.virtualbox.box
provider_override_args: provider_override_args:
- "persistent_storage.enabled = true" - "persistent_storage.enabled = true"
- "persistent_storage.location = 'molecule-lvm.vdi'" - "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.size = 100"
- "persistent_storage.mount = false" - "persistent_storage.mount = false"
- "persistent_storage.diskdevice = '/dev/sdb'" - "persistent_storage.diskdevice = '/dev/sdb'"
provisioner: provisioner:
name: ansible name: ansible
inventory:
group_vars:
lvm:
verifier: verifier:
name: testinfra name: testinfra
env: env:
+7
View File
@@ -18,6 +18,13 @@ def test_mylv_logical_volume_is_created(host):
assert int(cmd.stdout.rstrip()) >= 1 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): def test_volume_is_mounted(host):
host.file("/var/lib/mountpoint").mode == 0o731 host.file("/var/lib/mountpoint").mode == 0o731
+29
View 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"
include_role:
name: "ansible-manage-lvm"
+29
View 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
+1
View File
@@ -0,0 +1 @@
../default/tests
+14
View 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"
include_role:
name: "ansible-manage-lvm"
+29
View 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
+1
View File
@@ -0,0 +1 @@
../../default/tests/conftest.py
+11
View 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
View 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"
include_role:
name: "ansible-manage-lvm"
+29
View 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
+1
View File
@@ -0,0 +1 @@
../../default/tests/conftest.py
@@ -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
+27
View File
@@ -0,0 +1,27 @@
---
- 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
include_role:
name: ansible-manage-lvm
-17
View File
@@ -1,17 +0,0 @@
#!/usr/bin/env bash
TAR_FILE="v1.6.0.tar.gz"
# Prompt for Ansible role name
read -p "Enter the Ansible role name: " input
# Update .travis.yml with Ansible role name
sed -i '' "s/replace_role/${input}/g" ".travis.yml"
# Update tests/test.yml with Ansible role name
sed -i '' "s/replace_role/${input}/g" "tests/test.yml"
# Cleanup
if [ -f $TAR_FILE ]; then
rm $TAR_FILE
fi
+28 -24
View File
@@ -1,43 +1,47 @@
--- ---
- name: centos | installing lvm2 - name: centos | installing lvm2
package: package:
name: "lvm2" name: lvm2
state: "present" state: present
become: true become: true
- name: centos | installing sg3_utils - name: centos | installing sg3_utils
package: package:
name: "sg3_utils" name: sg3_utils
state: "present" state: present
become: true become: true
- name: centos | debug lvg
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 - name: centos | install xfs tools
package: package:
name: "xfsprogs" name: "xfsprogs"
state: "present" state: "present"
become: yes become: true
loop: "{{ lvm_groups|subelements('lvnames') }}" loop: "{{ lookup('subelements', lvm_groups, 'lvnames', {'skip_missing': True}, wantlist=True) }}"
when: > loop_control:
( loop_var: lv
(item.1 is defined and item.1 != 'None') and when:
( - lv.1 is defined
item.1.filesystem is defined and - lv.1 != "None"
item.1.filesystem == "xfs" - lv.1.filesystem is defined
) - lv.1.filesystem == "xfs"
and - lv.1.create is defined
( - lv.1.create|bool
item.1.create is defined and
item.1.create
)
)
- name: centos | checking for scsi devices - name: centos | checking for scsi devices
command: "sg_scan" command: sg_scan
become: true become: true
register: "scsi_devices" register: scsi_devices
changed_when: False changed_when: false
- name: centos | rescanning for new disks - name: centos | rescanning for new disks
command: "/usr/bin/rescan-scsi-bus.sh" command: /usr/bin/rescan-scsi-bus.sh
become: true become: true
changed_when: False changed_when: false
+77 -91
View File
@@ -1,110 +1,96 @@
--- ---
- name: manage_lvm | unmounting filesystem(s)
mount:
path: "{{ lv.mntp }}"
src: "/dev/{{ vg.vgname }}/{{ lv.lvname }}"
fstype: "{{ lv.filesystem | default(omit) }}"
state: "absent"
become: true
loop: "{{ vg.lvnames }}"
loop_control:
loop_var: lv
when: >
(lv is defined and
lv != 'None') and
(lv.create is defined and
not lv.create and
lv.filesystem != "swap")
- name: manage_lvm | creating new filesystem on new LVM logical volume(s) # unable to resize xfs: looks like we've to reference the mountpoint instead of the device
filesystem: - name: create_fs | check already converted
fstype: "{{ lv.filesystem }}"
dev: "/dev/{{ vg.vgname }}/{{ lv.lvname }}"
resizefs: yes
loop: "{{ vg.lvnames }}"
loop_control:
loop_var: lv
become: true
when: >
(
(vg.create is defined and
vg.create) and
(lv is defined and
lv != 'None') and
(lv.create is defined and
lv.create) and
(
lv.filesystem is defined and
lv.filesystem != 'None' and
lv.filesystem != 'xfs'
)
)
# unable to resize xfs: looks like we've to reference the mountpoint instead of the device
- name: lvm | check already converted
# at least xfs is executed twice if the partition has changed in the meantime # 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... # then it tries to recreate the fs on the mounted fs which indeed fails...
shell: "xfs_info {{ lv.mntp }} | grep -c 'ftype=1'" shell: "xfs_info {{ lv.mntp }} | grep -c 'ftype=1'"
become: yes become: yes
loop: "{{ vg.lvnames }}"
loop_control:
loop_var: lv
register: mountedxfs register: mountedxfs
ignore_errors: True ignore_errors: true
changed_when: no changed_when: false
when: > when:
( - lv is defined and lv != 'None'
(lv is defined and lv != 'None') and - lv.filesystem is defined
( - lv.filesystem == "xfs"
lv.filesystem is defined and - lv.create is defined
lv.filesystem == "xfs" - lv.create|bool
)
and
(
lv.create is defined and
lv.create
)
)
- name: manage_lvm | creating new xfs filesystem on new LVM logical volume(s) - name: create_fs | unmounting filesystem(s)
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)
filesystem: filesystem:
fstype: "{{ lv.filesystem }}" fstype: "{{ lv.filesystem }}"
dev: "/dev/{{ vg.vgname }}/{{ lv.lvname }}" dev: "/dev/{{ vg.vgname }}/{{ lv.lvname }}"
loop: "{{ vg.lvnames }}" resizefs: yes
loop_control:
loop_var: lv
become: true become: true
when: > when:
( - vg.create is defined
mountedxfs is failed and - vg.create|bool
(vg.create is defined and - lv is defined
vg.create) and - lv != 'None'
(lv is defined and - lv.create is defined
lv != 'None') and - lv.create|bool
(lv.create is defined and - lv.filesystem is defined
lv.create) and - lv.filesystem != 'None'
( - lv.filesystem != 'xfs'
lv.filesystem is defined and
lv.filesystem == 'xfs'
)
)
- name: manage_lvm | mounting new filesystem(s) - name: create_fs | creating new xfs filesystem on new LVM logical volume(s)
filesystem:
fstype: "{{ lv.filesystem }}"
dev: "/dev/{{ vg.vgname }}/{{ lv.lvname }}"
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)
mount: mount:
path: "{{ lv.mntp }}" path: "{{ lv.mntp }}"
src: "/dev/{{ vg.vgname }}/{{ lv.lvname }}" src: "/dev/{{ vg.vgname }}/{{ lv.lvname }}"
fstype: "{{ lv.filesystem }}" fstype: "{{ lv.filesystem }}"
state: "mounted" state: mounted
opts: "{{ lv.mopts | default('defaults') }}" opts: "{{ lv.mopts | default('defaults') }}"
become: true become: true
loop: "{{ vg.lvnames }}" when:
loop_control: - vg.create is defined
loop_var: lv - vg.create|bool
when: > - lv is defined
((vg.create is defined and - lv != 'None'
vg.create) and - lv.create is defined
lv != 'None' and - lv.create|bool
(lv.create is defined and - lv.mount is defined
lv.create) and - lv.mount|bool
(lv.mount is defined and
lv.mount)) - name: create_fs | resizing xfs filesystem on new LVM logical volume(s)
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
+22 -21
View File
@@ -1,30 +1,31 @@
--- ---
- debug: var=vg
- name: "debug lvm" - name: create_lv | Display Volume Group
loop: "{{ vg.lvnames }}" debug:
debug: var=lv var: vg
loop_control: verbosity: 2
loop_var: lv
- name: manage_lvm | creating new LVM logical volume(s) - name: create_lv | creating new LVM logical volume(s)
lvol: lvol:
vg: "{{ vg.vgname }}" vg: "{{ vg.vgname }}"
lv: "{{ lv.lvname }}" lv: "{{ lv.lvname }}"
size: "{{ lv.size }}" size: "{{ lv.size }}"
shrink: no shrink: false
opts: "{{ lv.opts | default('') }}" opts: "{{ lv.opts | default('') }}"
state: "present" state: present
loop: "{{ vg.lvnames }}"
loop_control:
loop_var: lv
become: true become: true
when: > register: lvchanged
( when:
(vg.create is defined - vg.create is defined
and vg.create) and - vg.create|bool
(lv is defined and - lv is defined
lv != 'None') and - lv != 'None'
(lv.create is defined and - lv.create is defined
lv.create) - lv.create|bool
)
- name: create_lv | debug changed attribute
debug:
var: lvchanged
- name: create_lv | configuring FS
include_tasks: create_fs.yml
+13 -9
View File
@@ -1,12 +1,16 @@
--- ---
- name: create_vg | creating new LVM volume group(s)
- name: manage_lvm | creating new LVM volume group(s)
lvg: lvg:
vg: "{{ item.vgname }}" vg: "{{ vg.vgname }}"
pvs: "{{ item.disks | join(',') }}" pvs: "{{ vg.disks | join(',') }}"
state: "present" state: present
become: true become: true
loop: "{{ lvm_groups }}" when:
when: > - vg.create is defined
item.create is defined and - vg.create|bool
item.create
- name: manage_lvm | loop over logical volume group(s) to create logical volumes
include_tasks: create_lv.yml
loop: "{{ vg.lvnames | default([]) }}"
loop_control:
loop_var: lv
+22 -22
View File
@@ -1,40 +1,40 @@
--- ---
- name: debian | Updating Apt Cache
apt:
update_cache: true
cache_valid_time: 3600
become: true
- name: debian | installing pre-reqs - name: debian | installing pre-reqs
package: apt:
name: name:
- lvm2 - lvm2
- scsitools - scsitools
state: "present" state: present
become: true become: true
- name: debian | install xfs tools - name: debian | install xfs tools
package: apt:
name: "xfsprogs" name: xfsprogs
state: "present" state: present
become: yes become: true
loop: "{{ lvm_groups|subelements('lvnames') }}" loop: "{{ lvm_groups|subelements('lvnames') }}"
when: > when:
( - item.1 is defined
(item.1 is defined and item.1 != 'None') and - item.1 != 'None'
( - item.1.filesystem is defined
item.1.filesystem is defined and - item.1.filesystem == "xfs"
item.1.filesystem == "xfs" - item.1.create is defined
) - item.1.create|bool
and
(
item.1.create is defined and
item.1.create
)
)
- name: debian | checking for scsi devices - name: debian | checking for scsi devices
command: "sg_scan" command: sg_scan
become: true become: true
register: "scsi_devices" register: scsi_devices
changed_when: false changed_when: false
- name: debian | rescanning for new disks added - name: debian | rescanning for new disks added
command: "/sbin/rescan-scsi-bus" command: /sbin/rescan-scsi-bus
become: true become: true
changed_when: false changed_when: false
when: scsi_devices['stdout'] | length when: scsi_devices['stdout'] | length
+3 -3
View File
@@ -7,6 +7,6 @@
when: ansible_os_family == "RedHat" when: ansible_os_family == "RedHat"
- include_tasks: manage_lvm.yml - include_tasks: manage_lvm.yml
when: > when:
manage_lvm and - lvm_groups is defined
lvm_groups is defined - manage_lvm|bool
+12 -21
View File
@@ -1,15 +1,6 @@
--- ---
- name: manage_lvm | manage physical volume group creation - name: manage_lvm | manage physical volume group creation
include_tasks: create_vg.yml include_tasks: create_vg.yml
- name: manage_lvm | loop over logical volume group(s) to create logical volumes
include_tasks: create_lv.yml
loop: "{{ lvm_groups }}"
loop_control:
loop_var: vg
- name: manage_lvm | loop over logical volume group(s) to create filesystems
include_tasks: create_fs.yml
loop: "{{ lvm_groups }}" loop: "{{ lvm_groups }}"
loop_control: loop_control:
loop_var: vg loop_var: vg
@@ -18,23 +9,23 @@
lvol: lvol:
vg: "{{ item.0.vgname }}" vg: "{{ item.0.vgname }}"
lv: "{{ item.1.lvname }}" lv: "{{ item.1.lvname }}"
state: "absent" state: absent
force: yes force: true
become: true become: true
loop: "{{ lvm_groups|subelements('lvnames') }}" loop: "{{ lvm_groups|subelements('lvnames', {'skip_missing': true}) }}"
when: > when:
(item.1 is defined and - item.1 is defined
item.1 != 'None') and - item.1 != 'None'
(item.1.create is defined and - item.1.create is defined
not item.1.create) - not item.1.create|bool
- name: manage_lvm | Removing LVM volume group(s) - name: manage_lvm | Removing LVM volume group(s)
lvg: lvg:
vg: "{{ item.vgname }}" vg: "{{ item.vgname }}"
pvs: "{{ item.disks | join(',') }}" pvs: "{{ item.disks | join(',') }}"
state: "absent" state: absent
become: true become: true
loop: "{{ lvm_groups }}" loop: "{{ lvm_groups }}"
when: > when:
item.create is defined and - item.create is defined
not item.create - not item.create|bool