2019-10-20 21:43:24 +00:00
|
|
|
---
|
|
|
|
- block:
|
|
|
|
- name: Install requirements
|
|
|
|
package:
|
|
|
|
name: "{{ item }}"
|
|
|
|
state: present
|
|
|
|
loop: "{{ lvm_packages }}"
|
|
|
|
|
|
|
|
- name: Create volume group
|
|
|
|
lvg:
|
|
|
|
vg: "{{ item.group }}"
|
|
|
|
pvs: "{{ item.disks | join(',') }}"
|
|
|
|
pesize: "4"
|
|
|
|
loop: "{{ lvm_volumes }}"
|
|
|
|
loop_control:
|
|
|
|
label: "name: {{ item.group }}, disks: {{ item.disks | join(',') }}"
|
|
|
|
|
|
|
|
# workaround: https://github.com/ansible/ansible/pull/52890
|
|
|
|
- name: Resize physical volume
|
|
|
|
command: "pvresize {{ item.disks | join(' ') }}"
|
|
|
|
changed_when: False
|
|
|
|
with_items: "{{ lvm_volumes }}"
|
|
|
|
loop_control:
|
|
|
|
label: "disks: {{ item.disks | join(',') }}"
|
|
|
|
|
|
|
|
- name: Create logical volume
|
|
|
|
lvol:
|
|
|
|
vg: "{{ item.group }}"
|
|
|
|
lv: "{{ item.name }}"
|
|
|
|
size: "{{ item.size }}"
|
|
|
|
resizefs: "{{ item.resizefs | default(True) }}"
|
2020-01-26 14:52:52 +00:00
|
|
|
state: present
|
2019-10-20 21:43:24 +00:00
|
|
|
loop: "{{ lvm_volumes }}"
|
|
|
|
loop_control:
|
|
|
|
label: "name: {{ item.group }}, size: {{ item.size }}"
|
|
|
|
|
|
|
|
- name: Create filesystem
|
|
|
|
filesystem:
|
|
|
|
fstype: "{{ item.fstype | default('ext4') }}"
|
|
|
|
dev: "/dev/mapper/{{ item.group }}-{{ item.name }}"
|
|
|
|
loop: "{{ lvm_volumes }}"
|
|
|
|
loop_control:
|
|
|
|
label: "device: /dev/mapper/{{ item.group }}-{{ item.name }}, fstype: {{ item.fstype | default('ext4') }}"
|
|
|
|
|
|
|
|
- name: Mount volume
|
|
|
|
mount:
|
|
|
|
path: "{{ item.mountpoint }}"
|
|
|
|
src: "/dev/mapper/{{ item.group }}-{{ item.name }}"
|
|
|
|
fstype: "{{ item.fstype | default('ext4') }}"
|
|
|
|
opts: "{{ item.mountopts | default([]) | join(',') or omit }}"
|
2020-01-26 14:38:28 +00:00
|
|
|
state: "{{ item.state | default('mounted') }}"
|
2019-10-20 21:43:24 +00:00
|
|
|
loop: "{{ lvm_volumes }}"
|
|
|
|
loop_control:
|
|
|
|
label: "mount: /dev/mapper/{{ item.group }}-{{ item.name }} {{ item.mountpoint }} {{ item.fstype | default('ext4') }}{% if item.mountopts is defined %} {{ item.mountopts | join(',') }}{% endif %}"
|
|
|
|
become: True
|
|
|
|
become_user: root
|