21 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
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
Charlie Mordant
1e997a3e80 Merge pull request #5 from Tcharl/id2
xfs support on centos
2020-04-23 19:56:02 +02:00
16 changed files with 192 additions and 59 deletions

View File

@@ -26,5 +26,7 @@ before_install:
script:
- |
sudo molecule test --scenario-name kvm
sudo molecule test --scenario-name kvmsinglelv
sudo molecule test --scenario-name kvmonlyvg
notifications:
webhooks: https://galaxy.ansible.com/api/v1/notifications/

View File

@@ -15,7 +15,7 @@
filesystem: ext4
mount: true
mntp: "/var/lib/mountpoint"
- lvname: my_lv2
- lvname: my_lw
size: 20%VG
opts: "--wipesignatures y"
mount: true

View File

@@ -18,6 +18,13 @@ def test_mylv_logical_volume_is_created(host):
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

View File

@@ -15,7 +15,7 @@
filesystem: ext4
mount: true
mntp: "/var/lib/mountpoint"
- lvname: my_lv2
- lvname: my_lw
size: 20%VG
opts: "--wipesignatures y"
mount: true

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"

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

View File

@@ -0,0 +1 @@
../../default/tests/conftest.py

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

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"

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

View File

@@ -0,0 +1 @@
../../default/tests/conftest.py

View 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

View File

@@ -1,4 +1,21 @@
---
# 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...
shell: "xfs_info {{ lv.mntp }} | grep -c 'ftype=1'"
become: yes
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)
mount:
path: "{{ lv.mntp }}"
@@ -6,9 +23,6 @@
fstype: "{{ lv.filesystem | default(omit) }}"
state: absent
become: true
loop: "{{ vg.lvnames }}"
loop_control:
loop_var: lv
when:
- lv is defined
- lv != 'None'
@@ -21,9 +35,6 @@
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
@@ -36,32 +47,10 @@
- lv.filesystem != 'None'
- lv.filesystem != 'xfs'
# 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...
shell: "xfs_info {{ lv.mntp }} | grep -c 'ftype=1'"
become: yes
loop: "{{ vg.lvnames }}"
loop_control:
loop_var: lv
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 | creating new xfs filesystem on new LVM logical volume(s)
filesystem:
fstype: "{{ lv.filesystem }}"
dev: "/dev/{{ vg.vgname }}/{{ lv.lvname }}"
loop: "{{ vg.lvnames }}"
loop_control:
loop_var: lv
become: true
when:
- mountedxfs is failed
@@ -82,14 +71,26 @@
state: mounted
opts: "{{ lv.mopts | default('defaults') }}"
become: true
loop: "{{ vg.lvnames }}"
loop_control:
loop_var: lv
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)
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

View File

@@ -1,17 +1,10 @@
---
- name: create_lv | Display Volume Group
debug:
var: vg
verbosity: 2
- name: create_lv | debug lvm
loop: "{{ vg.lvnames }}"
debug:
var: lv
verbosity: 1
loop_control:
loop_var: lv
- name: create_lv | creating new LVM logical volume(s)
lvol:
vg: "{{ vg.vgname }}"
@@ -20,10 +13,8 @@
shrink: false
opts: "{{ lv.opts | default('') }}"
state: present
loop: "{{ vg.lvnames }}"
loop_control:
loop_var: lv
become: true
register: lvchanged
when:
- vg.create is defined
- vg.create|bool
@@ -31,3 +22,10 @@
- lv != 'None'
- lv.create is defined
- lv.create|bool
- name: create_lv | debug changed attribute
debug:
var: lvchanged
- name: create_lv | configuring FS
include_tasks: create_fs.yml

View File

@@ -1,11 +1,16 @@
---
- name: create_vg | creating new LVM volume group(s)
lvg:
vg: "{{ item.vgname }}"
pvs: "{{ item.disks | join(',') }}"
vg: "{{ vg.vgname }}"
pvs: "{{ vg.disks | join(',') }}"
state: present
become: true
loop: "{{ lvm_groups }}"
when:
- item.create is defined
- item.create|bool
- vg.create is defined
- vg.create|bool
- 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

View File

@@ -1,15 +1,6 @@
---
- name: manage_lvm | manage physical volume group creation
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_control:
loop_var: vg
@@ -21,7 +12,7 @@
state: absent
force: true
become: true
loop: "{{ lvm_groups|subelements('lvnames') }}"
loop: "{{ lvm_groups|subelements('lvnames', {'skip_missing': true}) }}"
when:
- item.1 is defined
- item.1 != 'None'