Commit a0adbcb8 authored by ale's avatar ale

Add basic support for managing logical volumes (LVM)

Add a 'volumemgr' role that manages logical volumes on servers by
looking at the 'volumes' attribute of our services.

It can create LVs, format them with ext4, and mount them with the
right permissions.
parent 53592874
---
- include_tasks: service.yml
with_items: "{{ float_enabled_services }}"
loop_control:
loop_var: service_name_iter
when: "enable_volumes | default(False)"
---
- set_fact:
service: "{{ services[service_name_iter] }}"
- include_tasks: volume.yml
with_items: "{{ service.volumes | default([]) }}"
loop_control:
loop_var: volume
---
- set_fact:
lv_name: "{{ service.name }}-{{ volume.name }}"
- set_fact:
lv_dev: "/dev/{{ volumes_vg | default('vg0') }}/{{ lv_name }}"
- name: "Create mount point for volume {{ lv_name }}"
file:
path: "{{ volume.path }}"
owner: "{{ volume.owner | default('root') }}"
group: "{{ volume.group | default('root') }}"
mode: "{{ volume.mode | default('0755') }}"
state: directory
- name: "Create the LV {{ lv_name }}"
lvol:
vg: "{{ volumes_vg | default('vg0') }}"
lv: "{{ lv_name }}"
size: "{{ volume.size | default('10g') }}"
- name: "Create a filesystem on {{ lv_name }}"
filesystem:
dev: "{{ lv_dev }}"
fstype: ext4
register: lv_mkfs
- name: "Add the /etc/fstab entry for {{ lv_name }}"
mount:
path: "{{ volume.path }}"
src: "{{ lv_dev }}"
fstype: ext4
state: mounted
# Set permissions again if we have created the filesystem.
- name: "Fix permissions for {{ volume.path }}"
file:
path: "{{ volume.path }}"
owner: "{{ volume.owner | default('root') }}"
group: "{{ volume.group | default('root') }}"
mode: "{{ volume.mode | default('0755') }}"
state: directory
when: lv_mkfs.changed
......@@ -15,6 +15,13 @@ frontend:
- replds@acme.service
ports:
- 5005
volumes:
- name: cache
path: /var/cache/nginx
owner: nginx
group: nginx
mode: "0700"
size: 20g
log-collector:
scheduling_group: backend
......@@ -58,6 +65,13 @@ log-collector:
ports:
- 6514
- 9200
volumes:
- name: elasticsearch
path: /var/lib/elasticsearch
size: 100g
owner: docker-log-collector
group: docker-log-collector
mode: "0700"
prometheus:
scheduling_group: backend
......@@ -104,6 +118,11 @@ prometheus:
- prometheus-blackbox-exporter.service
ports:
- 9094
volumes:
- name: metrics
path: /var/lib/prometheus
owner: prometheus
group: prometheus
sso-server:
num_instances: 1
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment