blob: a93f1e4414ae32b0dab35f2349149889b29f2a47 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
# Copyright (c) 2018 Huawei Technologies Co., Ltd. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
---
- name: install lvm2 ang tgt external package when lvm backend enabled
apt:
name: "{{ item }}"
state: present
with_items:
- lvm2
- tgt
- thin-provisioning-tools
- name: configure lvm section in opensds global info if specify lvm backend
shell: |
cat >> opensds.conf <<OPENSDS_GLOABL_CONFIG_DOC
[lvm]
name = {{ lvm_name }}
description = {{ lvm_description }}
driver_name = {{ lvm_driver_name }}
config_path = {{ lvm_config_path }}
args:
chdir: "{{ opensds_config_dir }}"
ignore_errors: yes
- name: copy opensds lvm backend file to lvm config path if specify lvm backend
copy:
src: ../../../group_vars/lvm/lvm.yaml
dest: "{{ lvm_config_path }}"
- name: create directory to volume group file
file:
path: "{{ opensds_work_dir }}/volumegroups"
state: directory
recurse: yes
- name: create volume group in thin mode
shell:
_raw_params: |
function _create_lvm_volume_group {
local vg=$1
local size=$2
local backing_file={{ opensds_work_dir }}/volumegroups/${vg}.img
if ! sudo vgs $vg; then
# Only create if the file doesn't already exists
[[ -f $backing_file ]] || truncate -s $size $backing_file
local vg_dev
vg_dev=`sudo losetup -f --show $backing_file`
# Only create physical volume if it doesn't already exist
if ! sudo pvs $vg_dev; then
sudo pvcreate $vg_dev
fi
# Only create volume group if it doesn't already exist
if ! sudo vgs $vg; then
sudo vgcreate $vg $vg_dev
fi
fi
}
modprobe dm_thin_pool
_create_lvm_volume_group {{ opensds_volume_group }} 10G
args:
executable: /bin/bash
become: true
|