Skip to content

Commit

Permalink
feat: Add lvm role (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
konradasb authored Nov 10, 2023
1 parent 78479ff commit 493a0b7
Show file tree
Hide file tree
Showing 6 changed files with 155 additions and 0 deletions.
27 changes: 27 additions & 0 deletions roles/lvm/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# lvm

Ansible role for configuring LVM profiles, volume groups and logical volumes.

## Requirements

None.

## Dependencies

None.

## Role Variables

Refer to [defaults/main.yml](defaults/main.yml) for a list of variables along with documentation.

## Example Playbook

```yaml
- hosts: all
roles:
- role: hostinger.core.lvm
```
## License
See [LICENSE](../../LICENSE)
29 changes: 29 additions & 0 deletions roles/lvm/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
# Example:
#
# lvm_profiles:
# - name: example
# content: |
# activation {
# thin_pool_autoextend_threshold=80
# thin_pool_autoextend_percent=20
# }
lvm_profiles: []

# Example:
#
# lvm_vgs:
# - name: example
# state: present
# pvs:
# - /dev/sdb
lvm_vgs: []

# Example:
#
# lvm_lvs:
# - vg: example
# size: 100G
# thinpool: thinpool
# opts: "--poolmetadatasize 1G --profile example --monitor y"
lvm_lvs: []
19 changes: 19 additions & 0 deletions roles/lvm/meta/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
galaxy_info:
role_name: lvm
author: hostinger
description: Ansible role for configuring LVM profiles, volume groups and logical volumes.
license: license (MIT)
min_ansible_version: "2.10"
platforms:
- name: Fedora
versions:
- all
- name: Debian
versions:
- all
- name: Ubuntu
versions:
- all
galaxy_tags:
- lvm
17 changes: 17 additions & 0 deletions roles/lvm/molecule/default/converge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
- name: Converge
hosts:
- all

pre_tasks:
- name: Update apt cache
ansible.builtin.apt:
update_cache: yes
when: ansible_os_family == 'Debian'
- name: Update yum cache
ansible.builtin.yum:
update_cache: yes
when: ansible_os_family == 'RedHat'

roles:
- lvm
19 changes: 19 additions & 0 deletions roles/lvm/molecule/default/molecule.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
dependency:
name: galaxy
driver:
name: docker
platforms:
- name: default
image: geerlingguy/docker-${MOLECULE_DISTRO:-ubuntu2204}-ansible:latest
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:rw
command: ${MOLECULE_DOCKER_COMMAND:-""}
cgroupns_mode: host
pre_build_image: true
privileged: true
platform: amd64
provisioner:
name: ansible
playbooks:
converge: ${MOLECULE_PLAYBOOK:-converge.yml}
44 changes: 44 additions & 0 deletions roles/lvm/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
---
- name: Install dependencies
ansible.builtin.package:
name: "{{ item }}"
state: present
loop:
- lvm2

- name: Configure profiles
ansible.builtin.copy:
content: "{{ item.content }}"
dest: "/etc/lvm/profile/{{ item.name }}.profile"
owner: root
group: root
mode: 0644
loop: "{{ lvm_profiles }}"
when:
- lvm_profiles | length > 0

- name: Configure volume group(s)
community.general.lvg:
vg: "{{ item.name }}"
pvs: "{{ item.pvs | join(',') }}"
state: "{{ item.state | default('present') }}"
force: true
loop: "{{ lvm_vgs }}"
when:
- lvm_vgs | length > 0

- name: Configure logical volume(s)
community.general.lvol:
vg: "{{ item.vg }}"
lv: "{{ item.name | default(omit) }}"
size: "{{ item.size | default(omit) }}"
opts: "{{ item.opts | default('') }}"
thinpool: "{{ item.thinpool | default(omit) }}"
resizefs: "{{ item.resizefs | default(omit) }}"
active: "{{ item.active | default(omit) }}"
shrink: "{{ item.shrink | default(omit) }}"
state: "{{ item.state | default('present') }}"
force: true
loop: "{{ lvm_lvs }}"
when:
- lvm_lvs | length > 0

0 comments on commit 493a0b7

Please sign in to comment.